/
test.js
104 lines (89 loc) · 2.78 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
describe('Swiper', function () {
it('Swiper should have create', function () {
assert(Swiper !== undefined);
});
it('Swiper should be a Function', function(){
assert(typeof Swiper === 'function');
});
it('swiper should be instance of Swiper', function(){
assert(swiper instanceof Swiper);
});
});
describe('swiper should have the following methods:', function(){
var methods = [
'_init',
'_bind',
'_show',
'_activate',
'next',
'on'
];
var i = 0;
var len = methods.length;
for (i; i < len; i += 1) {
(function (i) {
it('.' + methods[i] + '()', function (done) {
assert(typeof swiper[methods[i]] === 'function');
done()
});
}(i));
}
});
describe('swiper should have the following properties', function(){
var properties = [
'version',
'_default',
'_options',
'_start',
'_move',
'_end',
'_prev',
'_current',
'_offset',
'_eventHandlers',
'$container',
'$items',
'count',
'_width',
'_height'
];
for (var i = 0, len = properties.length; i < len; i++){
(function(i){
it('.' + properties[i] + '', function(done){
assert(swiper[properties[i]] !== undefined);
done();
});
})(i);
}
});
describe('.next()', function (){
it('should translateY the container to the slide height & should add classes to dom', function (){
assert(swiper.$container.style['-webkit-transform'] === '');
for(var i = 1, len = swiper.$items.length; i < len; i++){
swiper.next();
var height = swiper.$items[i].style['height'].replace('px', '');
var expect = 'translate3d(0px, -'+ (height * i) +'px, 0px)';
assert(swiper._current === i);
assert(swiper.$container.style['-webkit-transform'] === expect);
}
});
});
describe('.go()', function (){
it('should translateY the container to the slide height & should add classes to dom', function (){
swiper.go(0);
for(var i = 1, len = swiper.$items.length; i < len; i++){
swiper.go(i);
var height = swiper.$items[i].style['height'].replace('px', '');
var expect = 'translate3d(0px, -'+ (height * i) +'px, 0px)';
assert(swiper._current === i);
assert(swiper.$container.style['-webkit-transform'] === expect);
}
});
});
describe('.on()', function (){
it('swiped listener should not be empty', function (){
swiper.on('swiped', function (){
});
assert(typeof swiper._eventHandlers['swiped'] === 'function');
})
});