-
Notifications
You must be signed in to change notification settings - Fork 2
/
glry.js
72 lines (63 loc) · 2.33 KB
/
glry.js
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
describe('glry', function () {
var elm, nav, glry, options;
function createElement(tag, props, child) {
var elm = document.createElement(tag);
for (var key in props) {
elm.setAttribute(key, props[key]);
}
if (child) elm.appendChild(child);
return elm;
}
function createEvent(eventName) {
var e = document.createEvent('MouseEvents');
e.initMouseEvent(eventName, true, true, window, 0, 0, 0, 0, 0, false, false, false, false, 0, null);
return e;
}
beforeAll(function () {
elm = createElement('figure', {'id': 'figure'});
elm.appendChild(createElement('div', {'class': 'loading'}));
elm.appendChild(createElement('div', {'class': 'error'}));
nav = createElement('nav', {'class': 'navigation'});
nav.appendChild(createElement('button', {'class': 'prev'}));
nav.appendChild(createElement('button', {'class': 'next'}));
elm.appendChild(nav);
document.body.appendChild(elm);
options = {
animationSpeed: 0,
load: function (directions) {
return 'base/test/test1.jpg';
}
};
});
afterAll(function () {
elm.parentNode.removeChild(elm);
elm = null;
});
it('should load image on init', function (done) {
spyOn(options, 'load').and.callThrough();
options.onLoadEnd = function () {
expect(options.load.calls.count()).toEqual(1);
expect(options.load).toHaveBeenCalledWith(undefined);
done();
};
glry = new Glry(options);
});
it('should show error', function (done) {
spyOn(options, 'load').and.returnValue('invalid.jpg');
options.onLoadEnd = function () {
expect(elm.querySelector('.error').classList.contains('hidden')).toBeFalsy();
done();
};
glry = new Glry(options);
});
it('should load next', function (done) {
spyOn(options, 'load').and.callThrough();
options.onLoadEnd = function () {
elm.querySelector('.next').dispatchEvent(createEvent('mouseup'));
expect(options.load.calls.count()).toEqual(2);
expect(options.load).toHaveBeenCalledWith('right');
done();
};
glry = new Glry(options);
});
});