organizationCrumb.spec.jsx 3.8 KB

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