ownershipInput.spec.jsx 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. import {mountWithTheme} from 'sentry-test/enzyme';
  2. import {selectByValueAsync} from 'sentry-test/select-new';
  3. import MemberListStore from 'sentry/stores/memberListStore';
  4. import OwnerInput from 'sentry/views/settings/project/projectOwnership/ownerInput';
  5. describe('Project Ownership Input', function () {
  6. let org;
  7. let project;
  8. let put;
  9. beforeEach(function () {
  10. org = TestStubs.Organization();
  11. project = TestStubs.Project();
  12. MockApiClient.addMockResponse({
  13. url: '/organizations/org-slug/members/',
  14. method: 'GET',
  15. body: TestStubs.Members(),
  16. });
  17. put = MockApiClient.addMockResponse({
  18. url: `/projects/${org.slug}/${project.slug}/ownership/`,
  19. method: 'PUT',
  20. body: {raw: 'url:src @dummy@example.com'},
  21. });
  22. MemberListStore.init();
  23. MemberListStore.loadInitialData([
  24. TestStubs.User({id: '1', email: 'bob@example.com'}),
  25. ]);
  26. });
  27. afterEach(() => {
  28. MemberListStore.teardown();
  29. });
  30. it('renders', function () {
  31. const wrapper = mountWithTheme(
  32. <OwnerInput
  33. params={{orgId: org.slug, projectId: project.slug}}
  34. organization={org}
  35. initialText="url:src @dummy@example.com"
  36. project={project}
  37. />
  38. );
  39. const submit = wrapper.find('SaveButton button');
  40. expect(put).not.toHaveBeenCalled();
  41. // if text is unchanged, submit button is disabled
  42. submit.simulate('click');
  43. expect(put).not.toHaveBeenCalled();
  44. wrapper.find('StyledTextArea').simulate('change', {target: {value: 'new'}});
  45. submit.simulate('click');
  46. expect(put).toHaveBeenCalled();
  47. expect(wrapper.find(OwnerInput)).toSnapshot();
  48. });
  49. it('updates on add preserving existing text', async function () {
  50. const wrapper = mountWithTheme(
  51. <OwnerInput
  52. params={{orgId: org.slug, projectId: project.slug}}
  53. organization={org}
  54. initialText="url:src @dummy@example.com"
  55. project={project}
  56. />
  57. );
  58. // Set a path, as path is selected bu default.
  59. const pathInput = wrapper.find('RuleBuilder BuilderInput');
  60. pathInput.simulate('change', {target: {value: 'file.js'}});
  61. // Select the user.
  62. await selectByValueAsync(wrapper, 'user:1', {control: true, name: 'owners'});
  63. wrapper.update();
  64. // Add the new rule.
  65. const button = wrapper.find('RuleBuilder AddButton button');
  66. button.simulate('click');
  67. wrapper.update();
  68. expect(put).toHaveBeenCalledWith(
  69. '/projects/org-slug/project-slug/ownership/',
  70. expect.objectContaining({
  71. data: {
  72. raw: 'url:src @dummy@example.com' + '\n' + 'path:file.js bob@example.com',
  73. },
  74. })
  75. );
  76. });
  77. });