index.spec.tsx 5.5 KB

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