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');
230 describe('events', function() {
231 var $d = $(document);
233 beforeEach(function() {
236 spyOnEvent($d, 'deck.change');
239 describe('deck.change', function() {
240 it('should fire on go(i)', function() {
242 expect('deck.change').toHaveBeenTriggeredOn($d);
245 it('should fire on next()', function() {
247 expect('deck.change').toHaveBeenTriggeredOn($d);
250 it('should fire on prev()', function() {
252 expect('deck.change').toHaveBeenTriggeredOn($d);
255 it('should pass parameters with from and to indices', function() {
256 var f = function(e, from, to) {
257 expect(from).toEqual(1);
258 expect(to).toEqual(3);
261 $d.bind('deck.change', f);
263 $d.unbind('deck.change', f);
269 describe('complex html structure', function() {
270 beforeEach(function() {
271 loadFixtures('complex.html');
272 if (Modernizr.history) {
273 history.replaceState({}, "", "#")
290 describe('compound state classes', function() {
291 it('should apply current class', function() {
292 $('.slide3').each(function(i, el) {
293 expect($(el)).toHaveClass(defaults.classes.current);
297 it('should apply previous class', function() {
298 $('.slide2').each(function(i, el) {
299 expect($(el)).toHaveClass(defaults.classes.previous);
303 it('should apply next class', function() {
304 $('.slide4').each(function(i, el) {
305 expect($(el)).toHaveClass(defaults.classes.next);
309 it('should apply before class', function() {
310 $('.slide1').each(function(i, el) {
311 expect($(el)).toHaveClass(defaults.classes.before);
315 it('should apply after class', function() {
316 $('.slide5, .slide6, .slide7, .slide8, .slide9, .slide10').each(function(i, el) {
317 expect($(el)).toHaveClass(defaults.classes.after);
321 it('should apply child-current class', function() {
322 expect($('.slide2').not('.slide10')).toHaveClass(defaults.classes.childCurrent);
326 it('should remove old state classes', function() {
328 expect($('.slide3').not('.slide5')).not.toHaveClass(defaults.classes.current);
329 expect($('.slide2').not('.slide4')).not.toHaveClass(defaults.classes.previous);
330 expect($('.slide4').not('.slide6')).not.toHaveClass(defaults.classes.next);