navigation.spec.jsx 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. import {initializeOrg} from 'sentry-test/initializeOrg';
  2. import {openModal} from 'sentry/actionCreators/modal';
  3. import {navigateTo} from 'sentry/actionCreators/navigation';
  4. import ProjectsStore from 'sentry/stores/projectsStore';
  5. jest.mock('sentry/actionCreators/modal');
  6. describe('navigation ActionCreator', () => {
  7. let router;
  8. beforeEach(() => {
  9. const initialData = initializeOrg({
  10. router: {
  11. location: {query: {}, search: ''},
  12. push: jest.fn(),
  13. },
  14. });
  15. router = initialData.router;
  16. ProjectsStore.loadInitialData(initialData.organization.projects);
  17. });
  18. afterEach(() => {
  19. ProjectsStore.reset();
  20. jest.resetAllMocks();
  21. });
  22. it('should get project from query parameters', () => {
  23. router.location.query.project = '2';
  24. expect(navigateTo('/settings/:projectId/alert', router)).toBe();
  25. expect(openModal).not.toHaveBeenCalled();
  26. expect(router.push).toHaveBeenCalledWith('/settings/project-slug/alert');
  27. });
  28. it('should open modal if the store is somehow missing selected projectId', () => {
  29. router.location.query.project = '911';
  30. expect(navigateTo('/settings/:projectId/alert', router)).toBe();
  31. expect(openModal).toHaveBeenCalled();
  32. });
  33. it('should open modal when no project is selected', () => {
  34. expect(navigateTo('/settings/:projectId/alert', router)).toBe();
  35. expect(openModal).toHaveBeenCalled();
  36. });
  37. it('should open modal if more than one project is selected', () => {
  38. router.location.query.project = ['1', '2', '3'];
  39. expect(navigateTo('/settings/:projectId/alert', router)).toBe();
  40. expect(openModal).toHaveBeenCalled();
  41. });
  42. it('should not open modal if url does not require project id', () => {
  43. expect(navigateTo('/settings/alert', router)).toBe();
  44. expect(openModal).not.toHaveBeenCalled();
  45. expect(router.push).toHaveBeenCalledWith('/settings/alert');
  46. });
  47. it('should open modal for orgId', () => {
  48. expect(navigateTo('/settings/:orgId', router)).toBe();
  49. expect(openModal).toHaveBeenCalled();
  50. });
  51. });