switchOrganization.spec.jsx 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. import React from 'react';
  2. import {mountWithTheme} from 'sentry-test/enzyme';
  3. import {SwitchOrganization} from 'app/components/sidebar/sidebarDropdown/switchOrganization';
  4. describe('SwitchOrganization', function() {
  5. const routerContext = TestStubs.routerContext();
  6. const {organization} = routerContext.context;
  7. it('can list organizations', function() {
  8. jest.useFakeTimers();
  9. const wrapper = mountWithTheme(
  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. const wrapper = mountWithTheme(
  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. const wrapper = mountWithTheme(
  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. });