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. const {container} = render(
  18. <BreadcrumbContextProvider>
  19. <SettingsIndex {...props} organization={TestStubs.Organization()} />
  20. </BreadcrumbContextProvider>
  21. );
  22. expect(container).toSnapshot();
  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={TestStubs.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. } as Organization;
  49. const spy = jest.spyOn(OrgActions, 'fetchOrganizationDetails');
  50. const api = MockApiClient.addMockResponse({
  51. url: `/organizations/${organization.slug}/`,
  52. });
  53. beforeEach(function () {
  54. ConfigStore.set('isSelfHosted', false);
  55. spy.mockClear();
  56. api.mockClear();
  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(organization.slug, {
  71. setActive: true,
  72. loadProjects: true,
  73. });
  74. expect(api).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(api).not.toHaveBeenCalled();
  90. });
  91. });
  92. });