forked from peduarte/wallop
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.js
106 lines (76 loc) · 3.06 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
'use restrict';
var Wallop = require('./js/Wallop');
var test = require('tape');
function createSlider(className, itemsTotal) {
var $wallop = document.createElement('div');
$wallop.classList.add(className);
document.body.appendChild($wallop);
var $wallopList = document.createElement('div');
$wallopList.classList.add('Wallop-list');
$wallop.appendChild($wallopList);
for (var i = 0; i < itemsTotal; i++) {
var $item = document.createElement('div');
$item.classList.add('Wallop-item');
$wallopList.appendChild($item);
}
var $wallopButtonPrevious = document.createElement('button');
$wallopButtonPrevious.classList.add('Wallop-buttonPrevious');
$wallop.appendChild($wallopButtonPrevious);
var $wallopButtonNext = document.createElement('button');
$wallopButtonNext.classList.add('Wallop-buttonNext');
$wallop.appendChild($wallopButtonNext);
}
test('First item is currentItem if not specified in HTML', function(assert) {
createSlider('Wallop1', 2);
var slider = document.querySelector('.Wallop1');
var wallop = new Wallop(slider);
assert.equal(wallop.currentItemIndex, 0, 'correct');
assert.end();
});
test('Button state on initialization when carousel option is disabled', function(assert) {
createSlider('Wallop2', 3);
var slider = document.querySelector('.Wallop2');
var wallop = new Wallop(slider, { carousel: false });
var previousButtonDisabled = slider.querySelector('.Wallop-buttonPrevious').disabled;
assert.equal(previousButtonDisabled, true, 'correct button state');
assert.end();
});
test('Clicking Next updates currentItemIndex', function(assert) {
createSlider('Wallop3', 3);
var slider = document.querySelector('.Wallop3');
var wallop = new Wallop(slider);
var index = wallop.currentItemIndex;
wallop.next();
index = wallop.currentItemIndex;
assert.equal(index, 1, 'updated index');
assert.end();
});
test('Go to specific item index', function(assert) {
createSlider('Wallop4', 3);
var slider = document.querySelector('.Wallop4');
var wallop = new Wallop(slider);
var index = wallop.currentItemIndex;
wallop.goTo(1);
index = wallop.currentItemIndex;
assert.equal(index, 1, 'goTo works');
assert.end();
});
test('Carousel is working', function(assert) {
createSlider('Wallop5', 3);
var slider = document.querySelector('.Wallop5');
var wallop = new Wallop(slider);
wallop.goTo(wallop.lastItemIndex);
index = wallop.currentItemIndex;
assert.equal(index, 2, 'went to last item index');
wallop.next();
index = wallop.currentItemIndex;
assert.equal(index, 0, 'went to first item index from the last');
var nextItem = wallop.allItemsArray[wallop.currentItemIndex];
assert.equal(nextItem.classList.contains('Wallop-item--showNext'), true, 'carousel works forwards');
wallop.previous();
index = wallop.currentItemIndex;
assert.equal(index, 2, 'went back to last item from first');
var previousItem = wallop.allItemsArray[wallop.currentItemIndex];
assert.equal(previousItem.classList.contains('Wallop-item--showPrevious'), true, 'carousel works backwards');
assert.end();
});