1
1
import React , { useState } from 'react' ;
2
+ import ReactDOM from 'react-dom' ;
3
+ import ReactTestUtils from 'react-dom/test-utils' ;
2
4
import Enzyme , { mount } from 'enzyme' ;
3
5
import Adapter from 'enzyme-adapter-react-16' ;
4
6
import assert from 'power-assert' ;
5
7
import dayjs from 'dayjs' ;
8
+ import co from 'co' ;
6
9
import moment from 'moment' ;
7
10
import DatePicker from '../../src/date-picker2/index' ;
8
11
import Form from '../../src/form/index' ;
9
12
import Field from '../../src/field/index' ;
10
13
import { DATE_PICKER_MODE } from '../../src/date-picker2/constant' ;
11
14
import { KEYCODE } from '../../src/util' ;
12
- import { delay } from '../util ' ;
15
+ import '../../src/date-picker2/style.js ' ;
13
16
14
17
Enzyme . configure ( { adapter : new Adapter ( ) } ) ;
15
18
@@ -21,6 +24,34 @@ const { DATE, WEEK, MONTH, QUARTER, YEAR } = DATE_PICKER_MODE;
21
24
const defaultVal = '2020-12-12' ;
22
25
const defaultRangeVal = [ '2020-12-12' , '2020-12-13' ] ;
23
26
const onChange = ( ...args ) => assert ( checkOutput ( ...args ) ) ;
27
+ const delay = time => new Promise ( resolve => setTimeout ( resolve , time ) ) ;
28
+
29
+ const render = element => {
30
+ let inc ;
31
+ const container = document . createElement ( 'div' ) ;
32
+ container . className = 'container' ;
33
+ document . body . appendChild ( container ) ;
34
+ ReactDOM . render ( element , container , function ( ) {
35
+ inc = this ;
36
+ } ) ;
37
+ return {
38
+ setProps : props => {
39
+ ReactDOM . unmountComponentAtNode ( container ) ;
40
+ const clonedElement = React . cloneElement ( element , props ) ;
41
+ ReactDOM . render ( clonedElement , container ) ;
42
+ } ,
43
+ unmount : ( ) => {
44
+ ReactDOM . unmountComponentAtNode ( container ) ;
45
+ document . body . removeChild ( container ) ;
46
+ } ,
47
+ instance : ( ) => {
48
+ return inc ;
49
+ } ,
50
+ find : selector => {
51
+ return container . querySelectorAll ( selector ) ;
52
+ } ,
53
+ } ;
54
+ } ;
24
55
25
56
/* eslint-disable */
26
57
describe ( 'Picker' , ( ) => {
@@ -601,7 +632,7 @@ describe('Picker', () => {
601
632
assert . deepEqual ( getStrValue ( ) , [ '2020-12-12 12:12:12' , '2020-12-13 12:12:35' ] ) ;
602
633
} ) ;
603
634
604
- it ( 'RangePicker cell class names' , async ( ) => {
635
+ it ( 'RangePicker cell class names' , done => {
605
636
wrapper = mount ( < RangePicker defaultPanelValue = { defaultVal } defaultVisible /> ) ;
606
637
607
638
clickDate ( '2020-12-13' ) ;
@@ -614,17 +645,20 @@ describe('Picker', () => {
614
645
assert ( hasClassNames ( findDate ( '2020-12-12' ) , 'next-calendar2-cell-disabled' ) ) ;
615
646
616
647
findDate ( '2020-12-15' ) . simulate ( 'mouseenter' ) ;
617
- await delay ( 20 ) ;
618
- [ '2020-12-13' , '2020-12-14' , '2020-12-15' ] . every ( v =>
619
- assert ( hasClassNames ( findDate ( v ) , 'next-calendar2-cell-hover' ) )
620
- ) ;
621
- assert ( hasClassNames ( findDate ( '2020-12-15' ) , 'next-calendar2-cell-hover-end' ) ) ;
648
+ setTimeout ( ( ) => {
649
+ [ '2020-12-13' , '2020-12-14' , '2020-12-15' ] . every ( v =>
650
+ assert ( hasClassNames ( findDate ( v ) , 'next-calendar2-cell-hover' ) )
651
+ ) ;
652
+ assert ( hasClassNames ( findDate ( '2020-12-15' ) , 'next-calendar2-cell-hover-end' ) ) ;
622
653
623
- findDate ( '2020-12-15' ) . simulate ( 'mouseleave' ) ;
624
- await delay ( 20 ) ;
625
- [ '2020-12-13' , '2020-12-14' , '2020-12-15' ] . every ( v =>
626
- assert ( ! hasClassNames ( findDate ( v ) , 'next-calendar2-cell-hover' ) )
627
- ) ;
654
+ findDate ( '2020-12-15' ) . simulate ( 'mouseleave' ) ;
655
+ setTimeout ( ( ) => {
656
+ [ '2020-12-13' , '2020-12-14' , '2020-12-15' ] . every ( v =>
657
+ assert ( ! hasClassNames ( findDate ( v ) , 'next-calendar2-cell-hover' ) )
658
+ ) ;
659
+ done ( ) ;
660
+ } ) ;
661
+ } ) ;
628
662
} ) ;
629
663
630
664
it ( 'RangePicker panelValue' , ( ) => {
@@ -851,6 +885,20 @@ describe('Picker', () => {
851
885
} ) ;
852
886
853
887
describe ( 'issues' , ( ) => {
888
+ beforeEach ( ( ) => {
889
+ const nodeListArr = [ ] . slice . call ( document . querySelectorAll ( '.next-overlay-wrapper' ) ) ;
890
+
891
+ nodeListArr . forEach ( node => {
892
+ node . parentNode . removeChild ( node ) ;
893
+ } ) ;
894
+ } ) ;
895
+
896
+ afterEach ( ( ) => {
897
+ if ( wrapper ) {
898
+ wrapper . unmount ( ) ;
899
+ wrapper = null ;
900
+ }
901
+ } ) ;
854
902
// https://github.com/alibaba-fusion/next/issues/2641
855
903
it ( 'value controlled issue' , ( ) => {
856
904
function App ( ) {
@@ -915,6 +963,28 @@ describe('Picker', () => {
915
963
assert ( getStrValue ( ) === '2020-12-13' ) ;
916
964
} ) ;
917
965
966
+ it ( 'should support triggerType' , ( ) => {
967
+ return co ( function * ( ) {
968
+ wrapper = render (
969
+ < DatePicker popupTriggerType = { "hover" } />
970
+ ) ;
971
+ const btn = document . querySelector ( '.next-date-picker2 > div' ) ;
972
+
973
+ ReactTestUtils . Simulate . mouseEnter ( btn ) ;
974
+ yield delay ( 300 ) ;
975
+ assert ( document . querySelector ( '.next-overlay-wrapper' ) ) ;
976
+
977
+ ReactTestUtils . Simulate . mouseLeave ( btn ) ;
978
+ ReactTestUtils . Simulate . mouseEnter ( document . querySelector ( '.next-calendar2-body' ) ) ;
979
+ yield delay ( 300 ) ;
980
+ assert ( document . querySelector ( '.next-overlay-wrapper' ) ) ;
981
+
982
+ ReactTestUtils . Simulate . mouseLeave ( document . querySelector ( '.next-calendar2-body' ) ) ;
983
+ yield delay ( 500 ) ;
984
+ assert ( ! document . querySelector ( '.next-overlay-wrapper' ) ) ;
985
+ } ) ;
986
+ } ) ;
987
+
918
988
it ( 'should reset value' , ( ) => {
919
989
const App = ( ) => {
920
990
return (
0 commit comments