accountSettingsLayout.spec.tsx 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. import {OrganizationFixture} from 'sentry-fixture/organization';
  2. import {initializeOrg} from 'sentry-test/initializeOrg';
  3. import {BreadcrumbContextProvider} from 'sentry-test/providers/breadcrumbContextProvider';
  4. import {render} from 'sentry-test/reactTestingLibrary';
  5. import * as OrgActions from 'sentry/actionCreators/organizations';
  6. import AccountSettingsLayout from 'sentry/views/settings/account/accountSettingsLayout';
  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', function () {
  24. const {rerender} = render(
  25. <BreadcrumbContextProvider>
  26. <AccountSettingsLayout {...routerProps}>content</AccountSettingsLayout>
  27. </BreadcrumbContextProvider>
  28. );
  29. // org from index endpoint, no `access` info
  30. rerender(
  31. <BreadcrumbContextProvider>
  32. <AccountSettingsLayout {...routerProps} organization={organization}>
  33. content
  34. </AccountSettingsLayout>
  35. </BreadcrumbContextProvider>
  36. );
  37. expect(spy).toHaveBeenCalledWith(expect.anything(), organization.slug, {
  38. setActive: true,
  39. loadProjects: true,
  40. });
  41. expect(api).toHaveBeenCalledTimes(1);
  42. });
  43. it('does not fetch org details for SidebarDropdown', function () {
  44. const {rerender} = render(
  45. <BreadcrumbContextProvider>
  46. <AccountSettingsLayout {...routerProps}>content</AccountSettingsLayout>
  47. </BreadcrumbContextProvider>
  48. );
  49. rerender(
  50. <BreadcrumbContextProvider>
  51. <AccountSettingsLayout {...routerProps} organization={OrganizationFixture()}>
  52. content
  53. </AccountSettingsLayout>
  54. </BreadcrumbContextProvider>
  55. );
  56. expect(spy).not.toHaveBeenCalledWith();
  57. expect(api).not.toHaveBeenCalled();
  58. });
  59. });