settingsLayout.spec.tsx 2.1 KB

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