organizationCrumb.spec.jsx 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. import {browserHistory} from 'react-router';
  2. import {mountWithTheme} from 'sentry-test/enzyme';
  3. import {initializeOrg} from 'sentry-test/initializeOrg';
  4. import OrganizationCrumb from 'sentry/views/settings/components/settingsBreadcrumb/organizationCrumb';
  5. jest.unmock('sentry/utils/recreateRoute');
  6. describe('OrganizationCrumb', function () {
  7. const {organization, project, routerContext} = initializeOrg();
  8. const organizations = [
  9. organization,
  10. TestStubs.Organization({
  11. id: '234',
  12. slug: 'org-slug2',
  13. }),
  14. ];
  15. const switchOrganization = async wrapper => {
  16. wrapper.find('Crumb').simulate('mouseEnter');
  17. await tick();
  18. wrapper.update();
  19. wrapper.find('AutoCompleteItem').at(1).simulate('click');
  20. };
  21. const createWrapper = props =>
  22. mountWithTheme(
  23. <OrganizationCrumb
  24. organizations={organizations}
  25. organization={organization}
  26. params={{orgId: organization.slug}}
  27. {...props}
  28. />,
  29. routerContext
  30. );
  31. beforeEach(function () {
  32. browserHistory.push.mockReset();
  33. });
  34. it('switches organizations on settings index', async function () {
  35. const routes = [
  36. {path: '/', childRoutes: []},
  37. {childRoutes: []},
  38. {path: '/foo/', childRoutes: []},
  39. {childRoutes: []},
  40. {path: ':bar', childRoutes: []},
  41. {path: '/settings/', name: 'Settings'},
  42. {name: 'Organizations', path: ':orgId/', childRoutes: []},
  43. ];
  44. const route = routes[6];
  45. const wrapper = createWrapper({
  46. routes,
  47. route,
  48. });
  49. await switchOrganization(wrapper);
  50. expect(browserHistory.push).toHaveBeenCalledWith('/settings/org-slug2/');
  51. });
  52. it('switches organizations while on API Keys Details route', async function () {
  53. const routes = [
  54. {path: '/', childRoutes: []},
  55. {childRoutes: []},
  56. {path: '/foo/', childRoutes: []},
  57. {childRoutes: []},
  58. {path: ':bar', childRoutes: []},
  59. {path: '/settings/', name: 'Settings'},
  60. {name: 'Organizations', path: ':orgId/', childRoutes: []},
  61. {childRoutes: []},
  62. {path: 'api-keys/', name: 'API Key'},
  63. {path: ':apiKey/', name: 'API Key Details'},
  64. ];
  65. const route = routes[6];
  66. const wrapper = createWrapper({
  67. routes,
  68. route,
  69. });
  70. await switchOrganization(wrapper);
  71. expect(browserHistory.push).toHaveBeenCalledWith('/settings/org-slug2/api-keys/');
  72. });
  73. it('switches organizations while on API Keys List route', async function () {
  74. const routes = [
  75. {path: '/', childRoutes: []},
  76. {childRoutes: []},
  77. {path: '/foo/', childRoutes: []},
  78. {childRoutes: []},
  79. {path: ':bar', childRoutes: []},
  80. {path: '/settings/', name: 'Settings'},
  81. {name: 'Organizations', path: ':orgId/', childRoutes: []},
  82. {childRoutes: []},
  83. {path: 'api-keys/', name: 'API Key'},
  84. ];
  85. const route = routes[6];
  86. const wrapper = createWrapper({
  87. routes,
  88. route,
  89. });
  90. await switchOrganization(wrapper);
  91. expect(browserHistory.push).toHaveBeenCalledWith('/settings/org-slug2/api-keys/');
  92. });
  93. it('switches organizations while in Project Client Keys Details route', async function () {
  94. const routes = [
  95. {path: '/', childRoutes: []},
  96. {path: '/settings/', name: 'Settings', childRoutes: []},
  97. {name: 'Organization', path: ':orgId/', childRoutes: []},
  98. {name: 'Project', path: 'projects/:projectId/', childRoutes: []},
  99. {path: 'keys/', name: 'Client Keys'},
  100. {path: ':keyId/', name: 'Details'},
  101. ];
  102. const route = routes[2];
  103. const wrapper = createWrapper({
  104. params: {
  105. orgId: organization.slug,
  106. projectId: project.slug,
  107. },
  108. routes,
  109. route,
  110. });
  111. await switchOrganization(wrapper);
  112. expect(browserHistory.push).toHaveBeenCalledWith('/settings/org-slug2/');
  113. });
  114. });