-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathqueue.js
More file actions
81 lines (75 loc) · 2.62 KB
/
queue.js
File metadata and controls
81 lines (75 loc) · 2.62 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
const assert = require('assert');
const jsdom = require('mocha-jsdom');
const Keyframes = require('../dist/keyframes').default;
const { animationIncludesTest } = require('./play');
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);
});
};
describe('#queue()', () => {
describe('Queueing', () => {
jsdom({ url: "http://localhost" });
it('Should be able to queue animations', () => {
const kf = new Keyframes(document.createElement("div"));
kf.queue(['ball-roll 0.1s']);
assert(animationIncludesTest(kf.queueStore[0], ['ball-roll', '0.1s']));
});
it('Should add multiple animations to the queue', () => {
const kf = new Keyframes(document.createElement("div"));
kf.queue(['ball-roll 0.1s']);
kf.queue('ball-roll2 0.1s');
assert.equal(kf.queueStore.length, 2);
});
});
describe('Playing', () => {
before(preload);
it('Should play last animation onEnd', async () => {
const animation = await browser.evaluate(async () => {
return new Promise((resolve, reject) => {
kf.queue(['ball-roll 0.1s']);
kf.queue('ball-roll2 0.1s', {
onEnd: () => {
resolve(window.elem.style.animation);
}
});
});
});
assert(animationIncludesTest(animation, ['ball-roll2', '0.1s']));
});
});
});
describe('#loop()', () => {
before(preload);
it('Should be able to loop animations', async () => {
const animation = await browser.evaluate(async () => {
return new Promise((resolve, reject) => {
let count = 0;
kf.loop(['ball-roll 0.1s', 'ball-roll2 0.1s'], {
onEnd: () => {
if (count > 1) {
resolve(true);
} else {
count += 1;
}
}
});
});
});
assert(animation);
});
});