index.spec.jsx 5.5 KB

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