pageOverview.spec.tsx 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. import {OrganizationFixture} from 'sentry-fixture/organization';
  2. import {render, screen, userEvent, waitFor} from 'sentry-test/reactTestingLibrary';
  3. import {useLocation} from 'sentry/utils/useLocation';
  4. import useOrganization from 'sentry/utils/useOrganization';
  5. import usePageFilters from 'sentry/utils/usePageFilters';
  6. import PageOverview from 'sentry/views/performance/browser/webVitals/pageOverview';
  7. jest.mock('sentry/utils/useLocation');
  8. jest.mock('sentry/utils/usePageFilters');
  9. jest.mock('sentry/utils/useOrganization');
  10. describe('PageOverview', function () {
  11. const organization = OrganizationFixture({
  12. features: ['starfish-browser-webvitals', 'performance-database-view'],
  13. });
  14. let eventsMock;
  15. beforeEach(function () {
  16. jest.mocked(useLocation).mockReturnValue({
  17. pathname: '',
  18. search: '',
  19. query: {},
  20. hash: '',
  21. state: undefined,
  22. action: 'PUSH',
  23. key: '',
  24. });
  25. jest.mocked(usePageFilters).mockReturnValue({
  26. isReady: true,
  27. desyncedFilters: new Set(),
  28. pinnedFilters: new Set(),
  29. shouldPersist: true,
  30. selection: {
  31. datetime: {
  32. period: '10d',
  33. start: null,
  34. end: null,
  35. utc: false,
  36. },
  37. environments: [],
  38. projects: [],
  39. },
  40. });
  41. jest.mocked(useOrganization).mockReturnValue(organization);
  42. eventsMock = MockApiClient.addMockResponse({
  43. url: `/organizations/${organization.slug}/events/`,
  44. body: {
  45. data: [],
  46. },
  47. });
  48. MockApiClient.addMockResponse({
  49. url: `/organizations/${organization.slug}/events-stats/`,
  50. body: {},
  51. });
  52. MockApiClient.addMockResponse({
  53. url: `/organizations/${organization.slug}/spans-aggregation/`,
  54. body: {},
  55. });
  56. });
  57. afterEach(function () {
  58. jest.clearAllMocks();
  59. });
  60. it('renders performance score migration alert', async () => {
  61. jest.mocked(useLocation).mockReturnValue({
  62. pathname: '',
  63. search: '',
  64. query: {useStoredScores: 'true', transaction: '/'},
  65. hash: '',
  66. state: undefined,
  67. action: 'PUSH',
  68. key: '',
  69. });
  70. render(<PageOverview />);
  71. await screen.findByText(
  72. /We made improvements to how Performance Scores are calculated for your projects/
  73. );
  74. });
  75. it('renders pageload and interaction switcher', async () => {
  76. const organizationWithInp = OrganizationFixture({
  77. features: [
  78. 'starfish-browser-webvitals',
  79. 'performance-database-view',
  80. 'starfish-browser-webvitals-replace-fid-with-inp',
  81. ],
  82. });
  83. jest.mocked(useOrganization).mockReturnValue(organizationWithInp);
  84. jest.mocked(useLocation).mockReturnValue({
  85. pathname: '',
  86. search: '',
  87. query: {useStoredScores: 'true', transaction: '/'},
  88. hash: '',
  89. state: undefined,
  90. action: 'PUSH',
  91. key: '',
  92. });
  93. render(<PageOverview />);
  94. await screen.findAllByText('Interactions');
  95. userEvent.click(screen.getAllByText('Interactions')[0]);
  96. await waitFor(() =>
  97. expect(eventsMock).toHaveBeenLastCalledWith(
  98. '/organizations/org-slug/events/',
  99. expect.objectContaining({
  100. query: expect.objectContaining({
  101. query:
  102. 'transaction.op:pageload transaction:"/" has:measurements.score.total has:measurements.fid (has:profile.id OR has:replayId) ',
  103. }),
  104. })
  105. )
  106. );
  107. });
  108. });