redirectToProject.spec.tsx 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  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 {router} = initializeOrg({
  10. router: {
  11. routes: [
  12. {path: '/', childRoutes: []},
  13. {name: 'Organizations', path: ':orgId/', childRoutes: []},
  14. {name: 'Projects', path: ':projectId/', childRoutes: []},
  15. ],
  16. },
  17. });
  18. jest.spyOn(window.location, 'assign').mockImplementation(() => {});
  19. renderGlobalModal();
  20. act(() =>
  21. openModal(modalProps => (
  22. <RedirectToProjectModal
  23. {...modalProps}
  24. routes={router.routes}
  25. router={router}
  26. location={router.location}
  27. slug="new-slug"
  28. params={{orgId: 'org-slug', projectId: 'project-slug'}}
  29. />
  30. ))
  31. );
  32. jest.advanceTimersByTime(4900);
  33. expect(window.location.assign).not.toHaveBeenCalled();
  34. jest.advanceTimersByTime(200);
  35. expect(window.location.assign).toHaveBeenCalledTimes(1);
  36. expect(window.location.assign).toHaveBeenCalledWith('/org-slug/new-slug/');
  37. });
  38. });