7
7
*/
8
8
9
9
import * as React from "react" ;
10
-
10
+ import { CSSProperties } from "react" ;
11
11
import { ReactWrapper , mount } from "enzyme" ;
12
12
import { assert } from "chai" ;
13
13
import { SinonSpy , spy } from "sinon" ;
14
14
15
- import { CSSTransitionProps , CSSTransition , transit } from "../src" ;
15
+ import { createTestDiv } from "../utils" ;
16
+ import { CSSTransitionProps , CSSTransition , transit } from "../../src" ;
16
17
17
18
const TICK = 17 ;
18
19
19
- describe ( "integration test" , ( ) => {
20
+ describe ( "basic integration test" , ( ) => {
20
21
describe ( "<CSSTransition>" , ( ) => {
21
- const activeStyle : React . CSSProperties = { width : "100px" } ;
22
- const defaultStyle : React . CSSProperties = { width : "50px" } ;
23
- const enterStyle : React . CSSProperties = { width : transit ( "100px" , 150 , "ease" , 25 ) } ;
24
- const leaveStyle : React . CSSProperties = { width : transit ( "50px" , 150 , "ease" , 25 ) } ;
25
- const enterStyleProcessed : React . CSSProperties = { width : "100px" , transition : "width 150ms ease 25ms" } ;
26
- const leaveStyleProcessed : React . CSSProperties = { width : "50px" , transition : "width 150ms ease 25ms" } ;
22
+ const activeStyle : CSSProperties = { width : "100px" } ;
23
+ const defaultStyle : CSSProperties = { width : "50px" } ;
24
+ const enterStyle : CSSProperties = { width : transit ( "100px" , 150 , "ease" , 25 ) } ;
25
+ const leaveStyle : CSSProperties = { width : transit ( "50px" , 150 , "ease" , 25 ) } ;
26
+ const enterStyleProcessed : CSSProperties = { width : "100px" , transition : "width 150ms ease 25ms" } ;
27
+ const leaveStyleProcessed : CSSProperties = { width : "50px" , transition : "width 150ms ease 25ms" } ;
27
28
let onTransitionComplete : SinonSpy ;
28
29
let getWrapper : ( props ?: CSSTransitionProps ) => ReactWrapper < any , { } > ;
29
30
let getWrapperAttached : ( props ?: CSSTransitionProps ) => ReactWrapper < any , { } > ;
@@ -35,7 +36,7 @@ describe("integration test", () => {
35
36
</ CSSTransition >
36
37
) ;
37
38
getWrapper = ( props ?: CSSTransitionProps ) => mount ( render ( props ) ) ;
38
- getWrapperAttached = ( props ?: CSSTransitionProps ) => mount ( render ( props ) , { attachTo : document . body } ) ;
39
+ getWrapperAttached = ( props ?: CSSTransitionProps ) => mount ( render ( props ) , { attachTo : createTestDiv ( ) } ) ;
39
40
} ) ;
40
41
41
42
it ( "should render dummy text" , ( ) => {
@@ -47,11 +48,10 @@ describe("integration test", () => {
47
48
} ) ;
48
49
49
50
it ( "should pass down unknown props" , ( ) => {
50
- const wrapper = getWrapper ( { id : "abc" , "data-test" : "test" } ) ;
51
+ const wrapper = getWrapper ( { id : "abc" } ) ;
51
52
const div = wrapper . find ( "#abc" ) ;
52
53
assert . lengthOf ( div , 1 ) ;
53
54
assert . strictEqual ( div . type ( ) , "div" ) ;
54
- assert . strictEqual ( ( div . props ( ) as any ) [ "data-test" ] , "test" ) ;
55
55
} ) ;
56
56
57
57
describe ( "transition default -> active" , ( ) => {
@@ -506,132 +506,5 @@ describe("integration test", () => {
506
506
} ) ;
507
507
} ) ;
508
508
} ) ;
509
-
510
- describe ( "transition appear" , ( ) => {
511
- let wrapper : ReactWrapper < any , { } > ;
512
- let target : ReactWrapper < any , { } > ;
513
-
514
- before ( ( ) => {
515
- onTransitionComplete = spy ( ) ;
516
- wrapper = getWrapperAttached ( {
517
- activeStyle, enterStyle, leaveStyle, defaultStyle,
518
- onTransitionComplete,
519
- active : true ,
520
- transitionAppear : true ,
521
- } ) ;
522
- target = wrapper . find ( "div" ) ;
523
- } ) ;
524
-
525
- after ( ( ) => {
526
- wrapper . detach ( ) ;
527
- } ) ;
528
-
529
- it ( "should start with default style" , ( ) => {
530
- const style = target . props ( ) . style ;
531
- assert . deepEqual ( style , defaultStyle ) ;
532
- } ) ;
533
-
534
- describe ( "after mount" , ( ) => {
535
- before ( ( done ) => {
536
- setTimeout ( ( ) => {
537
- done ( ) ;
538
- } , TICK + 5 ) ;
539
- } ) ;
540
-
541
- it ( "should automatically trigger transition" , ( ) => {
542
- const style = target . props ( ) . style ;
543
- assert . deepEqual ( style , enterStyleProcessed ) ;
544
- } ) ;
545
-
546
- describe ( "when transition starts" , ( ) => {
547
- before ( ( done ) => {
548
- setTimeout ( ( ) => {
549
- done ( ) ;
550
- } , 100 ) ;
551
- } ) ;
552
-
553
- it ( "should ignore" , ( ) => {
554
- const style = target . props ( ) . style ;
555
- assert . deepEqual ( style , enterStyleProcessed ) ;
556
- } ) ;
557
-
558
- it ( "should not call onTransitionComplete yet" , ( ) => {
559
- assert . isTrue ( onTransitionComplete . notCalled ) ;
560
- } ) ;
561
- } ) ;
562
-
563
- describe ( "when transition ends" , ( ) => {
564
- before ( ( done ) => {
565
- setTimeout ( ( ) => {
566
- done ( ) ;
567
- } , 100 ) ;
568
- } ) ;
569
-
570
- it ( "should become default" , ( ) => {
571
- const style = target . props ( ) . style ;
572
- assert . deepEqual ( style , activeStyle ) ;
573
- } ) ;
574
-
575
- it ( "should call onTransitionComplete" , ( ) => {
576
- assert . isTrue ( onTransitionComplete . calledOnce ) ;
577
- } ) ;
578
- } ) ;
579
- } ) ;
580
- } ) ;
581
-
582
- describe ( "transition appear interrupted" , ( ) => {
583
- let wrapper : ReactWrapper < any , { } > ;
584
- let target : ReactWrapper < any , { } > ;
585
-
586
- before ( ( ) => {
587
- onTransitionComplete = spy ( ) ;
588
- wrapper = getWrapperAttached ( {
589
- activeStyle, enterStyle, leaveStyle, defaultStyle,
590
- onTransitionComplete,
591
- active : true ,
592
- transitionAppear : true ,
593
- } ) ;
594
- target = wrapper . find ( "div" ) ;
595
- } ) ;
596
-
597
- after ( ( ) => {
598
- wrapper . detach ( ) ;
599
- } ) ;
600
-
601
- it ( "should start with default style" , ( ) => {
602
- const style = target . props ( ) . style ;
603
- assert . deepEqual ( style , defaultStyle ) ;
604
- } ) ;
605
-
606
- describe ( "after mount" , ( ) => {
607
- it ( "should not call onTransitionComplete yet" , ( ) => {
608
- assert . isTrue ( onTransitionComplete . notCalled ) ;
609
- } ) ;
610
-
611
- describe ( "when transition was interrupted" , ( ) => {
612
- before ( ( ) => {
613
- wrapper . setProps ( { active : false } ) ;
614
- } ) ;
615
-
616
- it ( "should remain in default" , ( ) => {
617
- const style = target . props ( ) . style ;
618
- assert . deepEqual ( style , defaultStyle ) ;
619
- } ) ;
620
-
621
- it ( "should continue to remain in default" , ( done ) => {
622
- setTimeout ( ( ) => {
623
- const style = target . props ( ) . style ;
624
- assert . deepEqual ( style , defaultStyle ) ;
625
- done ( ) ;
626
- } , 100 ) ;
627
- } ) ;
628
-
629
- it ( "should call onTransitionComplete" , ( ) => {
630
- assert . isTrue ( onTransitionComplete . calledOnce ) ;
631
- } ) ;
632
- } ) ;
633
- } ) ;
634
- } ) ;
635
-
636
509
} ) ;
637
510
} ) ;
0 commit comments