projectMapperField.spec.jsx 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. import {mountWithTheme} from 'sentry-test/enzyme';
  2. import {findOption, openMenu, selectByValue} from 'sentry-test/select-new';
  3. import {RenderField} from 'sentry/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('allows a single Sentry project to map to multiple items but not the value', () => {
  66. existingValues = [['24', '1']];
  67. wrapper = mountWithTheme(<RenderField {...props} value={existingValues} />);
  68. // can find the same project again
  69. openMenu(wrapper, {control: true, name: 'project'});
  70. expect(
  71. findOption(wrapper, {value: '24'}, {control: true, name: 'project'})
  72. ).toHaveLength(1);
  73. // but not the value
  74. openMenu(wrapper, {control: true, name: 'mappedDropdown'});
  75. expect(
  76. findOption(wrapper, {value: '1'}, {control: true, name: 'mappedDropdown'})
  77. ).toHaveLength(0);
  78. // validate we can still find 2
  79. expect(
  80. findOption(wrapper, {value: '2'}, {control: true, name: 'mappedDropdown'})
  81. ).toHaveLength(1);
  82. });
  83. });