index.spec.tsx 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195
  1. import {OrganizationFixture} from 'sentry-fixture/organization';
  2. import {ProjectFixture} from 'sentry-fixture/project';
  3. import {TeamFixture} from 'sentry-fixture/team';
  4. import {initializeOrg} from 'sentry-test/initializeOrg';
  5. import {render, screen, waitFor} from 'sentry-test/reactTestingLibrary';
  6. import {pinFilter} from 'sentry/actionCreators/pageFilters';
  7. import OrganizationStore from 'sentry/stores/organizationStore';
  8. import PageFiltersStore from 'sentry/stores/pageFiltersStore';
  9. import ProjectsStore from 'sentry/stores/projectsStore';
  10. import OrganizationDetails from 'sentry/views/organizationDetails';
  11. jest.mock(
  12. 'sentry/components/sidebar',
  13. () =>
  14. function () {
  15. return <div />;
  16. }
  17. );
  18. describe('OrganizationDetails', function () {
  19. const {routerProps} = initializeOrg();
  20. let getTeamsMock;
  21. let getProjectsMock;
  22. beforeEach(function () {
  23. OrganizationStore.reset();
  24. ProjectsStore.reset();
  25. PageFiltersStore.reset();
  26. MockApiClient.clearMockResponses();
  27. MockApiClient.addMockResponse({
  28. url: '/organizations/org-slug/broadcasts/',
  29. body: [],
  30. });
  31. MockApiClient.addMockResponse({
  32. url: '/organizations/org-slug/environments/',
  33. body: [],
  34. });
  35. getTeamsMock = MockApiClient.addMockResponse({
  36. url: '/organizations/org-slug/teams/',
  37. body: [TeamFixture()],
  38. });
  39. getProjectsMock = MockApiClient.addMockResponse({
  40. url: '/organizations/org-slug/projects/',
  41. body: [ProjectFixture()],
  42. });
  43. });
  44. it('can fetch projects and teams', function () {
  45. MockApiClient.addMockResponse({
  46. url: '/organizations/org-slug/',
  47. body: OrganizationFixture({
  48. slug: 'org-slug',
  49. }),
  50. });
  51. render(
  52. <OrganizationDetails
  53. {...routerProps}
  54. params={{orgId: 'org-slug'}}
  55. includeSidebar={false}
  56. >
  57. <div />
  58. </OrganizationDetails>
  59. );
  60. expect(getTeamsMock).toHaveBeenCalled();
  61. expect(getProjectsMock).toHaveBeenCalled();
  62. });
  63. describe('deletion states', () => {
  64. it('should render a restoration prompt', async function () {
  65. MockApiClient.addMockResponse({
  66. url: '/organizations/org-slug/',
  67. body: OrganizationFixture({
  68. slug: 'org-slug',
  69. status: {
  70. id: 'pending_deletion',
  71. name: 'pending deletion',
  72. },
  73. }),
  74. });
  75. render(
  76. <OrganizationDetails {...routerProps} params={{orgId: 'org-slug'}}>
  77. <div />
  78. </OrganizationDetails>
  79. );
  80. expect(await screen.findByText('Deletion Scheduled')).toBeInTheDocument();
  81. expect(screen.getByLabelText('Restore Organization')).toBeInTheDocument();
  82. expect(
  83. screen.getByText(
  84. 'Would you like to cancel this process and restore the organization back to the original state?'
  85. )
  86. ).toBeInTheDocument();
  87. });
  88. it('should render a restoration prompt without action for members', async function () {
  89. MockApiClient.addMockResponse({
  90. url: '/organizations/org-slug/',
  91. body: OrganizationFixture({
  92. slug: 'org-slug',
  93. access: [],
  94. status: {
  95. id: 'pending_deletion',
  96. name: 'pending deletion',
  97. },
  98. }),
  99. });
  100. render(
  101. <OrganizationDetails {...routerProps} params={{orgId: 'org-slug'}}>
  102. <div />
  103. </OrganizationDetails>
  104. );
  105. expect(await screen.findByText('Deletion Scheduled')).toBeInTheDocument();
  106. const mistakeText = screen.getByText(
  107. 'If this is a mistake, contact an organization owner and ask them to restore this organization.'
  108. );
  109. expect(mistakeText).toBeInTheDocument();
  110. expect(screen.queryByLabelText('Restore Organization')).not.toBeInTheDocument();
  111. });
  112. });
  113. it('should render a deletion in progress prompt', async function () {
  114. MockApiClient.addMockResponse({
  115. url: '/organizations/org-slug/',
  116. body: OrganizationFixture({
  117. slug: 'org-slug',
  118. status: {
  119. id: 'deletion_in_progress',
  120. name: 'deletion in progress',
  121. },
  122. }),
  123. });
  124. render(
  125. <OrganizationDetails {...routerProps} params={{orgId: 'org-slug'}}>
  126. <div />
  127. </OrganizationDetails>
  128. );
  129. const inProgress = await screen.findByText(
  130. 'currently in the process of being deleted from Sentry.',
  131. {exact: false}
  132. );
  133. expect(inProgress).toBeInTheDocument();
  134. expect(screen.queryByLabelText('Restore Organization')).not.toBeInTheDocument();
  135. });
  136. it('should switch organization', async function () {
  137. const body = OrganizationFixture({slug: 'org-slug'});
  138. MockApiClient.addMockResponse({url: '/organizations/org-slug/', body});
  139. MockApiClient.addMockResponse({url: '/organizations/other-org/', body});
  140. MockApiClient.addMockResponse({url: '/organizations/other-org/teams/', body: []});
  141. MockApiClient.addMockResponse({url: '/organizations/other-org/projects/', body: []});
  142. const {rerender} = render(
  143. <OrganizationDetails {...routerProps}>
  144. <div />
  145. </OrganizationDetails>
  146. );
  147. pinFilter('projects', true);
  148. await waitFor(() =>
  149. expect(PageFiltersStore.getState().pinnedFilters).toEqual(new Set(['projects']))
  150. );
  151. rerender(
  152. <OrganizationDetails {...routerProps} params={{orgId: 'org-slug'}}>
  153. <div />
  154. </OrganizationDetails>
  155. );
  156. expect(PageFiltersStore.getState().pinnedFilters).toEqual(new Set(['projects']));
  157. rerender(
  158. <OrganizationDetails {...routerProps} params={{orgId: 'other-org'}}>
  159. <div />
  160. </OrganizationDetails>
  161. );
  162. await waitFor(() =>
  163. expect(PageFiltersStore.getState().pinnedFilters).toEqual(new Set())
  164. );
  165. });
  166. });