index.spec.tsx 2.7 KB

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