index.spec.tsx 5.5 KB

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