ownerInput.spec.tsx 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. import {MembersFixture} from 'sentry-fixture/members';
  2. import {UserFixture} from 'sentry-fixture/user';
  3. import {initializeOrg} from 'sentry-test/initializeOrg';
  4. import {render, screen, userEvent} from 'sentry-test/reactTestingLibrary';
  5. import MemberListStore from 'sentry/stores/memberListStore';
  6. import OwnerInput from 'sentry/views/settings/project/projectOwnership/ownerInput';
  7. describe('Project Ownership Input', function () {
  8. const {organization, project} = initializeOrg();
  9. let put: jest.Mock;
  10. beforeEach(function () {
  11. MockApiClient.addMockResponse({
  12. url: `/organizations/${organization.slug}/members/`,
  13. method: 'GET',
  14. body: MembersFixture(),
  15. });
  16. put = MockApiClient.addMockResponse({
  17. url: `/projects/${organization.slug}/${project.slug}/ownership/`,
  18. method: 'PUT',
  19. body: {raw: 'url:src @dummy@example.com'},
  20. });
  21. MemberListStore.init();
  22. MemberListStore.loadInitialData([UserFixture({id: '1', email: 'bob@example.com'})]);
  23. });
  24. it('renders', async function () {
  25. render(
  26. <OwnerInput
  27. page="issue_details"
  28. onCancel={() => {}}
  29. dateUpdated={null}
  30. organization={organization}
  31. initialText="url:src @dummy@example.com"
  32. project={project}
  33. />
  34. );
  35. const submitButton = screen.getByRole('button', {name: 'Save'});
  36. expect(put).not.toHaveBeenCalled();
  37. // if text is unchanged, submit button is disabled
  38. await userEvent.click(submitButton);
  39. expect(put).not.toHaveBeenCalled();
  40. const textarea = screen.getByRole('textbox', {name: 'Ownership Rules'});
  41. await userEvent.clear(textarea);
  42. await userEvent.type(textarea, 'new');
  43. await userEvent.click(submitButton);
  44. expect(put).toHaveBeenCalled();
  45. });
  46. it('updates on add preserving existing text', async function () {
  47. render(
  48. <OwnerInput
  49. page="issue_details"
  50. onCancel={() => {}}
  51. dateUpdated={null}
  52. organization={organization}
  53. initialText="url:src @dummy@example.com"
  54. project={project}
  55. />
  56. );
  57. await userEvent.type(
  58. screen.getByRole('textbox', {name: 'Ownership Rules'}),
  59. '\npath:file.js bob@example.com'
  60. );
  61. await userEvent.click(screen.getByRole('button', {name: 'Save'}));
  62. expect(put).toHaveBeenCalledWith(
  63. `/projects/${organization.slug}/${project.slug}/ownership/`,
  64. expect.objectContaining({
  65. data: {
  66. raw: 'url:src @dummy@example.com' + '\n' + 'path:file.js bob@example.com',
  67. },
  68. })
  69. );
  70. });
  71. });