|
1 |
| -import React from 'react'; |
| 1 | +import React, { useState } from 'react'; |
2 | 2 | import { mount } from './enzyme';
|
3 | 3 | import Cascader from '../src';
|
4 | 4 | import { addressOptions } from './demoOptions';
|
@@ -34,6 +34,55 @@ describe('Cascader.Selector', () => {
|
34 | 34 | expect(onChange).toHaveBeenCalledWith([['exist']], expect.anything());
|
35 | 35 | });
|
36 | 36 |
|
| 37 | + it('avoid reuse', () => { |
| 38 | + const Tag: React.FC<any> = ({ children, onClose }) => { |
| 39 | + const [visible, setVisible] = useState(true); |
| 40 | + return ( |
| 41 | + <button |
| 42 | + onClick={() => { |
| 43 | + setVisible(false); |
| 44 | + onClose(); |
| 45 | + }} |
| 46 | + className={visible ? '' : 'reuse'} |
| 47 | + > |
| 48 | + {children} |
| 49 | + </button> |
| 50 | + ); |
| 51 | + }; |
| 52 | + |
| 53 | + const wrapper = mount( |
| 54 | + <Cascader |
| 55 | + options={[ |
| 56 | + { label: 'AA', value: 'aa' }, |
| 57 | + { label: 'BB', value: 'bb' }, |
| 58 | + { label: 'CC', value: 'cc' }, |
| 59 | + { label: 'DD', value: 'dd' }, |
| 60 | + { label: 'EE', value: 'ee' }, |
| 61 | + ]} |
| 62 | + value={[['aa'], ['bb'], ['cc'], ['dd'], ['ee']]} |
| 63 | + onChange={values => { |
| 64 | + wrapper.setProps({ |
| 65 | + value: values, |
| 66 | + }); |
| 67 | + }} |
| 68 | + tagRender={({ label, onClose }) => ( |
| 69 | + <Tag onClose={onClose} id={label}> |
| 70 | + {label} |
| 71 | + </Tag> |
| 72 | + )} |
| 73 | + checkable |
| 74 | + />, |
| 75 | + ); |
| 76 | + |
| 77 | + for (let i = 5; i > 0; i--) { |
| 78 | + const buttons = wrapper.find('button'); |
| 79 | + expect(buttons.length).toBe(i); |
| 80 | + buttons.first().simulate('click'); |
| 81 | + wrapper.update(); |
| 82 | + expect(wrapper.find('.reuse').length).toBe(0); |
| 83 | + } |
| 84 | + }); |
| 85 | + |
37 | 86 | it('when selected modify options', () => {
|
38 | 87 | const wrapper = mount(<Cascader options={addressOptions} open />);
|
39 | 88 |
|
|
0 commit comments