incidentRedirect.spec.tsx 1.4 KB

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