index.spec.tsx 2.2 KB

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