index.spec.tsx 5.5 KB

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