settingsLayout.spec.jsx 2.1 KB

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