pagePerformanceTable.spec.tsx 2.0 KB

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