@@ -23,6 +23,7 @@ describe('ScrollAnimate', function() {
23
23
24
24
describe ( 'Non-directional' , ( ) => {
25
25
const animationClass = 'flip'
26
+ const offset = 100
26
27
27
28
test ( 'should add animation classes' , ( ) => {
28
29
const fixture = createFixture ( scrollAnimate , { animationClass } )
@@ -32,6 +33,14 @@ describe('ScrollAnimate', function() {
32
33
expect ( fixture . getClassName ( ) ) . toEqual ( animationClass )
33
34
} )
34
35
36
+ test ( 'should add animation classes by offset' , ( ) => {
37
+ const fixture = createFixture ( scrollAnimate , { animationClass, offset } )
38
+
39
+ expect ( fixture . getClassName ( ) ) . toBeFalsy ( )
40
+ fixture . scrollDown ( true )
41
+ expect ( fixture . getClassName ( ) ) . toEqual ( animationClass )
42
+ } )
43
+
35
44
test ( 'should toggle animation when repeat is on' , ( ) => {
36
45
const fixture = createFixture (
37
46
scrollAnimate , { animationClass, repeat : true }
@@ -45,6 +54,20 @@ describe('ScrollAnimate', function() {
45
54
fixture . scrollUp ( true )
46
55
expect ( fixture . getClassName ( ) ) . toEqual ( animationClass )
47
56
} )
57
+
58
+ test ( 'should toggle animation when repeat is on by offset' , ( ) => {
59
+ const fixture = createFixture (
60
+ scrollAnimate , { animationClass, repeat : true , offset }
61
+ )
62
+
63
+ expect ( fixture . getClassName ( ) ) . toBeFalsy ( )
64
+ fixture . scrollDown ( true )
65
+ expect ( fixture . getClassName ( ) ) . toEqual ( animationClass )
66
+ fixture . scrollDown ( false )
67
+ expect ( fixture . getClassName ( ) ) . toBeFalsy ( )
68
+ fixture . scrollUp ( true )
69
+ expect ( fixture . getClassName ( ) ) . toEqual ( animationClass )
70
+ } )
48
71
49
72
test ( 'should not toggle animation when repeat is off' , ( ) => {
50
73
const fixture = createFixture (
@@ -64,6 +87,210 @@ describe('ScrollAnimate', function() {
64
87
expect ( fixture . getClassName ( ) ) . toEqual ( animationClass )
65
88
} )
66
89
90
+ test ( 'should not toggle animation when repeat is off by offset' , ( ) => {
91
+ const fixture = createFixture (
92
+ scrollAnimate , { animationClass, repeat : false , offset }
93
+ )
94
+
95
+ expect ( fixture . getClassName ( ) ) . toBeFalsy ( )
96
+ fixture . scrollDown ( true )
97
+ expect ( fixture . getClassName ( ) ) . toEqual ( animationClass )
98
+ fixture . scrollDown ( false )
99
+ expect ( fixture . getClassName ( ) ) . toEqual ( animationClass )
100
+ fixture . scrollUp ( true )
101
+ expect ( fixture . getClassName ( ) ) . toEqual ( animationClass )
102
+ fixture . scrollUp ( false )
103
+ fixture . scrollDown ( true )
104
+ fixture . scrollDown ( false )
105
+ expect ( fixture . getClassName ( ) ) . toEqual ( animationClass )
106
+ } )
107
+ } )
108
+
109
+ describe ( 'In animation' , ( ) => {
110
+ const animationClass = { in : 'flip' }
111
+ const offset = 100
112
+
113
+ test ( 'should add animation classes' , ( ) => {
114
+ const fixture = createFixture ( scrollAnimate , { animationClass } )
115
+
116
+ expect ( fixture . getClassName ( ) ) . toBeFalsy ( )
117
+ fixture . scrollDown ( true )
118
+ expect ( fixture . getClassName ( ) ) . toEqual ( animationClass . in )
119
+ } )
120
+
121
+ test ( 'should add animation classes by offset' , ( ) => {
122
+ const fixture = createFixture ( scrollAnimate , { animationClass, offset } )
123
+
124
+ expect ( fixture . getClassName ( ) ) . toBeFalsy ( )
125
+ fixture . scrollDown ( true )
126
+ expect ( fixture . getClassName ( ) ) . toEqual ( animationClass . in )
127
+ } )
128
+
129
+ test ( 'should toggle animation when repeat is on' , ( ) => {
130
+ const fixture = createFixture (
131
+ scrollAnimate , { animationClass, repeat : true }
132
+ )
133
+
134
+ expect ( fixture . getClassName ( ) ) . toBeFalsy ( )
135
+ fixture . scrollDown ( true )
136
+ expect ( fixture . getClassName ( ) ) . toEqual ( animationClass . in )
137
+ fixture . scrollDown ( false )
138
+ expect ( fixture . getClassName ( ) ) . toBeFalsy ( )
139
+ fixture . scrollUp ( true )
140
+ expect ( fixture . getClassName ( ) ) . toEqual ( animationClass . in )
141
+ } )
142
+
143
+ test ( 'should toggle animation when repeat is on by offset' , ( ) => {
144
+ const fixture = createFixture (
145
+ scrollAnimate , { animationClass, repeat : true , offset }
146
+ )
147
+
148
+ expect ( fixture . getClassName ( ) ) . toBeFalsy ( )
149
+ fixture . scrollDown ( true )
150
+ expect ( fixture . getClassName ( ) ) . toEqual ( animationClass . in )
151
+ fixture . scrollDown ( false )
152
+ expect ( fixture . getClassName ( ) ) . toBeFalsy ( )
153
+ fixture . scrollUp ( true )
154
+ expect ( fixture . getClassName ( ) ) . toEqual ( animationClass . in )
155
+ } )
156
+
157
+ test ( 'should not toggle animation when repeat is off' , ( ) => {
158
+ const fixture = createFixture (
159
+ scrollAnimate , { animationClass, repeat : false }
160
+ )
161
+
162
+ expect ( fixture . getClassName ( ) ) . toBeFalsy ( )
163
+ fixture . scrollDown ( true )
164
+ expect ( fixture . getClassName ( ) ) . toEqual ( animationClass . in )
165
+ fixture . scrollDown ( false )
166
+ expect ( fixture . getClassName ( ) ) . toEqual ( animationClass . in )
167
+ fixture . scrollUp ( true )
168
+ expect ( fixture . getClassName ( ) ) . toEqual ( animationClass . in )
169
+ fixture . scrollUp ( false )
170
+ fixture . scrollDown ( true )
171
+ fixture . scrollDown ( false )
172
+ expect ( fixture . getClassName ( ) ) . toEqual ( animationClass . in )
173
+ } )
174
+
175
+ test ( 'should not toggle animation when repeat is off by offset' , ( ) => {
176
+ const fixture = createFixture (
177
+ scrollAnimate , { animationClass, repeat : false , offset }
178
+ )
179
+
180
+ expect ( fixture . getClassName ( ) ) . toBeFalsy ( )
181
+ fixture . scrollDown ( true )
182
+ expect ( fixture . getClassName ( ) ) . toEqual ( animationClass . in )
183
+ fixture . scrollDown ( false )
184
+ expect ( fixture . getClassName ( ) ) . toEqual ( animationClass . in )
185
+ fixture . scrollUp ( true )
186
+ expect ( fixture . getClassName ( ) ) . toEqual ( animationClass . in )
187
+ fixture . scrollUp ( false )
188
+ fixture . scrollDown ( true )
189
+ fixture . scrollDown ( false )
190
+ expect ( fixture . getClassName ( ) ) . toEqual ( animationClass . in )
191
+ } )
192
+ } )
193
+
194
+ describe ( 'Out animation' , ( ) => {
195
+ const animationClass = { out : 'flipOut' }
196
+
197
+ test ( 'should print wrong parameter usage warning' , ( ) => {
198
+ jest . spyOn ( console , 'warn' ) . mockImplementation ( )
199
+ const fixture = createFixture ( scrollAnimate , { animationClass } )
200
+
201
+ expect ( fixture . getClassName ( ) ) . toBeFalsy ( )
202
+ fixture . scrollDown ( true )
203
+ expect ( console . warn ) . toHaveBeenCalledWith (
204
+ expect . stringContaining ( "animate-on-scroll" ) ,
205
+ expect . stringContaining ( "'out' parameter can't be used alone. 'in' required" ) ,
206
+ )
207
+ expect ( fixture . getClassName ( ) ) . toBeFalsy ( )
208
+ } )
209
+ } )
210
+
211
+ describe ( 'InOut animation' , ( ) => {
212
+ const animationClass = { in : 'flip' , out : 'flipOut' }
213
+ const offset = 100
214
+
215
+ test ( 'should add animation classes' , ( ) => {
216
+ const fixture = createFixture ( scrollAnimate , { animationClass } )
217
+
218
+ expect ( fixture . getClassName ( ) ) . toBeFalsy ( )
219
+ fixture . scrollDown ( true )
220
+ expect ( fixture . getClassName ( ) ) . toEqual ( animationClass . in )
221
+ } )
222
+
223
+ test ( 'should add animation classes by offset' , ( ) => {
224
+ const fixture = createFixture ( scrollAnimate , { animationClass, offset } )
225
+
226
+ expect ( fixture . getClassName ( ) ) . toBeFalsy ( )
227
+ fixture . scrollDown ( true )
228
+ expect ( fixture . getClassName ( ) ) . toEqual ( animationClass . in )
229
+ } )
230
+
231
+ test ( 'should toggle animation when repeat is on' , ( ) => {
232
+ const fixture = createFixture (
233
+ scrollAnimate , { animationClass, repeat : true }
234
+ )
235
+
236
+ expect ( fixture . getClassName ( ) ) . toBeFalsy ( )
237
+ fixture . scrollDown ( true )
238
+ expect ( fixture . getClassName ( ) ) . toEqual ( animationClass . in )
239
+ fixture . scrollDown ( false )
240
+ expect ( fixture . getClassName ( ) ) . toEqual ( animationClass . out )
241
+ fixture . scrollUp ( true )
242
+ expect ( fixture . getClassName ( ) ) . toEqual ( animationClass . in )
243
+ } )
244
+
245
+ test ( 'should toggle animation when repeat is on by offset' , ( ) => {
246
+ const fixture = createFixture (
247
+ scrollAnimate , { animationClass, repeat : true , offset }
248
+ )
249
+
250
+ expect ( fixture . getClassName ( ) ) . toBeFalsy ( )
251
+ fixture . scrollDown ( true )
252
+ expect ( fixture . getClassName ( ) ) . toEqual ( animationClass . in )
253
+ fixture . scrollDown ( false )
254
+ expect ( fixture . getClassName ( ) ) . toEqual ( animationClass . out )
255
+ fixture . scrollUp ( true )
256
+ expect ( fixture . getClassName ( ) ) . toEqual ( animationClass . in )
257
+ } )
258
+
259
+ test ( 'should not toggle animation when repeat is off' , ( ) => {
260
+ const fixture = createFixture (
261
+ scrollAnimate , { animationClass, repeat : false }
262
+ )
263
+
264
+ expect ( fixture . getClassName ( ) ) . toBeFalsy ( )
265
+ fixture . scrollDown ( true )
266
+ expect ( fixture . getClassName ( ) ) . toEqual ( animationClass . in )
267
+ fixture . scrollDown ( false )
268
+ expect ( fixture . getClassName ( ) ) . toEqual ( animationClass . in )
269
+ fixture . scrollUp ( true )
270
+ expect ( fixture . getClassName ( ) ) . toEqual ( animationClass . in )
271
+ fixture . scrollUp ( false )
272
+ fixture . scrollDown ( true )
273
+ fixture . scrollDown ( false )
274
+ expect ( fixture . getClassName ( ) ) . toEqual ( animationClass . in )
275
+ } )
276
+
277
+ test ( 'should not toggle animation when repeat is off by offset' , ( ) => {
278
+ const fixture = createFixture (
279
+ scrollAnimate , { animationClass, repeat : false , offset }
280
+ )
281
+
282
+ expect ( fixture . getClassName ( ) ) . toBeFalsy ( )
283
+ fixture . scrollDown ( true )
284
+ expect ( fixture . getClassName ( ) ) . toEqual ( animationClass . in )
285
+ fixture . scrollDown ( false )
286
+ expect ( fixture . getClassName ( ) ) . toEqual ( animationClass . in )
287
+ fixture . scrollUp ( true )
288
+ expect ( fixture . getClassName ( ) ) . toEqual ( animationClass . in )
289
+ fixture . scrollUp ( false )
290
+ fixture . scrollDown ( true )
291
+ fixture . scrollDown ( false )
292
+ expect ( fixture . getClassName ( ) ) . toEqual ( animationClass . in )
293
+ } )
67
294
} )
68
295
69
296
describe ( 'Downwards animation' , ( ) => {
0 commit comments