@@ -12,8 +12,8 @@ import { spy } from "sinon";
12
12
import { CSSTransitionProps } from "./csstransition" ;
13
13
import { transit } from "./transit" ;
14
14
import {
15
- reduce , StateID , StateIDList , ActionID , CSSTransitionState ,
16
- getAppearStyle , getAppearPendingStyle , getEnterPendingStyle , getLeavePendingStyle ,
15
+ reduce , StateID , StateIDList , ActionID , CSSTransitionState , getState ,
16
+ getDelay , transitionNames ,
17
17
defaultInitState , activeInitState , appearInitState ,
18
18
defaultState , activeState ,
19
19
appearPendingState , enterPendingState , leavePendingState ,
@@ -22,48 +22,79 @@ import {
22
22
} from "./csstransitionstate" ;
23
23
24
24
describe ( "csstransitionstate.ts" , ( ) => {
25
- describe ( "getAppearStyle()" , ( ) => {
26
- it ( "should return appearStyle" , ( ) => {
27
- const props : any = { appearStyle : { } } ;
28
- assert . strictEqual ( getAppearStyle ( props ) , props . appearStyle ) ;
25
+ describe ( "getDelay()" , ( ) => {
26
+ it ( "should process number" , ( ) => {
27
+ transitionNames . forEach ( ( name ) => assert . strictEqual ( getDelay ( name , 200 ) , 200 ) ) ;
29
28
} ) ;
30
- it ( "should fallback to enterStyle" , ( ) => {
31
- const props : any = { enterStyle : { } } ;
32
- assert . strictEqual ( getAppearStyle ( props ) , props . enterStyle ) ;
29
+
30
+ it ( "should process object" , ( ) => {
31
+ transitionNames . forEach ( ( name ) => assert . strictEqual ( getDelay ( name , { [ name ] : 100 } ) , 100 ) ) ;
33
32
} ) ;
34
33
} ) ;
35
- describe ( "getEnterPendingStyle()" , ( ) => {
36
- it ( "should return enterInitStyle" , ( ) => {
37
- const props : any = { enterInitStyle : { } } ;
38
- assert . strictEqual ( getEnterPendingStyle ( props ) , props . enterInitStyle ) ;
39
- } ) ;
40
- it ( "should fallback to defaultStyle" , ( ) => {
41
- const props : any = { defaultStyle : { } } ;
42
- assert . strictEqual ( getEnterPendingStyle ( props ) , props . defaultStyle ) ;
34
+ describe ( "getState()" , ( ) => {
35
+ it ( "should return active / default state" , ( ) => {
36
+ [ "active" , "default" ] . forEach ( ( name ) => {
37
+ const id = StateID . Active ;
38
+ const style = { left : "0px" } ;
39
+ assert . deepEqual (
40
+ getState ( id , name , { [ name + "Style" ] : style } ) , {
41
+ id,
42
+ style,
43
+ } ) ;
44
+ } ) ;
43
45
} ) ;
44
- } ) ;
45
- describe ( "getLeavePendingStyle()" , ( ) => {
46
- it ( "should return leaveInitStyle" , ( ) => {
47
- const props : any = { leaveInitStyle : { } } ;
48
- assert . strictEqual ( getLeavePendingStyle ( props ) , props . leaveInitStyle ) ;
46
+ it ( "should return transition state" , ( ) => {
47
+ transitionNames . forEach ( ( name ) => {
48
+ const id = StateID . EnterStarted ;
49
+ const style = { top : transit ( "5px" , 120 ) } ;
50
+ const styleProcessed = { top : "5px" , transition : "top 120ms ease 0ms" } ;
51
+ assert . deepEqual (
52
+ getState ( id , name , { [ name + "Style" ] : style } ) , {
53
+ id,
54
+ style : styleProcessed ,
55
+ } ) ;
56
+ } ) ;
49
57
} ) ;
50
- it ( "should fallback to activeStyle" , ( ) => {
51
- const props : any = { activeStyle : { } } ;
52
- assert . strictEqual ( getLeavePendingStyle ( props ) , props . activeStyle ) ;
58
+ it ( "should return transition init state" , ( ) => {
59
+ transitionNames . forEach ( ( name ) => {
60
+ const id = StateID . EnterStarted ;
61
+ const style = { left : "0px" } ;
62
+ assert . deepEqual (
63
+ getState ( id , name , { [ name + "InitStyle" ] : style , [ name + "Style" ] : { } } , { init : true } ) , {
64
+ id,
65
+ style,
66
+ } ) ;
67
+ } ) ;
53
68
} ) ;
54
- } ) ;
55
- describe ( "getAppearPendingStyle()" , ( ) => {
56
- it ( "should return appearInitStyle" , ( ) => {
57
- const props : any = { appearInitStyle : { } , appearStyle : { } } ;
58
- assert . strictEqual ( getAppearPendingStyle ( props ) , props . appearInitStyle ) ;
69
+ it ( "should return transition init fallback state" , ( ) => {
70
+ transitionNames . forEach ( ( name ) => {
71
+ const fallbackName = name === "leave" ? "active" : "default" ;
72
+ const id = StateID . EnterStarted ;
73
+ const style = { left : "0px" } ;
74
+ assert . deepEqual (
75
+ getState ( id , name , { [ fallbackName + "Style" ] : style , [ name + "Style" ] : { } } , { init : true } ) , {
76
+ id,
77
+ style,
78
+ } ) ;
79
+ } ) ;
59
80
} ) ;
60
- it ( "should fallback to enterInitStyle" , ( ) => {
61
- const props : any = { enterInitStyle : { } } ;
62
- assert . strictEqual ( getAppearPendingStyle ( props ) , props . enterInitStyle ) ;
81
+ it ( "should fallback to enter for appear" , ( ) => {
82
+ const id = StateID . AppearInit ;
83
+ const style = { left : "0px" } ;
84
+ assert . deepEqual (
85
+ getState ( id , "appear" , { enterStyle : style } ) , {
86
+ id,
87
+ style,
88
+ } ) ;
63
89
} ) ;
64
- it ( "should fallback to defaultStyle" , ( ) => {
65
- const props : any = { defaultStyle : { } } ;
66
- assert . strictEqual ( getAppearPendingStyle ( props ) , props . defaultStyle ) ;
90
+ it ( "should fallback to enterInit for appearInit" , ( ) => {
91
+ const id = StateID . AppearInit ;
92
+ const style = { left : "0px" } ;
93
+ assert . deepEqual (
94
+ getState ( id , "appear" , { enterInitStyle : style } , { init : true } ) , {
95
+ id,
96
+ style,
97
+ } ) ;
67
98
} ) ;
68
99
} ) ;
69
100
describe ( "states" , ( ) => {
@@ -77,7 +108,7 @@ describe("csstransitionstate.ts", () => {
77
108
) ;
78
109
describe (
79
110
"appearInitState" ,
80
- testState ( StateID . AppearInit , "defaultStyle " , ( props ) => appearInitState ( props ) ) ,
111
+ testState ( StateID . AppearInit , "appearInitStyle " , ( props ) => appearInitState ( props ) ) ,
81
112
) ;
82
113
describe (
83
114
"defaultState" ,
@@ -89,15 +120,15 @@ describe("csstransitionstate.ts", () => {
89
120
) ;
90
121
describe (
91
122
"appearPendingState" ,
92
- testState ( StateID . AppearPending , "defaultStyle " , ( props ) => appearPendingState ( props ) ) ,
123
+ testState ( StateID . AppearPending , "appearInitStyle " , ( props ) => appearPendingState ( props ) ) ,
93
124
) ;
94
125
describe (
95
126
"enterPendingState" ,
96
- testState ( StateID . EnterPending , "defaultStyle " , ( props ) => enterPendingState ( props ) ) ,
127
+ testState ( StateID . EnterPending , "enterInitStyle " , ( props ) => enterPendingState ( props ) ) ,
97
128
) ;
98
129
describe (
99
130
"leavePendingState" ,
100
- testState ( StateID . LeavePending , "activeStyle " , ( props ) => leavePendingState ( props ) ) ,
131
+ testState ( StateID . LeavePending , "leaveInitStyle " , ( props ) => leavePendingState ( props ) ) ,
101
132
) ;
102
133
describe (
103
134
"appearTriggeredState" ,
@@ -125,7 +156,7 @@ describe("csstransitionstate.ts", () => {
125
156
) ;
126
157
} ) ;
127
158
describe ( "actions" , ( ) => {
128
- describe ( "ActionInit " , ( ) => {
159
+ describe ( "Init " , ( ) => {
129
160
const actionID = ActionID . Init ;
130
161
131
162
it ( "should fail when state is already initialized" , ( ) => {
@@ -147,6 +178,19 @@ describe("csstransitionstate.ts", () => {
147
178
assert . strictEqual ( state . id , StateID . AppearInit ) ;
148
179
} ) ;
149
180
} ) ;
181
+ describe ( "Mount" , ( ) => {
182
+ const actionID = ActionID . Mount ;
183
+ it ( "should become AppearPending" , ( ) => {
184
+ const id = StateID . AppearInit ;
185
+ const { state, pending} = reduce ( { id } , actionID , { active : true , transitionAppear : true } ) ;
186
+ assert . strictEqual ( pending , ActionID . TransitionTrigger ) ;
187
+ assert . strictEqual ( state . id , StateID . AppearPending ) ;
188
+ } ) ;
189
+
190
+ it ( "should do nothing" , ( ) => {
191
+ assert . isNull ( reduce ( { id : StateID . Active } , actionID , { } ) ) ;
192
+ } ) ;
193
+ } ) ;
150
194
describe ( "TransitionInit" , ( ) => {
151
195
const actionID = ActionID . TransitionInit ;
152
196
const validOrigin = [
@@ -335,37 +379,44 @@ describe("csstransitionstate.ts", () => {
335
379
336
380
function testState ( id : StateID , styleName : string , state : ( props : CSSTransitionProps ) => CSSTransitionState ) {
337
381
return ( ) => {
382
+ const extraProps = [ "appearStyle" , "appearInitStyle" ] . indexOf ( styleName ) > - 1 ? { appearStyle : { } } : { } ;
338
383
it ( "should return id" , ( ) => {
339
384
assert . strictEqual ( state ( { } ) . id , id ) ;
340
385
} ) ;
341
- if ( [ "enterStyle" , "leaveStyle" ] . indexOf ( styleName ) < 0 ) {
386
+ if ( [ "appearStyle" , " enterStyle", "leaveStyle" ] . indexOf ( styleName ) < 0 ) {
342
387
it ( "should return style" , ( ) => {
343
388
const style = { top : "0px" } ;
344
- assert . deepEqual ( state ( { [ styleName ] : style } ) . style , style ) ;
389
+ assert . deepEqual ( state ( { ... extraProps , [ styleName ] : style } ) . style , style ) ;
345
390
} ) ;
346
391
it ( "should return combined style" , ( ) => {
347
392
const style = { top : "0px" } ;
348
393
const baseStyle = { left : "0px" } ;
349
- assert . deepEqual ( state ( { style : baseStyle , [ styleName ] : style } ) . style , { ...baseStyle , ...style } ) ;
394
+ assert . deepEqual (
395
+ state ( { ...extraProps , style : baseStyle , [ styleName ] : style } ) . style ,
396
+ { ...baseStyle , ...style } ,
397
+ ) ;
350
398
} ) ;
351
399
} else {
352
400
it ( "should return transition style" , ( ) => {
353
401
const style = { top : transit ( "5px" , 120 ) } ;
354
402
const styleProcessed = { top : "5px" , transition : "top 120ms ease 0ms" } ;
355
- assert . deepEqual ( state ( { [ styleName ] : style } ) . style , styleProcessed ) ;
403
+ assert . deepEqual ( state ( { ... extraProps , [ styleName ] : style } ) . style , styleProcessed ) ;
356
404
} ) ;
357
405
358
406
it ( "should return combined style" , ( ) => {
359
407
const style = { top : transit ( "5px" , 120 ) } ;
360
408
const styleProcessed = { top : "5px" , transition : "top 120ms ease 0ms" } ;
361
409
const baseStyle = { left : "0px" } ;
362
- assert . deepEqual ( state ( { style : baseStyle , [ styleName ] : style } ) . style , { ...baseStyle , ...styleProcessed } ) ;
410
+ assert . deepEqual (
411
+ state ( { ...extraProps , style : baseStyle , [ styleName ] : style } ) . style ,
412
+ { ...baseStyle , ...styleProcessed } ,
413
+ ) ;
363
414
} ) ;
364
415
365
416
it ( "should return transition style with extra delay" , ( ) => {
366
417
const style = { top : transit ( "5px" , 120 , "ease" , 10 ) } ;
367
418
const styleProcessed = { top : "5px" , transition : "top 120ms ease 30ms" } ;
368
- assert . deepEqual ( state ( { [ styleName ] : style , transitionDelay : 20 } ) . style , styleProcessed ) ;
419
+ assert . deepEqual ( state ( { ... extraProps , [ styleName ] : style , transitionDelay : 20 } ) . style , styleProcessed ) ;
369
420
} ) ;
370
421
}
371
422
} ;
0 commit comments