index.spec.jsx 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. import {render, screen, userEvent} from 'sentry-test/reactTestingLibrary';
  2. import SidebarDropdown from 'sentry/components/sidebar/sidebarDropdown';
  3. import ConfigStore from 'sentry/stores/configStore';
  4. function renderDropdown(props) {
  5. const user = ConfigStore.get('user');
  6. const config = ConfigStore.get('config');
  7. const organization = TestStubs.Organization({role: 'member'});
  8. const routerContext = TestStubs.routerContext([
  9. {
  10. organization,
  11. },
  12. ]);
  13. return render(
  14. <SidebarDropdown
  15. orientation="left"
  16. collapsed={false}
  17. user={user}
  18. config={config}
  19. org={organization}
  20. {...props}
  21. />,
  22. {context: routerContext}
  23. );
  24. }
  25. describe('SidebarDropdown', function () {
  26. it('renders', function () {
  27. const {container} = renderDropdown();
  28. expect(container).toSnapshot();
  29. });
  30. it('renders without org links', function () {
  31. const {container} = renderDropdown({hideOrgLinks: true});
  32. expect(container).toSnapshot();
  33. });
  34. it('renders open sidebar', function () {
  35. const config = {...ConfigStore.get('config'), singleOrganization: false};
  36. renderDropdown({collapsed: false, config});
  37. userEvent.click(screen.getByTestId('sidebar-dropdown'));
  38. expect(screen.getByText('Switch organization')).toBeInTheDocument();
  39. });
  40. it('sandbox/demo mode render open sidebar', function () {
  41. ConfigStore.set('demoMode', true);
  42. const config = {...ConfigStore.get('config'), singleOrganization: false};
  43. renderDropdown({collapsed: false, config});
  44. userEvent.click(screen.getByTestId('sidebar-dropdown'));
  45. expect(screen.queryByText('Switch organization')).not.toBeInTheDocument();
  46. });
  47. });