accountClose.spec.jsx 2.1 KB

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