redirectToProject.spec.tsx 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. import {initializeOrg} from 'sentry-test/initializeOrg';
  2. import {act, renderGlobalModal} from 'sentry-test/reactTestingLibrary';
  3. import {openModal} from 'sentry/actionCreators/modal';
  4. import {RedirectToProjectModal} from 'sentry/components/modals/redirectToProject';
  5. jest.unmock('sentry/utils/recreateRoute');
  6. describe('RedirectToProjectModal', function () {
  7. jest.useFakeTimers();
  8. it('has timer to redirect to new slug after mounting', function () {
  9. const {routerProps} = initializeOrg({
  10. router: {
  11. routes: [
  12. {path: '/', childRoutes: []},
  13. {name: 'Organizations', path: ':orgId/', childRoutes: []},
  14. {name: 'Projects', path: ':projectId/', childRoutes: []},
  15. ],
  16. params: {orgId: 'org-slug', projectId: 'project-slug'},
  17. },
  18. });
  19. jest.spyOn(window.location, 'assign').mockImplementation(() => {});
  20. renderGlobalModal();
  21. act(() =>
  22. openModal(modalProps => (
  23. <RedirectToProjectModal {...modalProps} {...routerProps} slug="new-slug" />
  24. ))
  25. );
  26. act(() => jest.advanceTimersByTime(4900));
  27. expect(window.location.assign).not.toHaveBeenCalled();
  28. act(() => jest.advanceTimersByTime(200));
  29. expect(window.location.assign).toHaveBeenCalledTimes(1);
  30. expect(window.location.assign).toHaveBeenCalledWith('/org-slug/new-slug/');
  31. });
  32. });