incidentRedirect.spec.tsx 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. import {browserHistory} from 'react-router';
  2. import {initializeOrg} from 'sentry-test/initializeOrg';
  3. import {render, waitFor} from 'sentry-test/reactTestingLibrary';
  4. import {trackAnalytics} from 'sentry/utils/analytics';
  5. import IncidentRedirect from './incidentRedirect';
  6. jest.mock('sentry/utils/analytics');
  7. describe('IncidentRedirect', () => {
  8. const params = {alertId: '123'};
  9. const {organization, project, routerContext, routerProps} = initializeOrg({
  10. router: {
  11. params,
  12. },
  13. });
  14. const mockIncident = TestStubs.Incident({projects: [project.slug]});
  15. beforeEach(() => {
  16. MockApiClient.addMockResponse({
  17. url: '/organizations/org-slug/incidents/123/',
  18. body: mockIncident,
  19. });
  20. });
  21. afterEach(() => {
  22. MockApiClient.clearMockResponses();
  23. jest.clearAllMocks();
  24. });
  25. it('redirects to alert details page', async () => {
  26. render(<IncidentRedirect organization={organization} {...routerProps} />, {
  27. context: routerContext,
  28. });
  29. expect(trackAnalytics).toHaveBeenCalledWith(
  30. 'alert_details.viewed',
  31. expect.objectContaining({
  32. alert_id: 123,
  33. })
  34. );
  35. await waitFor(() => {
  36. expect(browserHistory.replace).toHaveBeenCalledWith({
  37. pathname: '/organizations/org-slug/alerts/rules/details/4/',
  38. query: {
  39. alert: '123',
  40. },
  41. });
  42. });
  43. });
  44. });