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
|
describe('Deck JS Quick Go-To', function() {
var $d = $(document);
beforeEach(function() {
loadFixtures('standard.html');
if (Modernizr.history) {
history.replaceState({}, "", "#")
}
else {
window.location.hash = '#';
}
$.deck('.slide');
});
describe('showGoTo()', function() {
it('should show the go-to helper', function() {
expect($(defaults.selectors.container)).not.toHaveClass(defaults.classes.goto);
$.deck('showGoTo');
expect($(defaults.selectors.container)).toHaveClass(defaults.classes.goto);
});
it('should focus the go-to input', function() {
$.deck('showGoTo');
expect($(defaults.selectors.gotoInput)[0]).toEqual(document.activeElement);
});
it('should set aria-hidden to false', function() {
var $gotoForm = $(defaults.selectors.gotoForm);
$.deck('showGoTo');
expect($gotoForm).toHaveAttr('aria-hidden', 'false');
});
});
describe('hideGoTo()', function() {
beforeEach(function() {
$.deck('showGoTo');
$.deck('hideGoTo');
});
it('should hide the go-to helper', function() {
expect($(defaults.selectors.container)).not.toHaveClass(defaults.classes.goto);
});
it('should blur the go-to input', function() {
expect($(defaults.selectors.gotoInput)[0]).not.toEqual(document.activeElement);
});
it('should set aria-hidden to true', function() {
var $gotoForm = $(defaults.selectors.gotoForm);
$.deck('hideGoTo');
expect($gotoForm).toHaveAttr('aria-hidden', 'true');
});
});
describe('toggleGoTo()', function() {
it('should toggle the go-to helper on and off', function() {
expect($(defaults.selectors.container)).not.toHaveClass(defaults.classes.goto);
$.deck('toggleGoTo');
expect($(defaults.selectors.container)).toHaveClass(defaults.classes.goto);
$.deck('toggleGoTo');
expect($(defaults.selectors.container)).not.toHaveClass(defaults.classes.goto);
});
});
describe('Go-To submit', function() {
beforeEach(function() {
$.deck('showGoTo');
});
it('should hide the go-to helper', function() {
$(defaults.selectors.gotoInput).val('3');
$(defaults.selectors.gotoForm).submit();
expect($(defaults.selectors.container)).not.toHaveClass(defaults.classes.goto);
});
it('should go to the slide number entered', function() {
$(defaults.selectors.gotoInput).val('3');
$(defaults.selectors.gotoForm).submit();
expect($.deck('getSlide')).toEqual($.deck('getSlide'), 2);
});
it('should go to the slide id entered', function() {
$(defaults.selectors.gotoInput).val('custom-id');
$(defaults.selectors.gotoForm).submit();
expect($.deck('getSlide')).toEqual($.deck('getSlide'), 1);
});
it('should go nowhere if the number is negative', function() {
$(defaults.selectors.gotoInput).val('-2');
$(defaults.selectors.gotoForm).submit();
expect($.deck('getSlide')).toEqual($.deck('getSlide'), 0);
});
it('should go nowhere if the number is greater than the number of slides', function() {
$(defaults.selectors.gotoInput).val('9');
$(defaults.selectors.gotoForm).submit();
expect($.deck('getSlide')).toEqual($.deck('getSlide'), 0);
});
it('should go nowhere if the id does not exist', function() {
$(defaults.selectors.gotoInput).val('do-not-exist');
$(defaults.selectors.gotoForm).submit();
expect($.deck('getSlide')).toEqual($.deck('getSlide'), 0);
});
});
describe('Datalist population', function() {
it('should fill in options with all the slide ids', function() {
var $dataOptions = $(defaults.selectors.gotoDatalist).find('option');
expect($dataOptions.length).toEqual(5);
expect($dataOptions.eq(0).attr('value')).toEqual('slide-0');
expect($dataOptions.eq(1).attr('value')).toEqual('custom-id');
});
});
describe('key bindings', function() {
var e;
beforeEach(function() {
e = jQuery.Event('keydown.deckgoto');
});
it('should toggle the go-to helper if the specified key is pressed', function() {
e.which = 71; // g
$d.trigger(e);
expect($(defaults.selectors.container)).toHaveClass(defaults.classes.goto);
$d.trigger(e);
expect($(defaults.selectors.container)).not.toHaveClass(defaults.classes.goto);
});
});
describe('countNested false', function() {
beforeEach(function() {
loadFixtures('nesteds.html');
$.deck('.slide', {
countNested: false
});
$.deck('showGoTo');
});
it('should ignore nested slides when given a slide number', function() {
$(defaults.selectors.gotoInput).val('4');
$(defaults.selectors.gotoForm).submit();
expect($.deck('getSlide')).toHaveId('after');
});
it('should respect top side of new slide range', function() {
$.deck('go', 0);
$(defaults.selectors.gotoInput).val('6');
$(defaults.selectors.gotoForm).submit();
expect($.deck('getSlide')).toHaveId('slide-0');
});
});
});
|