pagePerformanceTable.spec.tsx 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. import {OrganizationFixture} from 'sentry-fixture/organization';
  2. import {render, 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 {PagePerformanceTable} from 'sentry/views/performance/browser/webVitals/pagePerformanceTable';
  7. jest.mock('sentry/utils/useLocation');
  8. jest.mock('sentry/utils/usePageFilters');
  9. jest.mock('sentry/utils/useOrganization');
  10. describe('PagePerformanceTable', function () {
  11. const organization = OrganizationFixture();
  12. let eventsMock;
  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. });
  47. afterEach(function () {
  48. jest.clearAllMocks();
  49. });
  50. it('escapes user input search filter', async () => {
  51. jest.mocked(useLocation).mockReturnValue({
  52. pathname: '',
  53. search: '',
  54. query: {query: '/issues/*'},
  55. hash: '',
  56. state: undefined,
  57. action: 'PUSH',
  58. key: '',
  59. });
  60. render(<PagePerformanceTable />);
  61. await waitFor(() => {
  62. expect(eventsMock).toHaveBeenCalledTimes(2);
  63. expect(eventsMock).toHaveBeenLastCalledWith(
  64. '/organizations/org-slug/events/',
  65. expect.objectContaining({
  66. query: expect.objectContaining({
  67. query: expect.stringContaining('transaction:"*/issues/\\**"'),
  68. }),
  69. })
  70. );
  71. });
  72. });
  73. });