accountClose.spec.jsx 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. import {mountWithTheme} from 'sentry-test/enzyme';
  2. import {mountGlobalModal} from 'sentry-test/modal';
  3. import AccountClose from 'sentry/views/settings/account/accountClose';
  4. describe('AccountClose', function () {
  5. let deleteMock;
  6. beforeEach(function () {
  7. MockApiClient.clearMockResponses();
  8. MockApiClient.addMockResponse({
  9. url: '/organizations/?owner=1',
  10. body: [
  11. {
  12. organization: TestStubs.Organization(),
  13. singleOwner: true,
  14. },
  15. {
  16. organization: TestStubs.Organization({
  17. id: '4',
  18. slug: 'non-single-owner',
  19. }),
  20. singleOwner: false,
  21. },
  22. ],
  23. });
  24. deleteMock = MockApiClient.addMockResponse({
  25. url: '/users/me/',
  26. method: 'DELETE',
  27. });
  28. });
  29. it('lists all orgs user is an owner of', async function () {
  30. const wrapper = mountWithTheme(<AccountClose />, TestStubs.routerContext());
  31. // Input for single owner org
  32. expect(wrapper.find('input').first().prop('checked')).toBe(true);
  33. expect(wrapper.find('input').first().prop('disabled')).toBe(true);
  34. // Input for non-single-owner org
  35. expect(wrapper.find('input').at(1).prop('checked')).toBe(false);
  36. expect(wrapper.find('input').at(1).prop('disabled')).toBe(false);
  37. // Can check 2nd org
  38. wrapper
  39. .find('input')
  40. .at(1)
  41. .simulate('change', {target: {checked: true}});
  42. wrapper.update();
  43. expect(wrapper.find('input').at(1).prop('checked')).toBe(true);
  44. // Delete
  45. wrapper.find('Confirm Button').simulate('click');
  46. // First button is cancel, target Button at index 2
  47. const modal = await mountGlobalModal();
  48. modal.find('Button').at(1).simulate('click');
  49. expect(deleteMock).toHaveBeenCalledWith(
  50. '/users/me/',
  51. expect.objectContaining({
  52. data: {
  53. organizations: ['org-slug', 'non-single-owner'],
  54. },
  55. })
  56. );
  57. });
  58. });