-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathplay.js
More file actions
97 lines (87 loc) · 2.98 KB
/
Copy pathplay.js
File metadata and controls
97 lines (87 loc) · 2.98 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
const assert = require('assert');
const jsdom = require('mocha-jsdom');
const Keyframes = require('../dist/keyframes').default;
global.requestAnimationFrame = cb => setTimeout(cb);
const preload = async () => {
await browser.evaluate(() => {
Keyframes.define([{
name: 'ball-roll',
from: {
transform: 'rotate(0deg)'
}
}, {
name: 'ball-roll2',
from: {
transform: 'rotate(5deg)'
}
}]);
window.elem = document.createElement('div');
document.body.appendChild(window.elem);
window.kf = new Keyframes(window.elem);
});
};
const animationIncludesTest = (haystack, needles) => {
for (let i = 0; i < needles.length; i += 1) {
if (haystack.includes(needles[i])) {
return true;
}
}
return false;
};
describe('Play', () => {
describe('#play()', () => {
before(preload);
it('Should be able to play an animation', async () => {
const animation = await browser.evaluate(async () => {
return new Promise((resolve, reject) => {
kf.play('ball-roll 0.1s', {
onEnd: () => {
resolve(window.elem.style.animation);
}
});
});
});
assert(animationIncludesTest(animation, ['ball-roll', '0.1s']));
});
it('Should execute callbacks', async () => {
const result = await browser.evaluate(async () => {
return new Promise((resolve, reject) => {
const events = [];
kf.play('ball-roll 0.05s linear 0s 5 normal forwards', {
onBeforeStart: () => {
events.push(1);
},
onStart: () => {
events.push(2);
},
onIteration: () => {
events.push(3);
},
onEnd: () => {
resolve(events);
}
});
});
});
assert.deepEqual(result, [1,2,3,3,3,3]);
});
it('Should execute cancel callback', async () => {
const count = await browser.evaluate(async () => {
return new Promise((resolve, reject) => {
kf.play('ball-roll 0.2s linear 0s infinite', {
onIteration: () => {
kf.play('ball-roll2 0.1s linear 0s infinite normal forwards');
},
onCancel: () => {
resolve(true);
}
});
});
});
assert(count);
});
});
});
module.exports = {
animationIncludesTest
}