settingsLayout.spec.tsx 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  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. const {container} = render(
  37. <BreadcrumbContextProvider>
  38. <SettingsLayout {...routerProps}>content</SettingsLayout>
  39. </BreadcrumbContextProvider>
  40. );
  41. expect(container).toSnapshot();
  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. });