settingsIndex.spec.tsx 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. import {OrganizationFixture} from 'sentry-fixture/organization';
  2. import {RouterFixture} from 'sentry-fixture/routerFixture';
  3. import {render, screen, waitFor} from 'sentry-test/reactTestingLibrary';
  4. import * as OrgActions from 'sentry/actionCreators/organizations';
  5. import ConfigStore from 'sentry/stores/configStore';
  6. import type {Organization} from 'sentry/types/organization';
  7. import SettingsIndex from 'sentry/views/settings/settingsIndex';
  8. import {BreadcrumbProvider} from './components/settingsBreadcrumb/context';
  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. <BreadcrumbProvider>
  21. <SettingsIndex {...props} organization={OrganizationFixture()} />
  22. </BreadcrumbProvider>
  23. );
  24. });
  25. it('has loading when there is no organization', function () {
  26. render(
  27. <BreadcrumbProvider>
  28. <SettingsIndex {...props} organization={null} />
  29. </BreadcrumbProvider>
  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. <BreadcrumbProvider>
  37. <SettingsIndex {...props} organization={OrganizationFixture()} />
  38. </BreadcrumbProvider>
  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 Organization;
  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. <BreadcrumbProvider>
  63. <SettingsIndex {...props} params={{}} organization={null} />
  64. </BreadcrumbProvider>
  65. );
  66. // org from index endpoint, no `access` info
  67. rerender(
  68. <BreadcrumbProvider>
  69. <SettingsIndex {...props} organization={organization} />
  70. </BreadcrumbProvider>
  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. <BreadcrumbProvider>
  81. <SettingsIndex {...props} params={{}} organization={null} />
  82. </BreadcrumbProvider>
  83. );
  84. // org already has details
  85. rerender(
  86. <BreadcrumbProvider>
  87. <SettingsIndex {...props} organization={OrganizationFixture()} />
  88. </BreadcrumbProvider>
  89. );
  90. expect(spy).not.toHaveBeenCalledWith();
  91. expect(orgApi).not.toHaveBeenCalled();
  92. });
  93. });
  94. });