switchOrganization.spec.tsx 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. import {act, render, screen, userEvent} from 'sentry-test/reactTestingLibrary';
  2. import {SwitchOrganization} from 'sentry/components/sidebar/sidebarDropdown/switchOrganization';
  3. describe('SwitchOrganization', function () {
  4. it('can list organizations', function () {
  5. jest.useFakeTimers();
  6. render(
  7. <SwitchOrganization
  8. canCreateOrganization={false}
  9. organizations={[
  10. TestStubs.Organization({name: 'Organization 1'}),
  11. TestStubs.Organization({name: 'Organization 2', slug: 'org2'}),
  12. ]}
  13. />
  14. );
  15. userEvent.hover(screen.getByTestId('sidebar-switch-org'));
  16. act(() => void jest.advanceTimersByTime(500));
  17. expect(screen.getByRole('list')).toBeInTheDocument();
  18. expect(screen.getByText('Organization 1')).toBeInTheDocument();
  19. expect(screen.getByText('Organization 2')).toBeInTheDocument();
  20. jest.useRealTimers();
  21. });
  22. it('shows "Create an Org" if they have permission', function () {
  23. jest.useFakeTimers();
  24. render(<SwitchOrganization canCreateOrganization organizations={[]} />);
  25. userEvent.hover(screen.getByTestId('sidebar-switch-org'));
  26. act(() => void jest.advanceTimersByTime(500));
  27. expect(screen.getByTestId('sidebar-create-org')).toBeInTheDocument();
  28. jest.useRealTimers();
  29. });
  30. it('does not have "Create an Org" if they do not have permission', function () {
  31. jest.useFakeTimers();
  32. render(<SwitchOrganization canCreateOrganization={false} organizations={[]} />);
  33. userEvent.hover(screen.getByTestId('sidebar-switch-org'));
  34. act(() => void jest.advanceTimersByTime(500));
  35. expect(screen.queryByTestId('sidebar-create-org')).not.toBeInTheDocument();
  36. jest.useRealTimers();
  37. });
  38. it('shows orgs pending deletion with a special icon', function () {
  39. const orgPendingDeletion = TestStubs.Organization({
  40. slug: 'org-2',
  41. status: {id: 'pending_deletion', name: 'pending_deletion'},
  42. });
  43. jest.useFakeTimers();
  44. render(
  45. <SwitchOrganization
  46. canCreateOrganization
  47. organizations={[TestStubs.Organization(), orgPendingDeletion]}
  48. />
  49. );
  50. userEvent.hover(screen.getByTestId('sidebar-switch-org'));
  51. act(() => void jest.advanceTimersByTime(500));
  52. expect(screen.getByTestId('pending-deletion-icon')).toBeInTheDocument();
  53. jest.useRealTimers();
  54. });
  55. });