screensOverviewTable.spec.tsx 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. import {render, screen} from '@testing-library/react';
  2. import type {Location} from 'history';
  3. import {OrganizationFixture} from 'sentry-fixture/organization';
  4. import {ProjectFixture} from 'sentry-fixture/project';
  5. import {ThemeAndStyleProvider} from 'sentry/components/themeAndStyleProvider';
  6. import EventView from 'sentry/utils/discover/eventView';
  7. import {useLocation} from 'sentry/utils/useLocation';
  8. import useOrganization from 'sentry/utils/useOrganization';
  9. import usePageFilters from 'sentry/utils/usePageFilters';
  10. import ScreensOverviewTable from 'sentry/views/insights/mobile/screens/components/screensOverviewTable';
  11. jest.mock('sentry/utils/useOrganization');
  12. jest.mock('sentry/utils/useLocation');
  13. jest.mock('sentry/views/insights/common/utils/useModuleURL');
  14. jest.mock('sentry/utils/usePageFilters');
  15. describe('ScreensOverviewTable', () => {
  16. const organization = OrganizationFixture({
  17. features: ['insights-addon-modules', 'insights-mobile-screens-module'],
  18. });
  19. const project = ProjectFixture();
  20. const location = {
  21. action: 'PUSH',
  22. hash: '',
  23. key: '',
  24. pathname: '/organizations/org-slug/performance/mobile/mobile-screens',
  25. query: {
  26. project: project.id,
  27. },
  28. search: '',
  29. state: undefined,
  30. } as Location;
  31. jest.mocked(useOrganization).mockReturnValue(organization);
  32. jest.mocked(useLocation).mockReturnValue(location);
  33. jest.mocked(usePageFilters).mockReturnValue({
  34. isReady: true,
  35. desyncedFilters: new Set(),
  36. pinnedFilters: new Set(),
  37. shouldPersist: true,
  38. selection: {
  39. datetime: {
  40. period: '10d',
  41. start: null,
  42. end: null,
  43. utc: false,
  44. },
  45. environments: [],
  46. projects: [parseInt(project.id, 10)],
  47. },
  48. });
  49. const mockEventView = EventView.fromLocation(location);
  50. const mockData = {
  51. data: [
  52. {
  53. id: '1',
  54. transaction: 'Screen 01',
  55. 'avg(mobile.slow_frames)': 12,
  56. 'avg(mobile.frozen_frames)': 23,
  57. 'count()': 45,
  58. },
  59. ],
  60. meta: {
  61. fields: [],
  62. },
  63. };
  64. it('renders columns', async () => {
  65. render(
  66. <ThemeAndStyleProvider>
  67. <ScreensOverviewTable
  68. data={mockData}
  69. eventView={mockEventView}
  70. isLoading={false}
  71. pageLinks=""
  72. />
  73. </ThemeAndStyleProvider>
  74. );
  75. // headers
  76. expect(await screen.findByText('Screen')).toBeInTheDocument();
  77. expect(await screen.findByText('Slow Frames')).toBeInTheDocument();
  78. expect(await screen.findByText('Frozen Frames')).toBeInTheDocument();
  79. expect(await screen.findByText('Screen 01')).toBeInTheDocument();
  80. // slow frames
  81. expect(await screen.findByText('12')).toBeInTheDocument();
  82. // frozen frames
  83. expect(await screen.findByText('23')).toBeInTheDocument();
  84. // count
  85. expect(await screen.findByText('45')).toBeInTheDocument();
  86. });
  87. });