settingsIndex.spec.tsx 3.2 KB

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