|
1 |
| -/* eslint-disable import/no-named-as-default-member */ |
2 | 1 | import { mount } from 'enzyme';
|
3 | 2 | import KeyCode from 'rc-util/lib/KeyCode';
|
4 | 3 | import classNames from 'classnames';
|
5 | 4 | import * as React from 'react';
|
6 |
| -import Select, { OptGroup, Option } from '../src'; |
| 5 | +import Select, { BaseSelect, OptGroup, Option } from '../src'; |
7 | 6 | import allowClearTest from './shared/allowClearTest';
|
8 | 7 | import blurTest from './shared/blurTest';
|
9 | 8 | import dynamicChildrenTest from './shared/dynamicChildrenTest';
|
@@ -329,6 +328,63 @@ describe('Select.Tags', () => {
|
329 | 328 |
|
330 | 329 | expect(tagRender).toHaveBeenCalledWith(expect.objectContaining({ closable: false }));
|
331 | 330 | });
|
| 331 | + |
| 332 | + it('should keep key', () => { |
| 333 | + const MyTag = ({ onClose, label }: any) => { |
| 334 | + const [closed, setClosed] = React.useState(false); |
| 335 | + |
| 336 | + return ( |
| 337 | + <span |
| 338 | + className="my-tag" |
| 339 | + onClick={() => { |
| 340 | + setClosed(true); |
| 341 | + onClose(); |
| 342 | + }} |
| 343 | + > |
| 344 | + {label} |
| 345 | + {String(closed)} |
| 346 | + </span> |
| 347 | + ); |
| 348 | + }; |
| 349 | + |
| 350 | + const onDisplayValuesChange = jest.fn(); |
| 351 | + |
| 352 | + const wrapper = mount( |
| 353 | + <BaseSelect |
| 354 | + mode="tags" |
| 355 | + maxTagCount={99} |
| 356 | + tagRender={(props) => <MyTag {...props} />} |
| 357 | + onDisplayValuesChange={onDisplayValuesChange} |
| 358 | + displayValues={[ |
| 359 | + { |
| 360 | + label: '1', |
| 361 | + value: 1, |
| 362 | + }, |
| 363 | + { |
| 364 | + label: '2', |
| 365 | + value: 2, |
| 366 | + }, |
| 367 | + ]} |
| 368 | + {...({} as any)} |
| 369 | + />, |
| 370 | + ); |
| 371 | + |
| 372 | + wrapper.find('.my-tag').at(0).simulate('click'); |
| 373 | + expect(onDisplayValuesChange).toHaveBeenCalled(); |
| 374 | + |
| 375 | + // Update |
| 376 | + wrapper.setProps({ |
| 377 | + displayValues: [ |
| 378 | + { |
| 379 | + label: '2', |
| 380 | + value: 2, |
| 381 | + }, |
| 382 | + ], |
| 383 | + }); |
| 384 | + |
| 385 | + expect(wrapper.find('span.my-tag')).toHaveLength(1); |
| 386 | + expect(wrapper.find('span.my-tag').text()).toEqual('2false'); |
| 387 | + }); |
332 | 388 | });
|
333 | 389 |
|
334 | 390 | describe('OptGroup', () => {
|
|
0 commit comments