metricsRibbon.spec.tsx 2.8 KB

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