metricsRibbon.spec.tsx 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. import {OrganizationFixture} from 'sentry-fixture/organization';
  2. import {ProjectFixture} from 'sentry-fixture/project';
  3. import {render, screen} from 'sentry-test/reactTestingLibrary';
  4. import {DiscoverDatasets} from 'sentry/utils/discover/types';
  5. import usePageFilters from 'sentry/utils/usePageFilters';
  6. import {MetricsRibbon} from 'sentry/views/performance/screenload/screenLoadSpans/metricsRibbon';
  7. jest.mock('sentry/utils/usePageFilters');
  8. describe('MetricsRibbon', function () {
  9. const organization = OrganizationFixture();
  10. const project = ProjectFixture();
  11. jest.mocked(usePageFilters).mockReturnValue({
  12. isReady: true,
  13. desyncedFilters: new Set(),
  14. pinnedFilters: new Set(),
  15. shouldPersist: true,
  16. selection: {
  17. datetime: {
  18. period: '10d',
  19. start: null,
  20. end: null,
  21. utc: false,
  22. },
  23. environments: [],
  24. projects: [parseInt(project.id, 10)],
  25. },
  26. });
  27. MockApiClient.addMockResponse({
  28. url: `/organizations/${organization.slug}/releases/`,
  29. body: [
  30. {
  31. id: 970136705,
  32. version: 'com.example.vu.android@2.10.5',
  33. dateCreated: '2023-12-19T21:37:53.895495Z',
  34. },
  35. {
  36. id: 969902997,
  37. version: 'com.example.vu.android@2.10.3+42',
  38. dateCreated: '2023-12-19T18:04:06.953025Z',
  39. },
  40. ],
  41. });
  42. it('makes a request to discover with the correct dataset and fields', async function () {
  43. const mockEventsQuery = MockApiClient.addMockResponse({
  44. url: `/organizations/${organization.slug}/events/`,
  45. body: {
  46. data: [{title: 'test-transaction', 'count()': 1, 'avg(duration)': 1000}],
  47. },
  48. });
  49. render(
  50. <MetricsRibbon
  51. dataset={DiscoverDatasets.SPANS_METRICS}
  52. filters={[
  53. 'duration:>0',
  54. 'transaction.op:ui.load',
  55. 'transaction:test-transaction',
  56. ]}
  57. blocks={[
  58. {dataKey: 'count()', title: 'Count', type: 'count'},
  59. {
  60. dataKey: 'avg(duration)',
  61. title: 'Custom Header',
  62. type: 'duration',
  63. },
  64. ]}
  65. fields={['count()', 'avg(duration)']}
  66. referrer="test-referrer"
  67. />
  68. );
  69. expect(screen.getByText('Custom Header')).toBeInTheDocument();
  70. expect(screen.getByText('Count')).toBeInTheDocument();
  71. expect(await screen.findByText('1')).toBeInTheDocument();
  72. expect(screen.getByText('1.00s')).toBeInTheDocument();
  73. expect(mockEventsQuery).toHaveBeenCalledWith(
  74. expect.anything(),
  75. expect.objectContaining({
  76. query: expect.objectContaining({
  77. query: 'duration:>0 transaction.op:ui.load transaction:test-transaction',
  78. referrer: 'test-referrer',
  79. dataset: 'spansMetrics',
  80. field: ['count()', 'avg(duration)'],
  81. }),
  82. })
  83. );
  84. });
  85. });