settingsLayout.spec.tsx 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. import {Organization} 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: '/internal/health/',
  12. body: {
  13. problems: [],
  14. },
  15. });
  16. MockApiClient.addMockResponse({
  17. url: '/organizations/',
  18. body: [Organization()],
  19. });
  20. MockApiClient.addMockResponse({
  21. url: '/organizations/org-slug/',
  22. method: 'DELETE',
  23. statusCode: 401,
  24. body: {
  25. sudoRequired: true,
  26. },
  27. });
  28. MockApiClient.addMockResponse({
  29. url: '/authenticators/',
  30. body: [],
  31. });
  32. });
  33. function getTestnav() {
  34. return screen.queryByRole('navigation', {name: 'Test Nav'});
  35. }
  36. it('renders', function () {
  37. render(
  38. <BreadcrumbContextProvider>
  39. <SettingsLayout {...routerProps}>content</SettingsLayout>
  40. </BreadcrumbContextProvider>
  41. );
  42. });
  43. it('can render navigation', function () {
  44. render(
  45. <BreadcrumbContextProvider>
  46. <SettingsLayout
  47. {...routerProps}
  48. renderNavigation={() => <nav aria-label="Test Nav" />}
  49. >
  50. content
  51. </SettingsLayout>
  52. </BreadcrumbContextProvider>
  53. );
  54. expect(getTestnav()).toBeInTheDocument();
  55. });
  56. it('can toggle mobile navigation', async function () {
  57. render(
  58. <BreadcrumbContextProvider>
  59. <SettingsLayout
  60. {...routerProps}
  61. renderNavigation={opts =>
  62. opts.isMobileNavVisible ? <nav aria-label="Test Nav" /> : null
  63. }
  64. >
  65. content
  66. </SettingsLayout>
  67. </BreadcrumbContextProvider>
  68. );
  69. expect(getTestnav()).not.toBeInTheDocument();
  70. await userEvent.click(screen.getByRole('button', {name: 'Open the menu'}));
  71. expect(getTestnav()).toBeInTheDocument();
  72. });
  73. });