12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364 |
- import React from 'react';
- import {mount} from 'enzyme';
- import {SwitchOrganization} from 'app/components/sidebar/sidebarDropdown/switchOrganization';
- describe('SwitchOrganization', function() {
- let routerContext = TestStubs.routerContext();
- let {organization} = routerContext.context;
- it('can list organizations', function() {
- jest.useFakeTimers();
- let wrapper = mount(
- <SwitchOrganization
- organizations={[organization, TestStubs.Organization({slug: 'org2'})]}
- />,
- routerContext
- );
- wrapper.find('SwitchOrganizationMenuActor').simulate('mouseEnter');
- jest.advanceTimersByTime(500);
- wrapper.update();
- expect(wrapper.find('OrganizationList')).toHaveLength(1);
- expect(wrapper.find('OrganizationList SidebarMenuItem')).toHaveLength(2);
- jest.useRealTimers();
- });
- it('shows "Create an Org" if they have permission', function() {
- jest.useFakeTimers();
- let wrapper = mount(
- <SwitchOrganization
- organizations={[organization, TestStubs.Organization({slug: 'org2'})]}
- canCreateOrganization
- />,
- routerContext
- );
- wrapper.find('SwitchOrganizationMenuActor').simulate('mouseEnter');
- jest.advanceTimersByTime(500);
- wrapper.update();
- expect(
- wrapper.find('SidebarMenuItem[data-test-id="sidebar-create-org"]')
- ).toHaveLength(1);
- jest.useRealTimers();
- });
- it('does not have "Create an Org" if they do not have permission', function() {
- jest.useFakeTimers();
- let wrapper = mount(
- <SwitchOrganization
- organizations={[organization, TestStubs.Organization({slug: 'org2'})]}
- canCreateOrganization={false}
- />,
- routerContext
- );
- wrapper.find('SwitchOrganizationMenuActor').simulate('mouseEnter');
- jest.advanceTimersByTime(500);
- wrapper.update();
- expect(
- wrapper.find('SidebarMenuItem[data-test-id="sidebar-create-org"]')
- ).toHaveLength(0);
- jest.useRealTimers();
- });
- });
|