|
3 | 3 | import React from 'react'; |
4 | 4 | import { resetWarned } from 'rc-util/lib/warning'; |
5 | 5 | import { spyElementPrototypes } from 'rc-util/lib/test/domHook'; |
6 | | -import { mount } from 'enzyme'; |
7 | | -import Cascader from '..'; |
| 6 | +import { mount } from './enzyme'; |
| 7 | +import Cascader from '../src'; |
8 | 8 | import { addressOptions, optionsForActiveMenuItems } from './demoOptions'; |
9 | 9 |
|
10 | 10 | describe('Cascader.Basic', () => { |
@@ -368,6 +368,8 @@ describe('Cascader.Basic', () => { |
368 | 368 | value: [], |
369 | 369 | }; |
370 | 370 |
|
| 371 | + timeout = null; |
| 372 | + |
371 | 373 | componentDidMount() { |
372 | 374 | this.timeout = setTimeout(() => { |
373 | 375 | this.setState({ |
@@ -650,47 +652,77 @@ describe('Cascader.Basic', () => { |
650 | 652 | }); |
651 | 653 |
|
652 | 654 | it('focus', () => { |
653 | | - const cascaderRef = React.createRef(); |
| 655 | + const cascaderRef = React.createRef() as any; |
654 | 656 | mount(<Cascader ref={cascaderRef} />); |
655 | 657 |
|
656 | 658 | cascaderRef.current.focus(); |
657 | 659 | expect(focusTimes === 1).toBeTruthy(); |
658 | 660 | }); |
659 | 661 |
|
660 | 662 | it('blur', () => { |
661 | | - const cascaderRef = React.createRef(); |
| 663 | + const cascaderRef = React.createRef() as any; |
662 | 664 | mount(<Cascader ref={cascaderRef} />); |
663 | 665 |
|
664 | 666 | cascaderRef.current.blur(); |
665 | 667 | expect(blurTimes === 1).toBeTruthy(); |
666 | 668 | }); |
667 | 669 | }); |
668 | 670 |
|
669 | | - it('active className', () => { |
670 | | - const wrapper = mount( |
671 | | - <Cascader |
672 | | - open |
673 | | - expandIcon="" |
674 | | - options={[ |
675 | | - { |
676 | | - label: 'Bamboo', |
677 | | - value: 'bamboo', |
678 | | - children: [ |
679 | | - { |
680 | | - label: 'Little', |
681 | | - value: 'little', |
682 | | - }, |
683 | | - ], |
684 | | - }, |
685 | | - ]} |
686 | | - />, |
687 | | - ); |
| 671 | + describe('active className', () => { |
| 672 | + it('expandTrigger: click', () => { |
| 673 | + const wrapper = mount( |
| 674 | + <Cascader |
| 675 | + open |
| 676 | + expandIcon="" |
| 677 | + options={[ |
| 678 | + { |
| 679 | + label: 'Bamboo', |
| 680 | + value: 'bamboo', |
| 681 | + children: [ |
| 682 | + { |
| 683 | + label: 'Little', |
| 684 | + value: 'little', |
| 685 | + }, |
| 686 | + ], |
| 687 | + }, |
| 688 | + ]} |
| 689 | + />, |
| 690 | + ); |
688 | 691 |
|
689 | | - wrapper.clickOption(0, 0); |
690 | | - wrapper.clickOption(1, 0); |
| 692 | + wrapper.clickOption(0, 0); |
| 693 | + wrapper.clickOption(1, 0); |
| 694 | + |
| 695 | + expect(wrapper.find('li.rc-cascader-menu-item-active')).toHaveLength(2); |
| 696 | + expect(wrapper.find('li.rc-cascader-menu-item-active').first().text()).toEqual('Bamboo'); |
| 697 | + expect(wrapper.find('li.rc-cascader-menu-item-active').last().text()).toEqual('Little'); |
| 698 | + }); |
| 699 | + |
| 700 | + it('expandTrigger: hover', () => { |
| 701 | + const wrapper = mount( |
| 702 | + <Cascader |
| 703 | + open |
| 704 | + expandIcon="" |
| 705 | + expandTrigger="hover" |
| 706 | + options={[ |
| 707 | + { |
| 708 | + label: 'Bamboo', |
| 709 | + value: 'bamboo', |
| 710 | + children: [ |
| 711 | + { |
| 712 | + label: 'Little', |
| 713 | + value: 'little', |
| 714 | + }, |
| 715 | + ], |
| 716 | + }, |
| 717 | + ]} |
| 718 | + />, |
| 719 | + ); |
691 | 720 |
|
692 | | - expect(wrapper.find('li.rc-cascader-menu-item-active')).toHaveLength(2); |
693 | | - expect(wrapper.find('li.rc-cascader-menu-item-active').first().text()).toEqual('Bamboo'); |
694 | | - expect(wrapper.find('li.rc-cascader-menu-item-active').last().text()).toEqual('Little'); |
| 721 | + wrapper.clickOption(0, 0, 'mouseEnter'); |
| 722 | + wrapper.clickOption(1, 0, 'mouseEnter'); |
| 723 | + |
| 724 | + expect(wrapper.find('li.rc-cascader-menu-item-active')).toHaveLength(1); |
| 725 | + expect(wrapper.find('li.rc-cascader-menu-item-active').first().text()).toEqual('Bamboo'); |
| 726 | + }); |
695 | 727 | }); |
696 | 728 | }); |
0 commit comments