redirectToProject.spec.jsx 1.2 KB

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