settingsIndex.spec.tsx 3.3 KB

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