organizationCrumb.spec.jsx 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  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. 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 = () => {
  16. userEvent.hover(screen.getByRole('link'));
  17. userEvent.click(screen.getAllByRole('option')[1]);
  18. };
  19. const renderComponent = props =>
  20. render(
  21. <OrganizationCrumb
  22. organizations={organizations}
  23. organization={organization}
  24. params={{orgId: organization.slug}}
  25. {...props}
  26. />,
  27. {context: routerContext}
  28. );
  29. beforeEach(function () {
  30. browserHistory.push.mockReset();
  31. });
  32. it('switches organizations on settings index', function () {
  33. const routes = [
  34. {path: '/', childRoutes: []},
  35. {childRoutes: []},
  36. {path: '/foo/', childRoutes: []},
  37. {childRoutes: []},
  38. {path: ':bar', childRoutes: []},
  39. {path: '/settings/', name: 'Settings'},
  40. {name: 'Organizations', path: ':orgId/', childRoutes: []},
  41. ];
  42. const route = routes[6];
  43. renderComponent({routes, route});
  44. switchOrganization();
  45. expect(browserHistory.push).toHaveBeenCalledWith('/settings/org-slug2/');
  46. });
  47. it('switches organizations while on API Keys Details route', function () {
  48. const routes = [
  49. {path: '/', childRoutes: []},
  50. {childRoutes: []},
  51. {path: '/foo/', childRoutes: []},
  52. {childRoutes: []},
  53. {path: ':bar', childRoutes: []},
  54. {path: '/settings/', name: 'Settings'},
  55. {name: 'Organizations', path: ':orgId/', childRoutes: []},
  56. {childRoutes: []},
  57. {path: 'api-keys/', name: 'API Key'},
  58. {path: ':apiKey/', name: 'API Key Details'},
  59. ];
  60. const route = routes[6];
  61. renderComponent({routes, route});
  62. switchOrganization();
  63. expect(browserHistory.push).toHaveBeenCalledWith('/settings/org-slug2/api-keys/');
  64. });
  65. it('switches organizations while on API Keys List route', function () {
  66. const routes = [
  67. {path: '/', childRoutes: []},
  68. {childRoutes: []},
  69. {path: '/foo/', childRoutes: []},
  70. {childRoutes: []},
  71. {path: ':bar', childRoutes: []},
  72. {path: '/settings/', name: 'Settings'},
  73. {name: 'Organizations', path: ':orgId/', childRoutes: []},
  74. {childRoutes: []},
  75. {path: 'api-keys/', name: 'API Key'},
  76. ];
  77. const route = routes[6];
  78. renderComponent({routes, route});
  79. switchOrganization();
  80. expect(browserHistory.push).toHaveBeenCalledWith('/settings/org-slug2/api-keys/');
  81. });
  82. it('switches organizations while in Project Client Keys Details route', function () {
  83. const routes = [
  84. {path: '/', childRoutes: []},
  85. {path: '/settings/', name: 'Settings', childRoutes: []},
  86. {name: 'Organization', path: ':orgId/', childRoutes: []},
  87. {name: 'Project', path: 'projects/:projectId/', childRoutes: []},
  88. {path: 'keys/', name: 'Client Keys'},
  89. {path: ':keyId/', name: 'Details'},
  90. ];
  91. const route = routes[2];
  92. renderComponent({
  93. params: {
  94. orgId: organization.slug,
  95. projectId: project.slug,
  96. },
  97. routes,
  98. route,
  99. });
  100. switchOrganization();
  101. expect(browserHistory.push).toHaveBeenCalledWith('/settings/org-slug2/');
  102. });
  103. });