|
| 1 | +/* eslint-disable import/no-named-as-default-member */ |
1 | 2 | import { mount } from 'enzyme';
|
2 | 3 | import KeyCode from 'rc-util/lib/KeyCode';
|
3 | 4 | import classNames from 'classnames';
|
@@ -268,26 +269,58 @@ describe('Select.Tags', () => {
|
268 | 269 | expect(onChange).toHaveBeenCalledWith(['a'], expect.anything());
|
269 | 270 | });
|
270 | 271 |
|
271 |
| - it('can render custom tags', () => { |
272 |
| - const onTagRender = jest.fn(); |
273 |
| - const tagRender = (props: any) => { |
274 |
| - const { label } = props; |
275 |
| - onTagRender(label); |
276 |
| - return ( |
277 |
| - <span className={classNames(label, 'customize-tag')}> |
278 |
| - {label} |
279 |
| - {label} |
280 |
| - </span> |
| 272 | + describe('tagRender', () => { |
| 273 | + it('can render custom tags', () => { |
| 274 | + const onTagRender = jest.fn(); |
| 275 | + const tagRender = (props: any) => { |
| 276 | + const { label } = props; |
| 277 | + onTagRender(label); |
| 278 | + return ( |
| 279 | + <span className={classNames(label, 'customize-tag')}> |
| 280 | + {label} |
| 281 | + {label} |
| 282 | + </span> |
| 283 | + ); |
| 284 | + }; |
| 285 | + const wrapper = mount(<Select mode="tags" tokenSeparators={[',']} tagRender={tagRender} />); |
| 286 | + |
| 287 | + wrapper.find('input').simulate('change', { target: { value: '1,A,42' } }); |
| 288 | + |
| 289 | + expect(wrapper.find('span.A').length).toBe(1); |
| 290 | + expect(wrapper.find('span.A').text()).toBe('AA'); |
| 291 | + expect(onTagRender).toHaveBeenCalled(); |
| 292 | + expect(wrapper.find('.customize-tag')).toHaveLength(3); |
| 293 | + }); |
| 294 | + |
| 295 | + it('disabled', () => { |
| 296 | + const tagRender = jest.fn(); |
| 297 | + mount( |
| 298 | + <Select |
| 299 | + mode="tags" |
| 300 | + disabled |
| 301 | + value={['light']} |
| 302 | + tagRender={tagRender} |
| 303 | + options={[{ value: 'light' }]} |
| 304 | + />, |
281 | 305 | );
|
282 |
| - }; |
283 |
| - const wrapper = mount(<Select mode="tags" tokenSeparators={[',']} tagRender={tagRender} />); |
284 | 306 |
|
285 |
| - wrapper.find('input').simulate('change', { target: { value: '1,A,42' } }); |
| 307 | + expect(tagRender).toHaveBeenCalledWith(expect.objectContaining({ closable: false })); |
| 308 | + }); |
286 | 309 |
|
287 |
| - expect(wrapper.find('span.A').length).toBe(1); |
288 |
| - expect(wrapper.find('span.A').text()).toBe('AA'); |
289 |
| - expect(onTagRender).toHaveBeenCalledTimes(3); |
290 |
| - expect(wrapper.find('.customize-tag')).toHaveLength(3); |
| 310 | + it('option disabled', () => { |
| 311 | + const tagRender = jest.fn(); |
| 312 | + mount( |
| 313 | + <Select |
| 314 | + mode="tags" |
| 315 | + disabled |
| 316 | + value={['light']} |
| 317 | + tagRender={tagRender} |
| 318 | + options={[{ value: 'light', disabled: true }]} |
| 319 | + />, |
| 320 | + ); |
| 321 | + |
| 322 | + expect(tagRender).toHaveBeenCalledWith(expect.objectContaining({ closable: false })); |
| 323 | + }); |
291 | 324 | });
|
292 | 325 |
|
293 | 326 | describe('OptGroup', () => {
|
@@ -326,12 +359,14 @@ describe('Select.Tags', () => {
|
326 | 359 | });
|
327 | 360 |
|
328 | 361 | it('should work fine when filterOption function exists', () => {
|
| 362 | + const LegacyOption = Select.Option as any; // Compatible to legacy usage |
| 363 | + |
329 | 364 | const children = [];
|
330 | 365 | for (let i = 10; i < 36; i += 1) {
|
331 | 366 | children.push(
|
332 |
| - <Option key={i.toString(36) + i} disabled={!(i % 3)}> |
| 367 | + <LegacyOption key={i.toString(36) + i} disabled={!(i % 3)}> |
333 | 368 | {i.toString(36) + i}
|
334 |
| - </Option>, |
| 369 | + </LegacyOption>, |
335 | 370 | );
|
336 | 371 | }
|
337 | 372 | const wrapper = mount(
|
|
0 commit comments