accountClose.spec.jsx 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  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', 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. // First button is cancel, target Button at index 2
  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. userEvent.click(screen.getByText('Confirm'));
  60. expect(deleteMock).toHaveBeenCalledWith(
  61. '/users/me/',
  62. expect.objectContaining({
  63. data: {
  64. organizations: [soloOrgSlug, nonSingleOwnerSlug],
  65. },
  66. })
  67. );
  68. });
  69. });