projectMapperField.spec.jsx 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. import {mountWithTheme} from 'sentry-test/enzyme';
  2. import {selectByValue} from 'sentry-test/select-new';
  3. import {RenderField} from 'app/views/settings/components/forms/projectMapperField';
  4. describe('ProjectMapperField', () => {
  5. let wrapper;
  6. const mappedDropdown = {
  7. placholder: 'hi',
  8. items: [
  9. {value: '1', label: 'label 1'},
  10. {value: '2', label: 'label 2'},
  11. {value: '3', label: 'label 3'},
  12. ],
  13. };
  14. const sentryProjects = [
  15. {id: '23', slug: 'cool', platform: 'javascript', name: 'Cool'},
  16. {id: '24', slug: 'beans', platform: 'python', name: 'Beans'},
  17. ];
  18. let onBlur, onChange, props, existingValues;
  19. beforeEach(() => {
  20. existingValues = [['23', '2']];
  21. onBlur = jest.fn();
  22. onChange = jest.fn();
  23. props = {
  24. mappedDropdown,
  25. sentryProjects,
  26. nextButton: {
  27. url: 'https://vercel.com/dashboard/integrations/icfg_fuqLnwH3IYmcpAKAWY8eoYlR',
  28. next: 'Return to Vercel',
  29. },
  30. value: existingValues,
  31. onChange,
  32. onBlur,
  33. };
  34. });
  35. it('clicking add updates values with current dropdown values', () => {
  36. wrapper = mountWithTheme(<RenderField {...props} />);
  37. selectByValue(wrapper, '24', {control: true, name: 'project'});
  38. selectByValue(wrapper, '1', {control: true, name: 'mappedDropdown'});
  39. wrapper.find('AddProjectWrapper Button').simulate('click');
  40. expect(onBlur).toHaveBeenCalledWith(
  41. [
  42. ['23', '2'],
  43. ['24', '1'],
  44. ],
  45. []
  46. );
  47. expect(onChange).toHaveBeenCalledWith(
  48. [
  49. ['23', '2'],
  50. ['24', '1'],
  51. ],
  52. []
  53. );
  54. });
  55. it('can delete item', () => {
  56. existingValues = [
  57. ['23', '2'],
  58. ['24', '1'],
  59. ];
  60. wrapper = mountWithTheme(<RenderField {...props} value={existingValues} />);
  61. wrapper.find('Button[aria-label="Delete"]').first().simulate('click');
  62. expect(onBlur).toHaveBeenCalledWith([['24', '1']], []);
  63. expect(onChange).toHaveBeenCalledWith([['24', '1']], []);
  64. });
  65. it('handles deleted items without error', () => {});
  66. });