ownerInput.spec.tsx 2.6 KB

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