settingsLayout.spec.tsx 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. import {OrganizationFixture} from 'sentry-fixture/organization';
  2. import {initializeOrg} from 'sentry-test/initializeOrg';
  3. import {BreadcrumbContextProvider} from 'sentry-test/providers/breadcrumbContextProvider';
  4. import {render, screen, userEvent} from 'sentry-test/reactTestingLibrary';
  5. import SettingsLayout from 'sentry/views/settings/components/settingsLayout';
  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. <BreadcrumbContextProvider>
  33. <SettingsLayout {...routerProps}>content</SettingsLayout>
  34. </BreadcrumbContextProvider>
  35. );
  36. });
  37. it('can render navigation', function () {
  38. render(
  39. <BreadcrumbContextProvider>
  40. <SettingsLayout
  41. {...routerProps}
  42. renderNavigation={() => <nav aria-label="Test Nav" />}
  43. >
  44. content
  45. </SettingsLayout>
  46. </BreadcrumbContextProvider>
  47. );
  48. expect(getTestnav()).toBeInTheDocument();
  49. });
  50. it('can toggle mobile navigation', async function () {
  51. render(
  52. <BreadcrumbContextProvider>
  53. <SettingsLayout
  54. {...routerProps}
  55. renderNavigation={opts =>
  56. opts.isMobileNavVisible ? <nav aria-label="Test Nav" /> : null
  57. }
  58. >
  59. content
  60. </SettingsLayout>
  61. </BreadcrumbContextProvider>
  62. );
  63. expect(getTestnav()).not.toBeInTheDocument();
  64. await userEvent.click(screen.getByRole('button', {name: 'Open the menu'}));
  65. expect(getTestnav()).toBeInTheDocument();
  66. });
  67. });