organizationCrumb.spec.jsx 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  1. import {browserHistory} from 'react-router';
  2. import {initializeOrg} from 'sentry-test/initializeOrg';
  3. import {render, screen, userEvent} from 'sentry-test/reactTestingLibrary';
  4. import OrganizationCrumb from 'sentry/views/settings/components/settingsBreadcrumb/organizationCrumb';
  5. jest.unmock('sentry/utils/recreateRoute');
  6. describe('OrganizationCrumb', function () {
  7. let initialData;
  8. const {organization, project, routerContext} = initializeOrg();
  9. const organizations = [
  10. organization,
  11. TestStubs.Organization({
  12. id: '234',
  13. slug: 'org-slug2',
  14. }),
  15. ];
  16. const switchOrganization = async () => {
  17. await userEvent.hover(screen.getByRole('link'));
  18. await userEvent.click(screen.getAllByRole('option')[1]);
  19. };
  20. const renderComponent = props =>
  21. render(
  22. <OrganizationCrumb
  23. organizations={organizations}
  24. organization={organization}
  25. params={{orgId: organization.slug}}
  26. {...props}
  27. />,
  28. {context: routerContext}
  29. );
  30. beforeEach(function () {
  31. initialData = window.__initialData;
  32. browserHistory.push.mockReset();
  33. window.location.assign.mockReset();
  34. });
  35. afterEach(function () {
  36. window.__initalData = initialData;
  37. });
  38. it('switches organizations on settings index', async function () {
  39. const routes = [
  40. {path: '/', childRoutes: []},
  41. {childRoutes: []},
  42. {path: '/foo/', childRoutes: []},
  43. {childRoutes: []},
  44. {path: ':bar', childRoutes: []},
  45. {path: '/settings/', name: 'Settings'},
  46. {name: 'Organizations', path: ':orgId/', childRoutes: []},
  47. ];
  48. const route = routes[6];
  49. renderComponent({routes, route});
  50. await switchOrganization();
  51. expect(browserHistory.push).toHaveBeenCalledWith('/settings/org-slug2/');
  52. });
  53. it('switches organizations while on API Keys Details route', async function () {
  54. const routes = [
  55. {path: '/', childRoutes: []},
  56. {childRoutes: []},
  57. {path: '/foo/', childRoutes: []},
  58. {childRoutes: []},
  59. {path: ':bar', childRoutes: []},
  60. {path: '/settings/', name: 'Settings'},
  61. {name: 'Organizations', path: ':orgId/', childRoutes: []},
  62. {childRoutes: []},
  63. {path: 'api-keys/', name: 'API Key'},
  64. {path: ':apiKey/', name: 'API Key Details'},
  65. ];
  66. const route = routes[6];
  67. renderComponent({routes, route});
  68. await switchOrganization();
  69. expect(browserHistory.push).toHaveBeenCalledWith('/settings/org-slug2/api-keys/');
  70. });
  71. it('switches organizations while on API Keys List route', async function () {
  72. const routes = [
  73. {path: '/', childRoutes: []},
  74. {childRoutes: []},
  75. {path: '/foo/', childRoutes: []},
  76. {childRoutes: []},
  77. {path: ':bar', childRoutes: []},
  78. {path: '/settings/', name: 'Settings'},
  79. {name: 'Organizations', path: ':orgId/', childRoutes: []},
  80. {childRoutes: []},
  81. {path: 'api-keys/', name: 'API Key'},
  82. ];
  83. const route = routes[6];
  84. renderComponent({routes, route});
  85. await switchOrganization();
  86. expect(browserHistory.push).toHaveBeenCalledWith('/settings/org-slug2/api-keys/');
  87. });
  88. it('switches organizations while in Project Client Keys Details route', async function () {
  89. const routes = [
  90. {path: '/', childRoutes: []},
  91. {path: '/settings/', name: 'Settings', childRoutes: []},
  92. {name: 'Organization', path: ':orgId/', childRoutes: []},
  93. {name: 'Project', path: 'projects/:projectId/', childRoutes: []},
  94. {path: 'keys/', name: 'Client Keys'},
  95. {path: ':keyId/', name: 'Details'},
  96. ];
  97. const route = routes[2];
  98. renderComponent({
  99. params: {
  100. orgId: organization.slug,
  101. projectId: project.slug,
  102. },
  103. routes,
  104. route,
  105. });
  106. await switchOrganization();
  107. expect(browserHistory.push).toHaveBeenCalledWith('/settings/org-slug2/');
  108. });
  109. it('switches organizations for child route with customer domains', async function () {
  110. window.__initialData = {
  111. customerDomain: {
  112. subdomain: 'albertos-apples',
  113. organizationUrl: 'https://albertos-apples.sentry.io',
  114. sentryUrl: 'https://sentry.io',
  115. },
  116. };
  117. const routes = [
  118. {path: '/', childRoutes: []},
  119. {childRoutes: []},
  120. {path: '/foo/', childRoutes: []},
  121. {childRoutes: []},
  122. {path: ':bar', childRoutes: []},
  123. {path: '/settings/', name: 'Settings'},
  124. {name: 'Organizations', path: ':orgId/', childRoutes: []},
  125. {childRoutes: []},
  126. {path: 'api-keys/', name: 'API Key'},
  127. ];
  128. const route = routes[6];
  129. const orgs = [
  130. organization,
  131. TestStubs.Organization({
  132. id: '234',
  133. slug: 'acme',
  134. features: ['customer-domains'],
  135. links: {
  136. organizationUrl: 'https://acme.sentry.io',
  137. },
  138. }),
  139. ];
  140. renderComponent({routes, route, organizations: orgs});
  141. await switchOrganization();
  142. // The double slug doesn't actually show up as we have more routing context present.
  143. expect(window.location.assign).toHaveBeenCalledWith(
  144. 'https://acme.sentry.io/settings/acme/api-keys/'
  145. );
  146. });
  147. });