switchOrganization.spec.jsx 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. import React from 'react';
  2. import {mount} from 'enzyme';
  3. import {SwitchOrganization} from 'app/components/sidebar/sidebarDropdown/switchOrganization';
  4. describe('SwitchOrganization', function() {
  5. let routerContext = TestStubs.routerContext();
  6. let {organization} = routerContext.context;
  7. it('can list organizations', function() {
  8. jest.useFakeTimers();
  9. let wrapper = mount(
  10. <SwitchOrganization
  11. organizations={[organization, TestStubs.Organization({slug: 'org2'})]}
  12. />,
  13. routerContext
  14. );
  15. wrapper.find('SwitchOrganizationMenuActor').simulate('mouseEnter');
  16. jest.advanceTimersByTime(500);
  17. wrapper.update();
  18. expect(wrapper.find('OrganizationList')).toHaveLength(1);
  19. expect(wrapper.find('OrganizationList SidebarMenuItem')).toHaveLength(2);
  20. jest.useRealTimers();
  21. });
  22. it('shows "Create an Org" if they have permission', function() {
  23. jest.useFakeTimers();
  24. let wrapper = mount(
  25. <SwitchOrganization
  26. organizations={[organization, TestStubs.Organization({slug: 'org2'})]}
  27. canCreateOrganization
  28. />,
  29. routerContext
  30. );
  31. wrapper.find('SwitchOrganizationMenuActor').simulate('mouseEnter');
  32. jest.advanceTimersByTime(500);
  33. wrapper.update();
  34. expect(
  35. wrapper.find('SidebarMenuItem[data-test-id="sidebar-create-org"]')
  36. ).toHaveLength(1);
  37. jest.useRealTimers();
  38. });
  39. it('does not have "Create an Org" if they do not have permission', function() {
  40. jest.useFakeTimers();
  41. let wrapper = mount(
  42. <SwitchOrganization
  43. organizations={[organization, TestStubs.Organization({slug: 'org2'})]}
  44. canCreateOrganization={false}
  45. />,
  46. routerContext
  47. );
  48. wrapper.find('SwitchOrganizationMenuActor').simulate('mouseEnter');
  49. jest.advanceTimersByTime(500);
  50. wrapper.update();
  51. expect(
  52. wrapper.find('SidebarMenuItem[data-test-id="sidebar-create-org"]')
  53. ).toHaveLength(0);
  54. jest.useRealTimers();
  55. });
  56. });