settingsIndex.spec.tsx 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  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. features: [],
  49. } as unknown as Organization;
  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={TestStubs.Organization()} />
  87. </BreadcrumbContextProvider>
  88. );
  89. expect(spy).not.toHaveBeenCalledWith();
  90. expect(orgApi).not.toHaveBeenCalled();
  91. });
  92. });
  93. });