1
1
import parseAnimationValue from '../src/util/parseAnimationValue'
2
- import { produce } from './util/produce'
3
2
4
3
describe ( 'Tailwind Defaults' , ( ) => {
5
4
it . each ( [
6
5
[
7
6
'spin 1s linear infinite' ,
8
- { name : 'spin' , duration : '1s' , timingFunction : 'linear' , iterationCount : 'infinite' } ,
9
- ] ,
10
- [
11
- 'ping 1s cubic-bezier(0, 0, 0.2, 1) infinite' ,
12
7
{
13
- name : 'ping ' ,
8
+ name : 'spin ' ,
14
9
duration : '1s' ,
15
- timingFunction : 'cubic-bezier(0, 0, 0.2, 1) ' ,
10
+ timingFunction : 'linear ' ,
16
11
iterationCount : 'infinite' ,
17
12
} ,
18
13
] ,
19
14
[
20
- 'pulse 2s cubic-bezier(0.4 , 0, 0.6 ) infinite' ,
15
+ 'ping 1s cubic-bezier(0, 0, 0.2, 1 ) infinite' ,
21
16
{
22
- name : 'pulse ' ,
23
- duration : '2s ' ,
24
- timingFunction : 'cubic-bezier(0.4 , 0, 0.6 )' ,
17
+ name : 'ping ' ,
18
+ duration : '1s ' ,
19
+ timingFunction : 'cubic-bezier(0, 0, 0.2, 1 )' ,
25
20
iterationCount : 'infinite' ,
26
21
} ,
27
22
] ,
@@ -48,7 +43,12 @@ describe('MDN Examples', () => {
48
43
] ,
49
44
[
50
45
'slidein 3s linear 1s' ,
51
- { delay : '1s' , duration : '3s' , name : 'slidein' , timingFunction : 'linear' } ,
46
+ {
47
+ delay : '1s' ,
48
+ duration : '3s' ,
49
+ name : 'slidein' ,
50
+ timingFunction : 'linear' ,
51
+ } ,
52
52
] ,
53
53
[ 'slidein 3s' , { duration : '3s' , name : 'slidein' } ] ,
54
54
] ) ( 'should be possible to parse: "%s"' , ( input , expected ) => {
@@ -59,44 +59,28 @@ describe('MDN Examples', () => {
59
59
describe ( 'duration & delay' , ( ) => {
60
60
it . each ( [
61
61
// Positive seconds (integer)
62
- [ 'spin 1s 1s linear' , { duration : '1s' , delay : '1s' } ] ,
63
62
[ 'spin 2s 1s linear' , { duration : '2s' , delay : '1s' } ] ,
64
- [ 'spin 1s 2s linear' , { duration : '1s' , delay : '2s' } ] ,
65
63
66
64
// Negative seconds (integer)
67
- [ 'spin -1s -1s linear' , { duration : '-1s' , delay : '-1s' } ] ,
68
65
[ 'spin -2s -1s linear' , { duration : '-2s' , delay : '-1s' } ] ,
69
- [ 'spin -1s -2s linear' , { duration : '-1s' , delay : '-2s' } ] ,
70
66
71
67
// Positive seconds (float)
72
- [ 'spin 1.321s 1.321s linear' , { duration : '1.321s' , delay : '1.321s' } ] ,
73
68
[ 'spin 2.321s 1.321s linear' , { duration : '2.321s' , delay : '1.321s' } ] ,
74
- [ 'spin 1.321s 2.321s linear' , { duration : '1.321s' , delay : '2.321s' } ] ,
75
69
76
70
// Negative seconds (float)
77
- [ 'spin -1.321s -1.321s linear' , { duration : '-1.321s' , delay : '-1.321s' } ] ,
78
71
[ 'spin -2.321s -1.321s linear' , { duration : '-2.321s' , delay : '-1.321s' } ] ,
79
- [ 'spin -1.321s -2.321s linear' , { duration : '-1.321s' , delay : '-2.321s' } ] ,
80
72
81
73
// Positive milliseconds (integer)
82
- [ 'spin 100ms 100ms linear' , { duration : '100ms' , delay : '100ms' } ] ,
83
74
[ 'spin 200ms 100ms linear' , { duration : '200ms' , delay : '100ms' } ] ,
84
- [ 'spin 100ms 200ms linear' , { duration : '100ms' , delay : '200ms' } ] ,
85
75
86
76
// Negative milliseconds (integer)
87
- [ 'spin -100ms -100ms linear' , { duration : '-100ms' , delay : '-100ms' } ] ,
88
77
[ 'spin -200ms -100ms linear' , { duration : '-200ms' , delay : '-100ms' } ] ,
89
- [ 'spin -100ms -200ms linear' , { duration : '-100ms' , delay : '-200ms' } ] ,
90
78
91
79
// Positive milliseconds (float)
92
- [ 'spin 100.321ms 100.321ms linear' , { duration : '100.321ms' , delay : '100.321ms' } ] ,
93
80
[ 'spin 200.321ms 100.321ms linear' , { duration : '200.321ms' , delay : '100.321ms' } ] ,
94
- [ 'spin 100.321ms 200.321ms linear' , { duration : '100.321ms' , delay : '200.321ms' } ] ,
95
81
96
82
// Negative milliseconds (float)
97
- [ 'spin -100.321ms -100.321ms linear' , { duration : '-100.321ms' , delay : '-100.321ms' } ] ,
98
83
[ 'spin -200.321ms -100.321ms linear' , { duration : '-200.321ms' , delay : '-100.321ms' } ] ,
99
- [ 'spin -100.321ms -200.321ms linear' , { duration : '-100.321ms' , delay : '-200.321ms' } ] ,
100
84
] ) ( 'should be possible to parse "%s" into %o' , ( input , { duration, delay } ) => {
101
85
const parsed = parseAnimationValue ( input )
102
86
expect ( parsed . duration ) . toEqual ( duration )
@@ -127,34 +111,6 @@ describe('iteration count', () => {
127
111
)
128
112
} )
129
113
130
- describe ( 'iteration count' , ( ) => {
131
- it . each ( [
132
- // Number
133
- [ '1 spin 200s 100s linear' , '1' ] ,
134
- [ 'spin 2 200s 100s linear' , '2' ] ,
135
- [ 'spin 200s 3 100s linear' , '3' ] ,
136
- [ 'spin 200s 100s 4 linear' , '4' ] ,
137
- [ 'spin 200s 100s linear 5' , '5' ] ,
138
- [ '100 spin 200s 100s linear' , '100' ] ,
139
- [ 'spin 200 200s 100s linear' , '200' ] ,
140
- [ 'spin 200s 300 100s linear' , '300' ] ,
141
- [ 'spin 200s 100s 400 linear' , '400' ] ,
142
- [ 'spin 200s 100s linear 500' , '500' ] ,
143
-
144
- // Infinite
145
- [ 'infinite spin 200s 100s linear' , 'infinite' ] ,
146
- [ 'spin infinite 200s 100s linear' , 'infinite' ] ,
147
- [ 'spin 200s infinite 100s linear' , 'infinite' ] ,
148
- [ 'spin 200s 100s infinite linear' , 'infinite' ] ,
149
- [ 'spin 200s 100s linear infinite' , 'infinite' ] ,
150
- ] ) (
151
- 'should be possible to parse "%s" with an iteraction count of "%s"' ,
152
- ( input , iterationCount ) => {
153
- expect ( parseAnimationValue ( input ) . iterationCount ) . toEqual ( iterationCount )
154
- }
155
- )
156
- } )
157
-
158
114
describe ( 'multiple animations' , ( ) => {
159
115
it ( 'should be possible to parse multiple applications at once' , ( ) => {
160
116
const input = [
@@ -166,7 +122,12 @@ describe('multiple animations', () => {
166
122
const parsed = parseAnimationValue ( input )
167
123
expect ( parsed ) . toHaveLength ( 3 )
168
124
expect ( parsed ) . toEqual ( [
169
- { name : 'spin' , duration : '1s' , timingFunction : 'linear' , iterationCount : 'infinite' } ,
125
+ {
126
+ name : 'spin' ,
127
+ duration : '1s' ,
128
+ timingFunction : 'linear' ,
129
+ iterationCount : 'infinite' ,
130
+ } ,
170
131
{
171
132
name : 'ping' ,
172
133
duration : '1s' ,
@@ -183,46 +144,21 @@ describe('multiple animations', () => {
183
144
} )
184
145
} )
185
146
186
- describe ( 'randomized crazy big examples' , ( ) => {
187
- function reOrder ( input , offset = 0 ) {
188
- return [ ...input . slice ( offset ) , ...input . slice ( 0 , offset ) ]
189
- }
190
-
191
- it . each (
192
- produce ( ( choose ) => {
193
- const direction = choose ( 'normal' , 'reverse' , 'alternate' , 'alternate-reverse' )
194
- const playState = choose ( 'running' , 'paused' )
195
- const fillMode = choose ( 'none' , 'forwards' , 'backwards' , 'both' )
196
- const iterationCount = choose ( 'infinite' , '1' , '100' )
197
- const timingFunction = choose (
198
- 'linear' ,
199
- 'ease' ,
200
- 'ease-in' ,
201
- 'ease-out' ,
202
- 'ease-in-out' ,
203
- 'cubic-bezier(0, 0, 0.2, 1)' ,
204
- 'steps(4, end)'
205
- )
206
- const name = choose ( 'animation-name-a' , 'animation-name-b' )
207
- const inputArgs = [ direction , playState , fillMode , iterationCount , timingFunction , name ]
208
- const orderOffset = choose ( ...Array ( inputArgs . length ) . keys ( ) )
209
-
210
- return [
211
- // Input
212
- reOrder ( inputArgs , orderOffset ) . join ( ' ' ) ,
213
-
214
- // Output
215
- {
216
- direction,
217
- playState,
218
- fillMode,
219
- iterationCount,
220
- timingFunction,
221
- name,
222
- } ,
223
- ]
224
- } )
225
- ) ( 'should be possible to parse "%s"' , ( input , output ) => {
226
- expect ( parseAnimationValue ( input ) ) . toEqual ( output )
227
- } )
147
+ it . each `
148
+ input | direction | playState | fillMode | iterationCount | timingFunction | duration | delay | name
149
+ ${ '1s spin 1s infinite' } | ${ undefined } | ${ undefined } | ${ undefined } | ${ 'infinite' } | ${ undefined } | ${ '1s' } | ${ '1s' } | ${ 'spin' }
150
+ ${ 'infinite infinite 1s 1s' } | ${ undefined } | ${ undefined } | ${ undefined } | ${ 'infinite' } | ${ undefined } | ${ '1s' } | ${ '1s' } | ${ 'infinite' }
151
+ ${ 'ease 1s ease 1s' } | ${ undefined } | ${ undefined } | ${ undefined } | ${ undefined } | ${ 'ease' } | ${ '1s' } | ${ '1s' } | ${ 'ease' }
152
+ ${ 'normal paused backwards infinite ease-in 1s 2s name' } | ${ 'normal' } | ${ 'paused' } | ${ 'backwards' } | ${ 'infinite' } | ${ 'ease-in' } | ${ '1s' } | ${ '2s' } | ${ 'name' }
153
+ ${ 'paused backwards infinite ease-in 1s 2s name normal' } | ${ 'normal' } | ${ 'paused' } | ${ 'backwards' } | ${ 'infinite' } | ${ 'ease-in' } | ${ '1s' } | ${ '2s' } | ${ 'name' }
154
+ ${ 'backwards infinite ease-in 1s 2s name normal paused' } | ${ 'normal' } | ${ 'paused' } | ${ 'backwards' } | ${ 'infinite' } | ${ 'ease-in' } | ${ '1s' } | ${ '2s' } | ${ 'name' }
155
+ ${ 'infinite ease-in 1s 2s name normal paused backwards' } | ${ 'normal' } | ${ 'paused' } | ${ 'backwards' } | ${ 'infinite' } | ${ 'ease-in' } | ${ '1s' } | ${ '2s' } | ${ 'name' }
156
+ ${ 'ease-in 1s 2s name normal paused backwards infinite' } | ${ 'normal' } | ${ 'paused' } | ${ 'backwards' } | ${ 'infinite' } | ${ 'ease-in' } | ${ '1s' } | ${ '2s' } | ${ 'name' }
157
+ ${ '1s 2s name normal paused backwards infinite ease-in' } | ${ 'normal' } | ${ 'paused' } | ${ 'backwards' } | ${ 'infinite' } | ${ 'ease-in' } | ${ '1s' } | ${ '2s' } | ${ 'name' }
158
+ ${ '2s name normal paused backwards infinite ease-in 1s' } | ${ 'normal' } | ${ 'paused' } | ${ 'backwards' } | ${ 'infinite' } | ${ 'ease-in' } | ${ '2s' } | ${ '1s' } | ${ 'name' }
159
+ ${ 'name normal paused backwards infinite ease-in 1s 2s' } | ${ 'normal' } | ${ 'paused' } | ${ 'backwards' } | ${ 'infinite' } | ${ 'ease-in' } | ${ '1s' } | ${ '2s' } | ${ 'name' }
160
+ ${ ' name normal paused backwards infinite ease-in 1s 2s ' } | ${ 'normal' } | ${ 'paused' } | ${ 'backwards' } | ${ 'infinite' } | ${ 'ease-in' } | ${ '1s' } | ${ '2s' } | ${ 'name' }
161
+ ` ( 'should parse "$input" correctly' , ( { input, ...expected } ) => {
162
+ let parsed = parseAnimationValue ( input )
163
+ expect ( parsed ) . toEqual ( expected )
228
164
} )
0 commit comments