navigation.spec.jsx 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  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. jest.resetAllMocks();
  22. });
  23. it('should get project from query parameters', () => {
  24. router.location.query.project = '2';
  25. expect(navigateTo('/settings/:projectId/alert', router)).toBe();
  26. expect(openModal).not.toHaveBeenCalled();
  27. expect(router.push).toHaveBeenCalledWith('/settings/project-slug/alert');
  28. });
  29. it('should get project id from query parameters', () => {
  30. router.location.query.project = '2';
  31. expect(
  32. navigateTo(
  33. '/organizations/albertos-apples/performance/?project=:project#performance-sidequest',
  34. router
  35. )
  36. ).toBe();
  37. expect(openModal).not.toHaveBeenCalled();
  38. expect(router.push).toHaveBeenCalledWith(
  39. '/organizations/albertos-apples/performance/?project=2#performance-sidequest'
  40. );
  41. });
  42. it('should get project and project id from query parameters', () => {
  43. router.location.query.project = '2';
  44. expect(
  45. navigateTo(
  46. '/settings/:projectId/alert?project=:project#performance-sidequest',
  47. router
  48. )
  49. ).toBe();
  50. expect(openModal).not.toHaveBeenCalled();
  51. expect(router.push).toHaveBeenCalledWith(
  52. '/settings/project-slug/alert?project=2#performance-sidequest'
  53. );
  54. });
  55. it('should open modal if the store is somehow missing selected projectId', () => {
  56. router.location.query.project = '911';
  57. expect(navigateTo('/settings/:projectId/alert', router)).toBe();
  58. expect(openModal).toHaveBeenCalled();
  59. });
  60. it('should open modal when no project is selected', () => {
  61. expect(navigateTo('/settings/:projectId/alert', router)).toBe();
  62. expect(openModal).toHaveBeenCalled();
  63. });
  64. it('should open modal when no project id is selected', () => {
  65. expect(
  66. navigateTo(
  67. '/organizations/albertos-apples/performance/?project=:project#performance-sidequest',
  68. router
  69. )
  70. ).toBe();
  71. expect(openModal).toHaveBeenCalled();
  72. });
  73. it('should open modal if more than one project is selected', () => {
  74. router.location.query.project = ['1', '2', '3'];
  75. expect(navigateTo('/settings/:projectId/alert', router)).toBe();
  76. expect(openModal).toHaveBeenCalled();
  77. });
  78. it('should not open modal if url does not require project id', () => {
  79. expect(navigateTo('/settings/alert', router)).toBe();
  80. expect(openModal).not.toHaveBeenCalled();
  81. expect(router.push).toHaveBeenCalledWith('/settings/alert');
  82. });
  83. it('should open modal for orgId', () => {
  84. expect(navigateTo('/settings/:orgId', router)).toBe();
  85. expect(openModal).toHaveBeenCalled();
  86. });
  87. it('normalizes URLs for customer domains', function () {
  88. window.__initialData = {
  89. customerDomain: {
  90. subdomain: 'albertos-apples',
  91. organizationUrl: 'https://albertos-apples.sentry.io',
  92. sentryUrl: 'https://sentry.io',
  93. },
  94. };
  95. navigateTo('/settings/org-slug/projects/', router);
  96. expect(openModal).not.toHaveBeenCalled();
  97. expect(router.push).toHaveBeenCalledWith('/settings/projects/');
  98. router.location.query.project = '2';
  99. navigateTo('/settings/org-slug/projects/:projectId/alerts/', router);
  100. expect(openModal).not.toHaveBeenCalled();
  101. expect(router.push).toHaveBeenCalledWith('/settings/projects/project-slug/alerts/');
  102. });
  103. });