-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.test.js
90 lines (70 loc) · 2.2 KB
/
index.test.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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
var plugin = require('./index');
var PluginApi = require('gardr-core-plugin').PluginApi;
describe('plugin', function () {
var pluginApi, spy;
beforeEach(function () {
pluginApi = new PluginApi();
spy = sinon.spy(pluginApi, 'on');
});
it('should listen to item:afterrender event', function () {
plugin(pluginApi, {});
expect(spy).to.have.been.calledOnce;
expect(spy).to.have.been.calledWith('item:afterrender');
});
it('should put a no tiling background image on body', function () {
var imageUrl = 'http://www.test.com/fooimage';
var expectedStyle = 'url(' + imageUrl + ') 50% 0% no-repeat fixed';
plugin(pluginApi, {});
var options = {
rendered : {
wallpaperimage : imageUrl
}
};
pluginApi.trigger('item:afterrender', options);
expect(document.body.style.background).to.equal(expectedStyle);
});
it('should put a tiling background image on body', function () {
var imageUrl = 'http://www.test.com/fooimage';
var tiling = 'yes';
var expectedStyle = 'url(' + imageUrl + ') 50% 0% repeat fixed';
plugin(pluginApi, {});
var options = {
rendered : {
wallpaperimage : imageUrl,
wallpapertiling : tiling
}
};
pluginApi.trigger('item:afterrender', options);
expect(document.body.style.background).to.equal(expectedStyle);
});
it('should set background color on body', function() {
var color = 'rgb(255, 136, 51)';
plugin(pluginApi, {});
var options = {
rendered : {
wallpapercolor : color
}
};
pluginApi.trigger('item:afterrender', options);
expect(document.body.style.background).to.equal(color);
});
it('should open url when body is clicked and wallpaperclick url is defined', function (done) {
var imageUrl = 'http://www.test.com/fooimage';
var clickUrl = 'http://www.test.com/foo';
var windowSpy = sinon.spy(window, 'open');
plugin(pluginApi, {});
var options = {
rendered : {
wallpaperimage : imageUrl,
wallpaperclick : clickUrl
}
};
pluginApi.trigger('item:afterrender', options);
setTimeout(function () {
document.body.click();
expect(windowSpy).to.have.been.calledOnce;
expect(windowSpy).to.have.been.calledWith(clickUrl, '_blank');
done();
});
});
});