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 to the slide with specified id', function() {
46 $.deck('go', 'custom-id');
47 expect($.deck('getSlide')).toHaveId('custom-id');
50 it('should go nowhere if i is out of bounds', function() {
52 expect($.deck('getSlide')).toHaveClass('slide1');
55 it('should go nowhere if id does not exist', function() {
56 $.deck('go', 'i-dont-exist');
57 expect($.deck('getSlide')).toHaveClass('slide1');
61 describe('next()', function() {
62 it('should go to the next slide', function() {
64 expect($.deck('getSlide')).toHaveClass('slide2');
67 it('should go nowhere if on the last slide', function() {
70 expect($.deck('getSlide')).toHaveClass('slide5');
74 describe('prev()', function() {
75 it('should go to the previous slide', function() {
78 expect($.deck('getSlide')).toHaveClass('slide2');
81 it('should go nowhere if on the first slide', function() {
83 expect($.deck('getSlide')).toHaveClass('slide1');
88 describe('getters', function() {
89 beforeEach(function() {
93 describe('getSlide()', function() {
94 it('should get the current slide', function() {
95 expect($.deck('getSlide')).toHaveClass('slide1');
97 expect($.deck('getSlide')).toHaveClass('slide3');
101 describe('getSlide(i)', function() {
102 it('should get slide number i (0 based index)', function() {
103 expect($.deck('getSlide', 1)).toHaveClass('slide2');
104 expect($.deck('getSlide', 3)).toHaveClass('slide4');
107 it('should return null if i is NaN', function() {
108 expect($.deck('getSlide', 'barfoo')).toBeNull();
111 it('should return null if i is out of bounds', function() {
112 expect($.deck('getSlide', 6)).toBeNull();
116 describe('getSlides()', function() {
117 it('should return an array of jQuery objects for each slide', function() {
118 var expectation = [],
119 slides = $.deck('getSlides');
120 $('.slide').each(function() {
121 expectation.push($(this));
123 expect(slides).toEqual(expectation);
127 describe('getContainer()', function() {
128 it('should return a jQuery object with the container element(s)', function() {
129 expect($.deck('getContainer')).toBe(defaults.selectors.container);
133 describe('getOptions()', function() {
134 it('should return the current options object', function() {
135 expect($.deck('getOptions')).toEqual(defaults);
140 describe('container states', function() {
141 beforeEach(function() {
145 it('should start at state 0', function() {
146 expect($(defaults.selectors.container)).toHaveClass(defaults.classes.onPrefix + '0');
149 it('should change states with the slide number', function() {
151 expect($(defaults.selectors.container)).toHaveClass(defaults.classes.onPrefix + '1');
153 expect($(defaults.selectors.container)).toHaveClass(defaults.classes.onPrefix + '3');
155 expect($(defaults.selectors.container)).toHaveClass(defaults.classes.onPrefix + '2');
159 describe('options object', function() {
160 var $d = $(document);
162 beforeEach(function() {
163 $.deck('.alt-slide', {
166 before: 'alt-before',
167 current: 'alt-current',
174 container: '.alt-container'
184 describe('classes', function() {
185 it('should use the specified after class', function() {
186 expect($('.alt-slide3, .alt-slide4, .alt-slide5')).toHaveClass('alt-after');
189 it('should use the specified before class', function() {
191 expect($('.alt-slide1, .alt-slide2, .alt-slide3')).toHaveClass('alt-before');
194 it('should use the specified container class', function() {
196 expect($('.alt-container')).toHaveClass('alt-on-2');
199 it('should use the specified current class', function() {
200 expect($.deck('getSlide')).toHaveClass('alt-current');
203 it('should use the specified next class', function() {
204 expect($('.alt-slide2')).toHaveClass('alt-next');
207 it('should use the specified previous class', function() {
209 expect($('.alt-slide1')).toHaveClass('alt-prev');
213 describe('key bindings', function() {
216 beforeEach(function() {
217 e = jQuery.Event('keydown.deck');
220 it('should go to the next slide using the specified key', function() {
223 expect($.deck('getSlide')).toHaveClass('alt-slide2');
226 it('should go to the previous slide using the specified key', function() {
230 expect($.deck('getSlide')).toHaveClass('alt-slide1');
233 it('should not trigger events that originate within editable elements', function() {
234 e = jQuery.Event('keydown');
236 $('.alt-slide1 input').trigger(e);
237 expect($.deck('getSlide')).toHaveClass('alt-slide1');
242 describe('events', function() {
243 var $d = $(document);
245 beforeEach(function() {
246 spyOnEvent($d, 'deck.init');
247 spyOnEvent($d, 'deck.beforeInit');
250 spyOnEvent($d, 'deck.change');
253 describe('deck.change', function() {
254 it('should fire on go(i)', function() {
256 expect('deck.change').toHaveBeenTriggeredOn($d);
259 it('should fire on next()', function() {
261 expect('deck.change').toHaveBeenTriggeredOn($d);
264 it('should fire on prev()', function() {
266 expect('deck.change').toHaveBeenTriggeredOn($d);
269 it('should pass parameters with from and to indices', function() {
270 var f = function(e, from, to) {
271 expect(from).toEqual(1);
272 expect(to).toEqual(3);
275 $d.bind('deck.change', f);
277 $d.unbind('deck.change', f);
280 it('should not change slides if default prevented', function() {
281 $d.bind('deck.change', false);
283 expect($.deck('getSlide')).toEqual($.deck('getSlide', 1));
284 $d.unbind('deck.change', false);
288 describe('deck.init', function() {
289 it('should fire on deck initialization', function() {
290 expect('deck.init').toHaveBeenTriggeredOn($d);
293 it('should have already populated the slides array', function() {
295 expect($.deck('getSlides').length).toBeGreaterThan(0);
298 $d.bind('deck.init', f);
300 $d.unbind('deck.init', f);
304 describe('deck.beforeInit', function() {
305 it('should fire on deck initialization', function() {
306 expect('deck.beforeInit').toHaveBeenTriggeredOn($d);
309 it('should have not populated the slides array', function() {
311 expect($.deck('getSlides').length).toEqual(0);
314 $d.bind('deck.beforeInit', f);
316 $d.unbind('deck.beforeInit', f);
322 describe('complex html structure', function() {
323 beforeEach(function() {
324 loadFixtures('complex.html');
325 if (Modernizr.history) {
326 history.replaceState({}, "", "#")
343 describe('compound state classes', function() {
344 it('should apply current class', function() {
345 $('.slide3').each(function(i, el) {
346 expect($(el)).toHaveClass(defaults.classes.current);
350 it('should apply previous class', function() {
351 $('.slide2').each(function(i, el) {
352 expect($(el)).toHaveClass(defaults.classes.previous);
356 it('should apply next class', function() {
357 $('.slide4').each(function(i, el) {
358 expect($(el)).toHaveClass(defaults.classes.next);
362 it('should apply before class', function() {
363 $('.slide1').each(function(i, el) {
364 expect($(el)).toHaveClass(defaults.classes.before);
368 it('should apply after class', function() {
369 $('.slide5, .slide6, .slide7, .slide8, .slide9, .slide10').each(function(i, el) {
370 expect($(el)).toHaveClass(defaults.classes.after);
374 it('should apply child-current class', function() {
375 expect($('.slide2').not('.slide10')).toHaveClass(defaults.classes.childCurrent);
379 it('should remove old state classes', function() {
381 expect($('.slide3').not('.slide5')).not.toHaveClass(defaults.classes.current);
382 expect($('.slide2').not('.slide4')).not.toHaveClass(defaults.classes.previous);
383 expect($('.slide4').not('.slide6')).not.toHaveClass(defaults.classes.next);
387 describe('iframes', function() {
388 beforeEach(function() {
389 loadFixtures('iframes.html');
390 if (Modernizr.history) {
391 history.replaceState({}, "", "#")
408 it('should remove/restore iframe sources when leaving/entering a slide', function() {
410 expect($.deck('getSlide').find('iframe').attr('src')).toEqual('fixtures/iframe_simple.html');
412 expect($('.slide5').find('iframe').attr('src')).toEqual('');
414 expect($('.slide5').find('iframe').attr('src')).toEqual('fixtures/iframe_simple.html');
417 it('should not store blank iframe sources', function() {
420 expect($.deck('getSlide').find('iframe').data('src')).toBeUndefined();
424 describe('empty deck', function() {
425 beforeEach(function() {
426 loadFixtures('empty.html');
430 describe('getSlide()', function() {
431 it('should not error on init', $.noop);