webVitalMeters.spec.tsx 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  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 usePageFilters from 'sentry/utils/usePageFilters';
  6. import WebVitalMeters from 'sentry/views/insights/browser/webVitals/components/webVitalMeters';
  7. import type {ProjectScore} from 'sentry/views/insights/browser/webVitals/types';
  8. jest.mock('sentry/utils/useLocation');
  9. jest.mock('sentry/utils/usePageFilters');
  10. describe('WebVitalMeters', function () {
  11. const organization = OrganizationFixture();
  12. const projectScore: ProjectScore = {
  13. lcpWeight: 30,
  14. fcpWeight: 20,
  15. clsWeight: 15,
  16. ttfbWeight: 10,
  17. inpWeight: 10,
  18. };
  19. const projectData: TableData = {
  20. data: [],
  21. };
  22. beforeEach(function () {
  23. jest.mocked(useLocation).mockReturnValue({
  24. pathname: '',
  25. search: '',
  26. query: {},
  27. hash: '',
  28. state: undefined,
  29. action: 'PUSH',
  30. key: '',
  31. });
  32. jest.mocked(usePageFilters).mockReturnValue({
  33. isReady: true,
  34. desyncedFilters: new Set(),
  35. pinnedFilters: new Set(),
  36. shouldPersist: true,
  37. selection: {
  38. datetime: {
  39. period: '10d',
  40. start: null,
  41. end: null,
  42. utc: false,
  43. },
  44. environments: [],
  45. projects: [],
  46. },
  47. });
  48. });
  49. it('renders web vital meters with interaction to next paint', async () => {
  50. render(<WebVitalMeters projectData={projectData} projectScore={projectScore} />, {
  51. organization,
  52. });
  53. await screen.findByText('Largest Contentful Paint');
  54. screen.getByText('First Contentful Paint');
  55. screen.getByText('Cumulative Layout Shift');
  56. screen.getByText('Time To First Byte');
  57. screen.getByText('Interaction to Next Paint');
  58. });
  59. });