accountSettingsLayout.spec.tsx 2.1 KB

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