2 describe('Deck JS', function() {
3 describe('standard html structure', function() {
4 beforeEach(function() {
5 loadFixtures('standard.html');
6 if (Modernizr
.history
) {
7 history
.replaceState({}, "", "#")
10 window
.location
.hash
= '#';
14 describe('init(selector)', function() {
15 it('should create slides', function() {
17 expect($.deck('getSlides').length
).toEqual($('.slide').length
);
21 describe('init([selectors])', function() {
22 it('should create slides', function() {
30 expect($.deck('getSlides').length
).toEqual($('.slide').length
);
34 describe('navigation functions', function() {
35 beforeEach(function() {
39 describe('go(i)', function() {
40 it('should go to the i slide (0 based index)', function() {
42 expect($.deck('getSlide')).toHaveClass('slide4');
45 it('should go nowhere if i is NaN', function() {
46 $.deck('go', 'foobar');
47 expect($.deck('getSlide')).toHaveClass('slide1');
50 it('should go nowhere if i is out of bounds', function() {
52 expect($.deck('getSlide')).toHaveClass('slide1');
56 describe('next()', function() {
57 it('should go to the next slide', function() {
59 expect($.deck('getSlide')).toHaveClass('slide2');
62 it('should go nowhere if on the last slide', function() {
65 expect($.deck('getSlide')).toHaveClass('slide5');
69 describe('prev()', function() {
70 it('should go to the previous slide', function() {
73 expect($.deck('getSlide')).toHaveClass('slide2');
76 it('should go nowhere if on the first slide', function() {
78 expect($.deck('getSlide')).toHaveClass('slide1');
83 describe('getters', function() {
84 beforeEach(function() {
88 describe('getSlide()', function() {
89 it('should get the current slide', function() {
90 expect($.deck('getSlide')).toHaveClass('slide1');
92 expect($.deck('getSlide')).toHaveClass('slide3');
96 describe('getSlide(i)', function() {
97 it('should get slide number i (0 based index)', function() {
98 expect($.deck('getSlide', 1)).toHaveClass('slide2');
99 expect($.deck('getSlide', 3)).toHaveClass('slide4');
102 it('should return null if i is NaN', function() {
103 expect($.deck('getSlide', 'barfoo')).toBeNull();
106 it('should return null if i is out of bounds', function() {
107 expect($.deck('getSlide', 6)).toBeNull();
111 describe('getSlides()', function() {
112 it('should return an array of jQuery objects for each slide', function() {
113 var expectation
= [],
114 slides
= $.deck('getSlides');
115 $('.slide').each(function() {
116 expectation
.push($(this));
118 expect(slides
).toEqual(expectation
);
122 describe('getContainer()', function() {
123 it('should return a jQuery object with the container element(s)', function() {
124 expect($.deck('getContainer')).toBe(defaults
.selectors
.container
);
128 describe('getOptions()', function() {
129 it('should return the current options object', function() {
130 expect($.deck('getOptions')).toEqual(defaults
);
135 describe('container states', function() {
136 beforeEach(function() {
140 it('should start at state 0', function() {
141 expect($(defaults
.selectors
.container
)).toHaveClass(defaults
.classes
.onPrefix
+ '0');
144 it('should change states with the slide number', function() {
146 expect($(defaults
.selectors
.container
)).toHaveClass(defaults
.classes
.onPrefix
+ '1');
148 expect($(defaults
.selectors
.container
)).toHaveClass(defaults
.classes
.onPrefix
+ '3');
150 expect($(defaults
.selectors
.container
)).toHaveClass(defaults
.classes
.onPrefix
+ '2');
154 describe('options object', function() {
155 var $d
= $(document
);
157 beforeEach(function() {
158 $.deck('.alt-slide', {
161 before
: 'alt-before',
162 current
: 'alt-current',
169 container
: '.alt-container'
179 describe('classes', function() {
180 it('should use the specified after class', function() {
181 expect($('.alt-slide3, .alt-slide4, .alt-slide5')).toHaveClass('alt-after');
184 it('should use the specified before class', function() {
186 expect($('.alt-slide1, .alt-slide2, .alt-slide3')).toHaveClass('alt-before');
189 it('should use the specified container class', function() {
191 expect($('.alt-container')).toHaveClass('alt-on-2');
194 it('should use the specified current class', function() {
195 expect($.deck('getSlide')).toHaveClass('alt-current');
198 it('should use the specified next class', function() {
199 expect($('.alt-slide2')).toHaveClass('alt-next');
202 it('should use the specified previous class', function() {
204 expect($('.alt-slide1')).toHaveClass('alt-prev');
208 describe('key bindings', function() {
211 beforeEach(function() {
212 e
= jQuery
.Event('keydown.deck');
215 it('should go to the next slide using the specified key', function() {
218 expect($.deck('getSlide')).toHaveClass('alt-slide2');
221 it('should go to the previous slide using the specified key', function() {
225 expect($.deck('getSlide')).toHaveClass('alt-slide1');
228 it('should not trigger events that originate within editable elements', function() {
229 e
= jQuery
.Event('keydown');
231 $('.alt-slide1 input').trigger(e
);
232 expect($.deck('getSlide')).toHaveClass('alt-slide1');
237 describe('events', function() {
238 var $d
= $(document
);
240 beforeEach(function() {
243 spyOnEvent($d
, 'deck.change');
246 describe('deck.change', function() {
247 it('should fire on go(i)', function() {
249 expect('deck.change').toHaveBeenTriggeredOn($d
);
252 it('should fire on next()', function() {
254 expect('deck.change').toHaveBeenTriggeredOn($d
);
257 it('should fire on prev()', function() {
259 expect('deck.change').toHaveBeenTriggeredOn($d
);
262 it('should pass parameters with from and to indices', function() {
263 var f = function(e
, from, to
) {
264 expect(from).toEqual(1);
265 expect(to
).toEqual(3);
268 $d
.bind('deck.change', f
);
270 $d
.unbind('deck.change', f
);
276 describe('complex html structure', function() {
277 beforeEach(function() {
278 loadFixtures('complex.html');
279 if (Modernizr
.history
) {
280 history
.replaceState({}, "", "#")
297 describe('compound state classes', function() {
298 it('should apply current class', function() {
299 $('.slide3').each(function(i
, el
) {
300 expect($(el
)).toHaveClass(defaults
.classes
.current
);
304 it('should apply previous class', function() {
305 $('.slide2').each(function(i
, el
) {
306 expect($(el
)).toHaveClass(defaults
.classes
.previous
);
310 it('should apply next class', function() {
311 $('.slide4').each(function(i
, el
) {
312 expect($(el
)).toHaveClass(defaults
.classes
.next
);
316 it('should apply before class', function() {
317 $('.slide1').each(function(i
, el
) {
318 expect($(el
)).toHaveClass(defaults
.classes
.before
);
322 it('should apply after class', function() {
323 $('.slide5, .slide6, .slide7, .slide8, .slide9, .slide10').each(function(i
, el
) {
324 expect($(el
)).toHaveClass(defaults
.classes
.after
);
328 it('should apply child-current class', function() {
329 expect($('.slide2').not('.slide10')).toHaveClass(defaults
.classes
.childCurrent
);
333 it('should remove old state classes', function() {
335 expect($('.slide3').not('.slide5')).not
.toHaveClass(defaults
.classes
.current
);
336 expect($('.slide2').not('.slide4')).not
.toHaveClass(defaults
.classes
.previous
);
337 expect($('.slide4').not('.slide6')).not
.toHaveClass(defaults
.classes
.next
);