accountSettingsLayout.spec.tsx 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. import {OrganizationFixture} from 'sentry-fixture/organization';
  2. import {initializeOrg} from 'sentry-test/initializeOrg';
  3. import {render, waitFor} from 'sentry-test/reactTestingLibrary';
  4. import * as OrgActions from 'sentry/actionCreators/organizations';
  5. import AccountSettingsLayout from 'sentry/views/settings/account/accountSettingsLayout';
  6. import {BreadcrumbProvider} from 'sentry/views/settings/components/settingsBreadcrumb/context';
  7. describe('AccountSettingsLayout', function () {
  8. let spy: jest.SpyInstance;
  9. let api: jest.Mock;
  10. const {routerProps} = initializeOrg();
  11. const organization = OrganizationFixture({
  12. id: '44',
  13. name: 'Org Index',
  14. slug: 'org-index',
  15. access: undefined,
  16. });
  17. beforeEach(function () {
  18. spy = jest.spyOn(OrgActions, 'fetchOrganizationDetails');
  19. api = MockApiClient.addMockResponse({
  20. url: `/organizations/${organization.slug}/`,
  21. });
  22. });
  23. it('fetches org details for SidebarDropdown', async function () {
  24. const {rerender} = render(
  25. <BreadcrumbProvider>
  26. <AccountSettingsLayout {...routerProps}>content</AccountSettingsLayout>
  27. </BreadcrumbProvider>
  28. );
  29. // org from index endpoint, no `access` info
  30. rerender(
  31. <BreadcrumbProvider>
  32. <AccountSettingsLayout {...routerProps} organization={organization}>
  33. content
  34. </AccountSettingsLayout>
  35. </BreadcrumbProvider>
  36. );
  37. await waitFor(() => expect(api).toHaveBeenCalledTimes(1));
  38. expect(spy).toHaveBeenCalledWith(expect.anything(), organization.slug, {
  39. setActive: true,
  40. loadProjects: true,
  41. });
  42. });
  43. it('does not fetch org details for SidebarDropdown', function () {
  44. const {rerender} = render(
  45. <BreadcrumbProvider>
  46. <AccountSettingsLayout {...routerProps}>content</AccountSettingsLayout>
  47. </BreadcrumbProvider>
  48. );
  49. rerender(
  50. <BreadcrumbProvider>
  51. <AccountSettingsLayout {...routerProps} organization={OrganizationFixture()}>
  52. content
  53. </AccountSettingsLayout>
  54. </BreadcrumbProvider>
  55. );
  56. expect(spy).not.toHaveBeenCalledWith();
  57. expect(api).not.toHaveBeenCalled();
  58. });
  59. });