-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Expand file tree
/
Copy pathtest.js
More file actions
134 lines (117 loc) · 3.96 KB
/
Copy pathtest.js
File metadata and controls
134 lines (117 loc) · 3.96 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
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
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 slideout = new Slideout({
'panel': doc.getElementById('panel'),
'menu': doc.getElementById('menu')
});
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'];
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',
'_fromedge'
];
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);
});
});
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 () {
var translate3d = exports ? 'translate3d(0px, 0, 0)' : 'translate3d(0px, 0px, 0px)';
assert(slideout.panel.style.transform === translate3d);
assert(slideout.panel.style.transition === '');
});
it('should set _opened to false.', function () {
assert(slideout._opened === false);
});
});
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);
});
});
});