webVitalMeters.spec.tsx 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. import {OrganizationFixture} from 'sentry-fixture/organization';
  2. import {render, screen} from 'sentry-test/reactTestingLibrary';
  3. import type {TableData} from 'sentry/utils/discover/discoverQuery';
  4. import {useLocation} from 'sentry/utils/useLocation';
  5. import useOrganization from 'sentry/utils/useOrganization';
  6. import usePageFilters from 'sentry/utils/usePageFilters';
  7. import WebVitalMeters from 'sentry/views/performance/browser/webVitals/components/webVitalMeters';
  8. import type {ProjectScore} from 'sentry/views/performance/browser/webVitals/utils/types';
  9. jest.mock('sentry/utils/useLocation');
  10. jest.mock('sentry/utils/usePageFilters');
  11. jest.mock('sentry/utils/useOrganization');
  12. describe('WebVitalMeters', function () {
  13. const organization = OrganizationFixture();
  14. const projectScore: ProjectScore = {
  15. lcpWeight: 30,
  16. fcpWeight: 20,
  17. fidWeight: 25,
  18. clsWeight: 15,
  19. ttfbWeight: 10,
  20. inpWeight: 10,
  21. };
  22. const projectData: TableData = {
  23. data: [],
  24. };
  25. beforeEach(function () {
  26. jest.mocked(useLocation).mockReturnValue({
  27. pathname: '',
  28. search: '',
  29. query: {},
  30. hash: '',
  31. state: undefined,
  32. action: 'PUSH',
  33. key: '',
  34. });
  35. jest.mocked(usePageFilters).mockReturnValue({
  36. isReady: true,
  37. desyncedFilters: new Set(),
  38. pinnedFilters: new Set(),
  39. shouldPersist: true,
  40. selection: {
  41. datetime: {
  42. period: '10d',
  43. start: null,
  44. end: null,
  45. utc: false,
  46. },
  47. environments: [],
  48. projects: [],
  49. },
  50. });
  51. jest.mocked(useOrganization).mockReturnValue(organization);
  52. });
  53. it('renders web vital meters with first input delay', async () => {
  54. render(<WebVitalMeters projectData={projectData} projectScore={projectScore} />);
  55. await screen.findByText('Largest Contentful Paint');
  56. screen.getByText('First Contentful Paint');
  57. screen.getByText('Cumulative Layout Shift');
  58. screen.getByText('Time To First Byte');
  59. screen.getByText('First Input Delay');
  60. });
  61. it('renders web vital meters with interaction to next paint', async () => {
  62. const organizationWithInp = OrganizationFixture({
  63. features: ['starfish-browser-webvitals-replace-fid-with-inp'],
  64. });
  65. jest.mocked(useOrganization).mockReturnValue(organizationWithInp);
  66. render(<WebVitalMeters projectData={projectData} projectScore={projectScore} />);
  67. await screen.findByText('Largest Contentful Paint');
  68. screen.getByText('First Contentful Paint');
  69. screen.getByText('Cumulative Layout Shift');
  70. screen.getByText('Time To First Byte');
  71. screen.getByText('Interaction to Next Paint');
  72. });
  73. });