index.spec.tsx 2.4 KB

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