webVitalsDetailPanel.spec.tsx 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. import {OrganizationFixture} from 'sentry-fixture/organization';
  2. import {render, screen, waitForElementToBeRemoved} 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 {WebVitalsDetailPanel} from 'sentry/views/performance/browser/webVitals/webVitalsDetailPanel';
  7. jest.mock('sentry/utils/useLocation');
  8. jest.mock('sentry/utils/usePageFilters');
  9. jest.mock('sentry/utils/useOrganization');
  10. describe('WebVitalsDetailPanel', function () {
  11. const organization = OrganizationFixture();
  12. let eventsMock, eventsStatsMock;
  13. beforeEach(function () {
  14. jest.mocked(useLocation).mockReturnValue({
  15. pathname: '',
  16. search: '',
  17. query: {},
  18. hash: '',
  19. state: undefined,
  20. action: 'PUSH',
  21. key: '',
  22. });
  23. jest.mocked(usePageFilters).mockReturnValue({
  24. isReady: true,
  25. desyncedFilters: new Set(),
  26. pinnedFilters: new Set(),
  27. shouldPersist: true,
  28. selection: {
  29. datetime: {
  30. period: '10d',
  31. start: null,
  32. end: null,
  33. utc: false,
  34. },
  35. environments: [],
  36. projects: [],
  37. },
  38. });
  39. jest.mocked(useOrganization).mockReturnValue(organization);
  40. eventsMock = MockApiClient.addMockResponse({
  41. url: `/organizations/${organization.slug}/events/`,
  42. body: {
  43. data: [],
  44. },
  45. });
  46. eventsStatsMock = MockApiClient.addMockResponse({
  47. url: `/organizations/${organization.slug}/events-stats/`,
  48. body: {},
  49. });
  50. });
  51. afterEach(function () {
  52. jest.resetAllMocks();
  53. });
  54. it('renders correctly with empty results', async () => {
  55. render(<WebVitalsDetailPanel onClose={() => undefined} webVital="lcp" />);
  56. await waitForElementToBeRemoved(() => screen.getByTestId('loading-indicator'));
  57. // Once for project web vitals and once for samples
  58. expect(eventsMock).toHaveBeenCalledTimes(2);
  59. expect(eventsStatsMock).toHaveBeenCalledTimes(1);
  60. expect(screen.getByText('Largest Contentful Paint (P75)')).toBeInTheDocument();
  61. expect(screen.getByText('—')).toBeInTheDocument();
  62. expect(
  63. screen.getByText(/Largest Contentful Paint \(LCP\) measures the render/)
  64. ).toBeInTheDocument();
  65. });
  66. });