webVitalsDetailPanel.spec.tsx 2.2 KB

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