index.spec.jsx 5.5 KB

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