settingsIndex.spec.tsx 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. import {OrganizationFixture} from 'sentry-fixture/organization';
  2. import {RouterFixture} from 'sentry-fixture/routerFixture';
  3. import {BreadcrumbContextProvider} from 'sentry-test/providers/breadcrumbContextProvider';
  4. import {render, screen, waitFor} from 'sentry-test/reactTestingLibrary';
  5. import * as OrgActions from 'sentry/actionCreators/organizations';
  6. import ConfigStore from 'sentry/stores/configStore';
  7. import type {Organization as TOrganization} from 'sentry/types';
  8. import SettingsIndex from 'sentry/views/settings/settingsIndex';
  9. describe('SettingsIndex', function () {
  10. const props = {
  11. router: RouterFixture(),
  12. location: {} as any,
  13. routes: [],
  14. route: {},
  15. params: {},
  16. routeParams: {},
  17. };
  18. it('renders', function () {
  19. render(
  20. <BreadcrumbContextProvider>
  21. <SettingsIndex {...props} organization={OrganizationFixture()} />
  22. </BreadcrumbContextProvider>
  23. );
  24. });
  25. it('has loading when there is no organization', function () {
  26. render(
  27. <BreadcrumbContextProvider>
  28. <SettingsIndex {...props} organization={null} />
  29. </BreadcrumbContextProvider>
  30. );
  31. expect(screen.getByTestId('loading-indicator')).toBeInTheDocument();
  32. });
  33. it('has different links for self-hosted users', function () {
  34. ConfigStore.set('isSelfHosted', true);
  35. render(
  36. <BreadcrumbContextProvider>
  37. <SettingsIndex {...props} organization={OrganizationFixture()} />
  38. </BreadcrumbContextProvider>
  39. );
  40. const formLink = screen.getByText('Community Forums');
  41. expect(formLink).toBeInTheDocument();
  42. expect(formLink).toHaveAttribute('href', 'https://forum.sentry.io/');
  43. });
  44. describe('Fetch org details for Sidebar', function () {
  45. const organization = {
  46. id: '44',
  47. name: 'Org Index',
  48. slug: 'org-index',
  49. features: [],
  50. } as unknown as TOrganization;
  51. const spy = jest.spyOn(OrgActions, 'fetchOrganizationDetails');
  52. let orgApi: jest.Mock;
  53. beforeEach(function () {
  54. ConfigStore.set('isSelfHosted', false);
  55. MockApiClient.clearMockResponses();
  56. orgApi = MockApiClient.addMockResponse({
  57. url: `/organizations/${organization.slug}/`,
  58. });
  59. });
  60. it('fetches org details for SidebarDropdown', async function () {
  61. const {rerender} = render(
  62. <BreadcrumbContextProvider>
  63. <SettingsIndex {...props} params={{}} organization={null} />
  64. </BreadcrumbContextProvider>
  65. );
  66. // org from index endpoint, no `access` info
  67. rerender(
  68. <BreadcrumbContextProvider>
  69. <SettingsIndex {...props} organization={organization} />
  70. </BreadcrumbContextProvider>
  71. );
  72. await waitFor(() => expect(orgApi).toHaveBeenCalledTimes(1));
  73. expect(spy).toHaveBeenCalledWith(expect.anything(), organization.slug, {
  74. setActive: true,
  75. loadProjects: true,
  76. });
  77. });
  78. it('does not fetch org details for SidebarDropdown', function () {
  79. const {rerender} = render(
  80. <BreadcrumbContextProvider>
  81. <SettingsIndex {...props} params={{}} organization={null} />
  82. </BreadcrumbContextProvider>
  83. );
  84. // org already has details
  85. rerender(
  86. <BreadcrumbContextProvider>
  87. <SettingsIndex {...props} organization={OrganizationFixture()} />
  88. </BreadcrumbContextProvider>
  89. );
  90. expect(spy).not.toHaveBeenCalledWith();
  91. expect(orgApi).not.toHaveBeenCalled();
  92. });
  93. });
  94. });