forked from Mango/slideout
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.js
195 lines (171 loc) · 5.15 KB
/
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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
if (exports) {
var fs = require('fs');
var jsdom = require('jsdom');
var html = fs.readFileSync('./test/index.html', 'utf-8');
window = jsdom.jsdom(html).parentWindow;
var Slideout = require('../');
var assert = require('better-assert');
}
var doc = window.document;
var beforeopenEvent = false;
var openEvent = false;
var beforecloseEvent = false;
var closeEvent = false;
var slideout = new Slideout({
'panel': doc.getElementById('panel'),
'menu': doc.getElementById('menu')
});
slideout
.on('beforeopen', function() {
beforeopenEvent = true;
})
.on('open', function() {
openEvent = true;
})
.on('beforeclose', function() {
beforecloseEvent = true;
})
.on('close', function() {
closeEvent = true;
});
describe('Slideout', function () {
it('should be defined.', function () {
assert(Slideout !== undefined);
});
it('should be a function.', function () {
assert(typeof Slideout === 'function');
});
it('should return a new instance.', function () {
assert(slideout instanceof Slideout);
});
describe('should have the following methods:', function () {
var methods = [
'open',
'close',
'toggle',
'isOpen',
'_initTouchEvents',
'_translateXTo',
'_setTransition',
'on',
'once',
'off',
'emit'
];
var i = 0;
var len = methods.length;
for (i; i < len; i += 1) {
(function (i) {
it('.' + methods[i] + '()', function (done) {
assert(typeof slideout[methods[i]] === 'function');
done()
});
}(i));
}
});
describe('should define the following properties:', function () {
var properties = [
'panel',
'menu',
'_startOffsetX',
'_currentOffsetX',
'_opening',
'_moved',
'_opened',
'_fx',
'_duration',
'_tolerance',
'_padding',
'_touch'
];
var i = 0;
var len = properties.length;
for (i; i < len; i += 1) {
(function (i) {
it('.' + properties[i] + '()', function (done) {
assert(slideout[properties[i]] !== undefined);
done()
});
}(i));
}
});
it('should add classnames to panel and menu DOM elements.', function () {
assert(slideout.panel.className.search('slideout-panel') !== -1);
assert(slideout.menu.className.search('slideout-menu') !== -1);
});
describe('.open()', function () {
it('should add "slideout-open" classname to HTML.', function () {
assert(doc.documentElement.className.search('slideout-open') === -1);
slideout.open();
assert(doc.documentElement.className.search('slideout-open') !== -1);
});
it('should translateX the panel to the given padding.', function () {
var translate3d = exports ? 'translate3d(256px, 0, 0)' : 'translate3d(256px, 0px, 0px)';
assert(slideout.panel.style.transform === translate3d);
assert(slideout.panel.style.transition.search(/transform 300ms ease/) !== -1);
});
it('should set _opened to true.', function () {
assert(slideout._opened === true);
});
it('should emit "beforeopen" event.', function () {
assert(beforeopenEvent === true);
});
it('should emit "open" event.', function (done) {
setTimeout(function(){
assert(openEvent === true);
done();
}, 400);
});
});
describe('.isOpen()', function () {
it('should return true if the slideout is opened.', function () {
assert(slideout.isOpen());
});
});
describe('.close()', function () {
it('should remove "slideout-open" classname to HTML.', function (done) {
assert(doc.documentElement.className.search('slideout-open') !== -1);
slideout.close();
setTimeout(function(){
assert(doc.documentElement.className.search('slideout-open') === -1);
done();
}, 350);
});
it('should translateX the panel to 0.', function () {
assert(slideout.panel.style.transform === '');
assert(slideout.panel.style.transition === '');
});
it('should set _opened to false.', function () {
assert(slideout._opened === false);
});
it('should emit "beforeclose" event.', function () {
assert(beforecloseEvent === true);
});
it('should emit "close" event.', function () {
assert(closeEvent === true);
});
});
describe('.toggle()', function () {
it('should show the slideout if it is not opened.', function (done) {
assert(doc.documentElement.className.search('slideout-open') === -1);
slideout.toggle();
assert(doc.documentElement.className.search('slideout-open') !== -1);
slideout.toggle();
setTimeout(function(){
assert(doc.documentElement.className.search('slideout-open') === -1);
done();
}, 350);
});
});
describe('.destroy()', function() {
it('should destroy the instance internals allowing a new one to be created in it\'s place.', function(){
slideout.destroy();
slideout = new Slideout({
'panel': doc.getElementById('panel'),
'menu': doc.getElementById('menu')
});
slideout.open();
setTimeout(function(){ slideout.close(); }, 750);
});
});
});