navigation.spec.jsx 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  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. ProjectsStore.init();
  10. const initialData = initializeOrg({
  11. router: {
  12. location: {query: {}, search: ''},
  13. push: jest.fn(),
  14. },
  15. });
  16. router = initialData.router;
  17. ProjectsStore.loadInitialData(initialData.organization.projects);
  18. });
  19. afterEach(() => {
  20. ProjectsStore.reset();
  21. ProjectsStore.teardown();
  22. jest.resetAllMocks();
  23. });
  24. it('should get project from query parameters', () => {
  25. router.location.query.project = '2';
  26. expect(navigateTo('/settings/:projectId/alert', router)).toBe();
  27. expect(openModal).not.toHaveBeenCalled();
  28. expect(router.push).toHaveBeenCalledWith('/settings/project-slug/alert');
  29. });
  30. it('should get project id from query parameters', () => {
  31. router.location.query.project = '2';
  32. expect(
  33. navigateTo(
  34. '/organizations/albertos-apples/performance/?project=:project#performance-sidequest',
  35. router
  36. )
  37. ).toBe();
  38. expect(openModal).not.toHaveBeenCalled();
  39. expect(router.push).toHaveBeenCalledWith(
  40. '/organizations/albertos-apples/performance/?project=2#performance-sidequest'
  41. );
  42. });
  43. it('should get project and project id from query parameters', () => {
  44. router.location.query.project = '2';
  45. expect(
  46. navigateTo(
  47. '/settings/:projectId/alert?project=:project#performance-sidequest',
  48. router
  49. )
  50. ).toBe();
  51. expect(openModal).not.toHaveBeenCalled();
  52. expect(router.push).toHaveBeenCalledWith(
  53. '/settings/project-slug/alert?project=2#performance-sidequest'
  54. );
  55. });
  56. it('should open modal if the store is somehow missing selected projectId', () => {
  57. router.location.query.project = '911';
  58. expect(navigateTo('/settings/:projectId/alert', router)).toBe();
  59. expect(openModal).toHaveBeenCalled();
  60. });
  61. it('should open modal when no project is selected', () => {
  62. expect(navigateTo('/settings/:projectId/alert', router)).toBe();
  63. expect(openModal).toHaveBeenCalled();
  64. });
  65. it('should open modal when no project id is selected', () => {
  66. expect(
  67. navigateTo(
  68. '/organizations/albertos-apples/performance/?project=:project#performance-sidequest',
  69. router
  70. )
  71. ).toBe();
  72. expect(openModal).toHaveBeenCalled();
  73. });
  74. it('should open modal if more than one project is selected', () => {
  75. router.location.query.project = ['1', '2', '3'];
  76. expect(navigateTo('/settings/:projectId/alert', router)).toBe();
  77. expect(openModal).toHaveBeenCalled();
  78. });
  79. it('should not open modal if url does not require project id', () => {
  80. expect(navigateTo('/settings/alert', router)).toBe();
  81. expect(openModal).not.toHaveBeenCalled();
  82. expect(router.push).toHaveBeenCalledWith('/settings/alert');
  83. });
  84. it('should open modal for orgId', () => {
  85. expect(navigateTo('/settings/:orgId', router)).toBe();
  86. expect(openModal).toHaveBeenCalled();
  87. });
  88. });