accountClose.spec.jsx 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. import React from 'react';
  2. import {mountWithTheme} from 'sentry-test/enzyme';
  3. import AccountClose from 'app/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', function() {
  30. const wrapper = mountWithTheme(<AccountClose />, TestStubs.routerContext());
  31. // Input for single owner org
  32. expect(
  33. wrapper
  34. .find('input')
  35. .first()
  36. .prop('checked')
  37. ).toBe(true);
  38. expect(
  39. wrapper
  40. .find('input')
  41. .first()
  42. .prop('disabled')
  43. ).toBe(true);
  44. // Input for non-single-owner org
  45. expect(
  46. wrapper
  47. .find('input')
  48. .at(1)
  49. .prop('checked')
  50. ).toBe(false);
  51. expect(
  52. wrapper
  53. .find('input')
  54. .at(1)
  55. .prop('disabled')
  56. ).toBe(false);
  57. // Can check 2nd org
  58. wrapper
  59. .find('input')
  60. .at(1)
  61. .simulate('change', {target: {checked: true}});
  62. wrapper.update();
  63. expect(
  64. wrapper
  65. .find('input')
  66. .at(1)
  67. .prop('checked')
  68. ).toBe(true);
  69. // Delete
  70. wrapper.find('Confirm Button').simulate('click');
  71. // First button is cancel, target Button at index 2
  72. wrapper
  73. .find('Modal Button')
  74. .at(1)
  75. .simulate('click');
  76. expect(deleteMock).toHaveBeenCalledWith(
  77. '/users/me/',
  78. expect.objectContaining({
  79. data: {
  80. organizations: ['org-slug', 'non-single-owner'],
  81. },
  82. })
  83. );
  84. });
  85. });