index.spec.tsx 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. import {LocationFixture} from 'sentry-fixture/locationFixture';
  2. import type {InitializeDataSettings} from 'sentry-test/performance/initializePerformanceData';
  3. import {initializeData as _initializeData} from 'sentry-test/performance/initializePerformanceData';
  4. import {act, cleanup, render, screen} from 'sentry-test/reactTestingLibrary';
  5. import ProjectsStore from 'sentry/stores/projectsStore';
  6. import {useLocation} from 'sentry/utils/useLocation';
  7. import TransactionAnomalies from 'sentry/views/performance/transactionSummary/transactionAnomalies';
  8. jest.mock('sentry/utils/useLocation');
  9. const mockUseLocation = jest.mocked(useLocation);
  10. const initializeData = (settings: InitializeDataSettings) => {
  11. const data = _initializeData(settings);
  12. act(() => void ProjectsStore.loadInitialData(data.projects));
  13. return data;
  14. };
  15. describe('AnomaliesTab', function () {
  16. let anomaliesMock: any;
  17. beforeEach(function () {
  18. mockUseLocation.mockReturnValue(
  19. LocationFixture({pathname: '/organizations/org-slug/performance/summary'})
  20. );
  21. MockApiClient.addMockResponse({
  22. url: '/organizations/org-slug/projects/',
  23. body: [],
  24. });
  25. MockApiClient.addMockResponse({
  26. url: '/organizations/org-slug/sdk-updates/',
  27. body: [],
  28. });
  29. MockApiClient.addMockResponse({
  30. url: '/organizations/org-slug/prompts-activity/',
  31. body: {},
  32. });
  33. MockApiClient.addMockResponse({
  34. url: '/organizations/org-slug/events-has-measurements/',
  35. body: {measurements: false},
  36. });
  37. MockApiClient.addMockResponse({
  38. url: '/organizations/org-slug/replay-count/',
  39. body: {},
  40. });
  41. anomaliesMock = MockApiClient.addMockResponse({
  42. url: '/organizations/org-slug/transaction-anomaly-detection/',
  43. body: {},
  44. });
  45. });
  46. afterEach(cleanup);
  47. it('renders basic UI elements with flag', async function () {
  48. const initialData = initializeData({
  49. features: ['performance-view', 'performance-anomaly-detection-ui'],
  50. query: {project: '1', transaction: 'transaction'},
  51. });
  52. render(<TransactionAnomalies location={initialData.router.location} />, {
  53. router: initialData.router,
  54. organization: initialData.organization,
  55. });
  56. expect(await screen.findByText('Transaction Count')).toBeInTheDocument();
  57. expect(anomaliesMock).toHaveBeenCalledTimes(1);
  58. expect(anomaliesMock).toHaveBeenNthCalledWith(
  59. 1,
  60. expect.anything(),
  61. expect.objectContaining({
  62. query: expect.objectContaining({
  63. environment: [],
  64. field: ['tpm()'],
  65. per_page: 50,
  66. project: ['1'],
  67. query: 'transaction:transaction',
  68. statsPeriod: '14d',
  69. }),
  70. })
  71. );
  72. });
  73. });