index.spec.tsx 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. import {OrganizationFixture} from 'sentry-fixture/organization';
  2. import {initializeOrg} from 'sentry-test/initializeOrg';
  3. import {render, screen, userEvent} from 'sentry-test/reactTestingLibrary';
  4. import OrganizationRestore from 'sentry/views/organizationRestore';
  5. describe('OrganizationRestore', function () {
  6. let mockUpdate, mockGet;
  7. const pendingDeleteOrg = OrganizationFixture({
  8. status: {id: 'pending_deletion', name: 'Pending Deletion'},
  9. });
  10. const deleteInProgressOrg = OrganizationFixture({
  11. status: {id: 'deletion_in_progress', name: 'Deletion in progress'},
  12. });
  13. beforeEach(() => {
  14. mockUpdate = MockApiClient.addMockResponse({
  15. url: `/organizations/${pendingDeleteOrg.slug}/`,
  16. method: 'PUT',
  17. status: 200,
  18. body: OrganizationFixture(),
  19. });
  20. });
  21. it('loads the current organization', async () => {
  22. mockGet = MockApiClient.addMockResponse({
  23. url: `/organizations/${pendingDeleteOrg.slug}/`,
  24. method: 'GET',
  25. status: 200,
  26. body: pendingDeleteOrg,
  27. });
  28. const {routerProps, routerContext} = initializeOrg<{orgId: string}>({
  29. organization: pendingDeleteOrg,
  30. });
  31. render(<OrganizationRestore {...routerProps} />, {context: routerContext});
  32. const text = await screen.findByText(/currently scheduled for deletion/);
  33. expect(mockGet).toHaveBeenCalled();
  34. expect(text).toBeInTheDocument();
  35. expect(screen.getByTestId('form-submit')).toBeInTheDocument();
  36. });
  37. it('submits update requests', async () => {
  38. mockGet = MockApiClient.addMockResponse({
  39. url: `/organizations/${pendingDeleteOrg.slug}/`,
  40. method: 'GET',
  41. status: 200,
  42. body: pendingDeleteOrg,
  43. });
  44. const {routerProps, routerContext} = initializeOrg<{orgId: string}>({
  45. organization: pendingDeleteOrg,
  46. });
  47. render(<OrganizationRestore {...routerProps} />, {context: routerContext});
  48. const button = await screen.findByTestId('form-submit');
  49. await userEvent.click(button);
  50. expect(mockUpdate).toHaveBeenCalled();
  51. expect(window.location.assign).toHaveBeenCalledWith(
  52. `/organizations/${pendingDeleteOrg.slug}/issues/`
  53. );
  54. });
  55. it('shows message and no form during deletion', async () => {
  56. mockGet = MockApiClient.addMockResponse({
  57. url: `/organizations/${deleteInProgressOrg.slug}/`,
  58. method: 'GET',
  59. status: 200,
  60. body: deleteInProgressOrg,
  61. });
  62. const {routerProps, routerContext} = initializeOrg<{orgId: string}>({
  63. organization: deleteInProgressOrg,
  64. });
  65. render(<OrganizationRestore {...routerProps} />, {context: routerContext});
  66. const text = await screen.findByText(
  67. /organization is currently in progress of being deleted/
  68. );
  69. expect(text).toBeInTheDocument();
  70. expect(screen.queryByTestId('form-submit')).not.toBeInTheDocument();
  71. });
  72. });