accountClose.spec.tsx 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. import {OrganizationFixture} from 'sentry-fixture/organization';
  2. import {
  3. render,
  4. renderGlobalModal,
  5. screen,
  6. userEvent,
  7. } from 'sentry-test/reactTestingLibrary';
  8. import AccountClose from 'sentry/views/settings/account/accountClose';
  9. describe('AccountClose', function () {
  10. let deleteMock;
  11. const soloOrgSlug = 'solo-owner';
  12. const nonSingleOwnerSlug = 'non-single-owner';
  13. beforeEach(function () {
  14. MockApiClient.clearMockResponses();
  15. MockApiClient.addMockResponse({
  16. url: '/organizations/',
  17. body: [
  18. {
  19. organization: OrganizationFixture({
  20. slug: soloOrgSlug,
  21. }),
  22. singleOwner: true,
  23. },
  24. {
  25. organization: OrganizationFixture({
  26. id: '4',
  27. slug: nonSingleOwnerSlug,
  28. }),
  29. singleOwner: false,
  30. },
  31. ],
  32. });
  33. deleteMock = MockApiClient.addMockResponse({
  34. url: '/users/me/',
  35. method: 'DELETE',
  36. });
  37. });
  38. it('lists all orgs user is an owner of', async function () {
  39. render(<AccountClose />);
  40. renderGlobalModal();
  41. // Input for single owner org
  42. const singleOwner = await screen.findByRole('checkbox', {name: soloOrgSlug});
  43. expect(singleOwner).toBeChecked();
  44. expect(singleOwner).toBeDisabled();
  45. // Input for non-single-owner org
  46. const nonSingleOwner = screen.getByRole('checkbox', {name: nonSingleOwnerSlug});
  47. expect(nonSingleOwner).not.toBeChecked();
  48. expect(nonSingleOwner).toBeEnabled();
  49. // Can check 2nd org
  50. await userEvent.click(nonSingleOwner);
  51. expect(nonSingleOwner).toBeChecked();
  52. // Delete
  53. await userEvent.click(screen.getByRole('button', {name: 'Close Account'}));
  54. expect(
  55. screen.getByText(
  56. 'This is permanent and cannot be undone, are you really sure you want to do this?'
  57. )
  58. ).toBeInTheDocument();
  59. await userEvent.click(screen.getByText('Confirm'));
  60. await screen.findByText(
  61. 'Your account has been deactivated and scheduled for removal.'
  62. );
  63. expect(deleteMock).toHaveBeenCalledWith(
  64. '/users/me/',
  65. expect.objectContaining({
  66. data: {
  67. organizations: [soloOrgSlug, nonSingleOwnerSlug],
  68. },
  69. })
  70. );
  71. });
  72. });