settingsLayout.spec.tsx 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. import {OrganizationFixture} from 'sentry-fixture/organization';
  2. import {initializeOrg} from 'sentry-test/initializeOrg';
  3. import {render, screen, userEvent} from 'sentry-test/reactTestingLibrary';
  4. import SettingsLayout from 'sentry/views/settings/components/settingsLayout';
  5. import {BreadcrumbProvider} from './settingsBreadcrumb/context';
  6. describe('SettingsLayout', function () {
  7. const {routerProps} = initializeOrg();
  8. beforeEach(function () {
  9. MockApiClient.clearMockResponses();
  10. MockApiClient.addMockResponse({
  11. url: '/organizations/',
  12. body: [OrganizationFixture()],
  13. });
  14. MockApiClient.addMockResponse({
  15. url: '/organizations/org-slug/',
  16. method: 'DELETE',
  17. statusCode: 401,
  18. body: {
  19. sudoRequired: true,
  20. },
  21. });
  22. MockApiClient.addMockResponse({
  23. url: '/authenticators/',
  24. body: [],
  25. });
  26. });
  27. function getTestnav() {
  28. return screen.queryByRole('navigation', {name: 'Test Nav'});
  29. }
  30. it('renders', function () {
  31. render(
  32. <BreadcrumbProvider>
  33. <SettingsLayout {...routerProps}>content</SettingsLayout>
  34. </BreadcrumbProvider>
  35. );
  36. });
  37. it('can render navigation', function () {
  38. render(
  39. <BreadcrumbProvider>
  40. <SettingsLayout
  41. {...routerProps}
  42. renderNavigation={() => <nav aria-label="Test Nav" />}
  43. >
  44. content
  45. </SettingsLayout>
  46. </BreadcrumbProvider>
  47. );
  48. expect(getTestnav()).toBeInTheDocument();
  49. });
  50. it('can toggle mobile navigation', async function () {
  51. render(
  52. <BreadcrumbProvider>
  53. <SettingsLayout
  54. {...routerProps}
  55. renderNavigation={opts =>
  56. opts.isMobileNavVisible ? <nav aria-label="Test Nav" /> : null
  57. }
  58. >
  59. content
  60. </SettingsLayout>
  61. </BreadcrumbProvider>
  62. );
  63. expect(getTestnav()).not.toBeInTheDocument();
  64. await userEvent.click(screen.getByRole('button', {name: 'Open the menu'}));
  65. expect(getTestnav()).toBeInTheDocument();
  66. });
  67. });