1 describe('Deck JS Quick Go-To', function() {
4 beforeEach(function() {
5 loadFixtures('standard.html');
6 if (Modernizr.history) {
7 history.replaceState({}, "", "#")
10 window.location.hash = '#';
15 describe('showGoTo()', function() {
16 it('should show the go-to helper', function() {
17 expect($(defaults.selectors.container)).not.toHaveClass(defaults.classes.goto);
19 expect($(defaults.selectors.container)).toHaveClass(defaults.classes.goto);
22 it('should focus the go-to input', function() {
24 expect($(defaults.selectors.gotoInput)[0]).toEqual(document.activeElement);
27 it('should set aria-hidden to false', function() {
28 var $gotoForm = $(defaults.selectors.gotoForm);
30 expect($gotoForm).toHaveAttr('aria-hidden', 'false');
34 describe('hideGoTo()', function() {
35 beforeEach(function() {
40 it('should hide the go-to helper', function() {
41 expect($(defaults.selectors.container)).not.toHaveClass(defaults.classes.goto);
44 it('should blur the go-to input', function() {
45 expect($(defaults.selectors.gotoInput)[0]).not.toEqual(document.activeElement);
48 it('should set aria-hidden to true', function() {
49 var $gotoForm = $(defaults.selectors.gotoForm);
51 expect($gotoForm).toHaveAttr('aria-hidden', 'true');
55 describe('toggleGoTo()', function() {
56 it('should toggle the go-to helper on and off', function() {
57 expect($(defaults.selectors.container)).not.toHaveClass(defaults.classes.goto);
59 expect($(defaults.selectors.container)).toHaveClass(defaults.classes.goto);
61 expect($(defaults.selectors.container)).not.toHaveClass(defaults.classes.goto);
65 describe('Go-To submit', function() {
66 beforeEach(function() {
70 it('should hide the go-to helper', function() {
71 $(defaults.selectors.gotoInput).val('3');
72 $(defaults.selectors.gotoForm).submit();
73 expect($(defaults.selectors.container)).not.toHaveClass(defaults.classes.goto);
76 it('should go to the slide number entered', function() {
77 $(defaults.selectors.gotoInput).val('3');
78 $(defaults.selectors.gotoForm).submit();
79 expect($.deck('getSlide')).toEqual($.deck('getSlide'), 2);
82 it('should go to the slide id entered', function() {
83 $(defaults.selectors.gotoInput).val('custom-id');
84 $(defaults.selectors.gotoForm).submit();
85 expect($.deck('getSlide')).toEqual($.deck('getSlide'), 1);
88 it('should go nowhere if the number is negative', function() {
89 $(defaults.selectors.gotoInput).val('-2');
90 $(defaults.selectors.gotoForm).submit();
91 expect($.deck('getSlide')).toEqual($.deck('getSlide'), 0);
94 it('should go nowhere if the number is greater than the number of slides', function() {
95 $(defaults.selectors.gotoInput).val('9');
96 $(defaults.selectors.gotoForm).submit();
97 expect($.deck('getSlide')).toEqual($.deck('getSlide'), 0);
100 it('should go nowhere if the id does not exist', function() {
101 $(defaults.selectors.gotoInput).val('do-not-exist');
102 $(defaults.selectors.gotoForm).submit();
103 expect($.deck('getSlide')).toEqual($.deck('getSlide'), 0);
107 describe('Datalist population', function() {
108 it('should fill in options with all the slide ids', function() {
109 var $dataOptions = $(defaults.selectors.gotoDatalist).find('option');
110 expect($dataOptions.length).toEqual(5);
111 expect($dataOptions.eq(0).attr('value')).toEqual('slide-0');
112 expect($dataOptions.eq(1).attr('value')).toEqual('custom-id');
116 describe('key bindings', function() {
119 beforeEach(function() {
120 e = jQuery.Event('keydown.deckgoto');
123 it('should toggle the go-to helper if the specified key is pressed', function() {
126 expect($(defaults.selectors.container)).toHaveClass(defaults.classes.goto);
128 expect($(defaults.selectors.container)).not.toHaveClass(defaults.classes.goto);
132 describe('countNested false', function() {
133 beforeEach(function() {
134 loadFixtures('nesteds.html');
141 it('should ignore nested slides when given a slide number', function() {
142 $(defaults.selectors.gotoInput).val('4');
143 $(defaults.selectors.gotoForm).submit();
144 expect($.deck('getSlide')).toHaveId('after');
147 it('should respect top side of new slide range', function() {
149 $(defaults.selectors.gotoInput).val('6');
150 $(defaults.selectors.gotoForm).submit();
151 expect($.deck('getSlide')).toHaveId('slide-0');