diff --git a/examples/singleFieldNames.tsx b/examples/singleFieldNames.tsx new file mode 100644 index 000000000..232b700e2 --- /dev/null +++ b/examples/singleFieldNames.tsx @@ -0,0 +1,37 @@ +/* eslint-disable no-console */ +import React from 'react'; +import Select from '../src'; +import '../assets/index.less'; +import './single.less'; + +export default () => { + return ( + , + ); + } + + it('fieldNames should work', () => { + const onChange = jest.fn(); + const onSelect = jest.fn(); + + const wrapper = mountSelect({ onChange, onSelect }); + + act(() => { + jest.runAllTimers(); + }); + + // Label match + expect(wrapper.find('.rc-select-item-group').text()).toEqual('Bamboo'); + expect(wrapper.find('.rc-select-item-option').first().text()).toEqual('Light'); + expect(wrapper.find('.rc-select-item-option').last().text()).toEqual('Little'); + + // Click + wrapper.find('.rc-select-item-option-content').last().simulate('click'); + expect(onChange).toHaveBeenCalledWith('little', OPTION_2); + expect(onSelect).toHaveBeenCalledWith('little', OPTION_2); + }); + + it('multiple', () => { + const onChange = jest.fn(); + const wrapper = mountSelect({ mode: 'multiple', onChange }); + + // First one + wrapper.find('.rc-select-item-option-content').first().simulate('click'); + expect(onChange).toHaveBeenCalledWith(['light'], [OPTION_1]); + + // Last one + onChange.mockReset(); + wrapper.find('.rc-select-item-option-content').last().simulate('click'); + expect(onChange).toHaveBeenCalledWith(['light', 'little'], [OPTION_1, OPTION_2]); + }); +});