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);
28 describe('hideGoTo()', function() {
29 beforeEach(function() {
34 it('should hide the go-to helper', function() {
35 expect($(defaults.selectors.container)).not.toHaveClass(defaults.classes.goto);
38 it('should blur the go-to input', function() {
39 expect($(defaults.selectors.gotoInput)[0]).not.toEqual(document.activeElement);
43 describe('toggleGoTo()', function() {
44 it('should toggle the go-to helper on and off', function() {
45 expect($(defaults.selectors.container)).not.toHaveClass(defaults.classes.goto);
47 expect($(defaults.selectors.container)).toHaveClass(defaults.classes.goto);
49 expect($(defaults.selectors.container)).not.toHaveClass(defaults.classes.goto);
53 describe('Go-To submit', function() {
54 beforeEach(function() {
58 it('should hide the go-to helper', function() {
59 $(defaults.selectors.gotoInput).val('3');
60 $(defaults.selectors.gotoForm).submit();
61 expect($(defaults.selectors.container)).not.toHaveClass(defaults.classes.goto);
64 it('should go to the slide number entered', function() {
65 $(defaults.selectors.gotoInput).val('3');
66 $(defaults.selectors.gotoForm).submit();
67 expect($.deck('getSlide')).toEqual($.deck('getSlide'), 2);
70 it('should go to the slide id entered', function() {
71 $(defaults.selectors.gotoInput).val('custom-id');
72 $(defaults.selectors.gotoForm).submit();
73 expect($.deck('getSlide')).toEqual($.deck('getSlide'), 1);
76 it('should go nowhere if the number is negative', function() {
77 $(defaults.selectors.gotoInput).val('-2');
78 $(defaults.selectors.gotoForm).submit();
79 expect($.deck('getSlide')).toEqual($.deck('getSlide'), 0);
82 it('should go nowhere if the number is greater than the number of slides', function() {
83 $(defaults.selectors.gotoInput).val('9');
84 $(defaults.selectors.gotoForm).submit();
85 expect($.deck('getSlide')).toEqual($.deck('getSlide'), 0);
88 it('should go nowhere if the id does not exist', function() {
89 $(defaults.selectors.gotoInput).val('do-not-exist');
90 $(defaults.selectors.gotoForm).submit();
91 expect($.deck('getSlide')).toEqual($.deck('getSlide'), 0);
95 describe('Datalist population', function() {
96 it('should fill in options with all the slide ids', function() {
97 var $dataOptions = $(defaults.selectors.gotoDatalist).find('option');
98 expect($dataOptions.length).toEqual(5);
99 expect($dataOptions.eq(0).attr('value')).toEqual('slide-0');
100 expect($dataOptions.eq(1).attr('value')).toEqual('custom-id');
104 describe('key bindings', function() {
107 beforeEach(function() {
108 e = jQuery.Event('keydown.deckgoto');
111 it('should toggle the go-to helper if the specified key is pressed', function() {
114 expect($(defaults.selectors.container)).toHaveClass(defaults.classes.goto);
116 expect($(defaults.selectors.container)).not.toHaveClass(defaults.classes.goto);
120 describe('countNested false', function() {
121 beforeEach(function() {
122 loadFixtures('nesteds.html');
129 it('should ignore nested slides when given a slide number', function() {
130 $(defaults.selectors.gotoInput).val('4');
131 $(defaults.selectors.gotoForm).submit();
132 expect($.deck('getSlide')).toHaveId('after');
135 it('should respect top side of new slide range', function() {
137 $(defaults.selectors.gotoInput).val('6');
138 $(defaults.selectors.gotoForm).submit();
139 expect($.deck('getSlide')).toHaveId('slide-0');