index.spec.tsx 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  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. anomaliesMock = MockApiClient.addMockResponse({
  31. url: '/organizations/org-slug/transaction-anomaly-detection/',
  32. body: {},
  33. });
  34. });
  35. afterEach(cleanup);
  36. it('renders basic UI elements with flag', async function () {
  37. const initialData = initializeData({
  38. features: ['performance-view', 'performance-anomaly-detection-ui'],
  39. query: {project: '1', transaction: 'transaction'},
  40. });
  41. render(<TransactionAnomalies location={initialData.router.location} />, {
  42. context: initialData.routerContext,
  43. organization: initialData.organization,
  44. });
  45. expect(await screen.findByText('Transaction Count')).toBeInTheDocument();
  46. expect(anomaliesMock).toHaveBeenCalledTimes(1);
  47. expect(anomaliesMock).toHaveBeenNthCalledWith(
  48. 1,
  49. expect.anything(),
  50. expect.objectContaining({
  51. query: expect.objectContaining({
  52. environment: [],
  53. field: ['tpm()'],
  54. per_page: 50,
  55. project: ['1'],
  56. query: 'transaction:transaction',
  57. statsPeriod: '14d',
  58. }),
  59. })
  60. );
  61. });
  62. });