Skip to content

Commit 3b6c972

Browse files
committed
update tests.js, disable prevButton on non-loop
1 parent 40d2e35 commit 3b6c972

File tree

7 files changed

+112
-24
lines changed

7 files changed

+112
-24
lines changed

dist/min/tiny-slider.js

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/min/tiny-slider.native.js

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/tiny-slider.js

+16-13
Original file line numberDiff line numberDiff line change
@@ -407,7 +407,7 @@ var gn = (function (g) {
407407
return g;
408408
})(window.gn || {});
409409
// extend
410-
// @require "/src/gn/gn.js"
410+
// @require "/src/gn/base.js"
411411

412412
gn.extend = function () {
413413
var obj, name, copy,
@@ -431,19 +431,19 @@ gn.extend = function () {
431431
return target;
432432
};
433433
// isInViewport
434-
// @require "/src/gn/gn.js"
434+
// @require "/src/gn/base.js"
435435

436436
gn.isInViewport = function ( elem ) {
437437
var rect = elem.getBoundingClientRect();
438438
return (
439-
rect.bottom >= 0 &&
440-
rect.right >= 0 &&
441-
rect.top <= (window.innerHeight || document.documentElement.clientHeight) &&
442-
rect.left <= (window.innerWidth || document.documentElement.clientWidth)
439+
rect.bottom > 0 &&
440+
rect.right > 0 &&
441+
rect.top < document.documentElement.clientHeight &&
442+
rect.left < document.documentElement.clientWidth
443443
);
444444
};
445445
// indexOf
446-
// @require "/src/gn/gn.js"
446+
// @require "/src/gn/base.js"
447447

448448
gn.indexOf = function (array, item) {
449449
for (var i = 0; i < array.length; i++) {
@@ -452,7 +452,7 @@ gn.indexOf = function (array, item) {
452452
return -1;
453453
};
454454
// get supported property
455-
// @require "/src/gn/gn.js"
455+
// @require "/src/gn/base.js"
456456

457457
gn.getSupportedProp = function (proparray){
458458
var root = document.documentElement;
@@ -466,7 +466,7 @@ gn.getSupportedProp = function (proparray){
466466
// var getTD = gn.getSupportedProp(['transitionDuration', 'WebkitTransitionDuration', 'MozTransitionDuration', 'OTransitionDuration']),
467467
// getTransform = gn.getSupportedProp(['transform', 'WebkitTransform', 'MozTransform', 'OTransform']);
468468
// DOM ready
469-
// @require "/src/gn/gn.js"
469+
// @require "/src/gn/base.js"
470470

471471
gn.ready = function ( fn ) {
472472

@@ -482,15 +482,15 @@ gn.ready = function ( fn ) {
482482
document.addEventListener( 'DOMContentLoaded', fn, false );
483483
};
484484
// isNodeList
485-
// @require "/src/gn/gn.js"
485+
// @require "/src/gn/base.js"
486486

487487
gn.isNodeList = function (el) {
488488
// Only NodeList has the "item()" function
489489
return typeof el.item !== 'undefined';
490490
};
491491

492492
// append
493-
// @require "/src/gn/gn.js"
493+
// @require "/src/gn/base.js"
494494
// @require "/src/gn/isNodeList.js"
495495

496496
gn.append = function(els, data) {
@@ -517,7 +517,7 @@ gn.append = function(els, data) {
517517

518518

519519
// wrap
520-
// @require "/src/gn/gn.js"
520+
// @require "/src/gn/base.js"
521521
// @require "/src/gn/isNodeList.js"
522522

523523
gn.wrap = function (els, obj) {
@@ -548,7 +548,7 @@ gn.wrap = function (els, obj) {
548548

549549

550550
// unwrap
551-
// @require "/src/gn/gn.js"
551+
// @require "/src/gn/base.js"
552552
// @require "/src/gn/isNodeList.js"
553553

554554
gn.unwrap = function (els) {
@@ -891,6 +891,9 @@ var tinySlider = (function () {
891891
}
892892
if (controls) {
893893
_setAttrs(nextButton, {'tabindex': '0'});
894+
if (index === 0 && !loop || rewind) {
895+
prevButton.disabled = true;
896+
}
894897
}
895898
if (nav) {
896899
_setAttrs(allNavs[0], {'tabindex': '0', 'aria-selected': 'true'});

dist/tiny-slider.native.js

+3
Original file line numberDiff line numberDiff line change
@@ -321,6 +321,9 @@ var tinySlider = (function () {
321321
}
322322
if (controls) {
323323
_setAttrs(nextButton, {'tabindex': '0'});
324+
if (index === 0 && !loop || rewind) {
325+
prevButton.disabled = true;
326+
}
324327
}
325328
if (nav) {
326329
_setAttrs(allNavs[0], {'tabindex': '0', 'aria-selected': 'true'});

gulpfile.js

-1
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,6 @@ var inject = require('gulp-inject');
9393
var browserSync = require('browser-sync').create();
9494
var rename = require('gulp-rename');
9595
var mergeStream = require('merge-stream');
96-
var nightwatch = require('gulp-nightwatch');
9796

9897
function errorlog (error) {
9998
console.error.bind(error);

src/tiny-slider.native.js

+3
Original file line numberDiff line numberDiff line change
@@ -321,6 +321,9 @@ var tinySlider = (function () {
321321
}
322322
if (controls) {
323323
_setAttrs(nextButton, {'tabindex': '0'});
324+
if (index === 0 && !loop || rewind) {
325+
prevButton.disabled = true;
326+
}
324327
}
325328
if (nav) {
326329
_setAttrs(allNavs[0], {'tabindex': '0', 'aria-selected': 'true'});

tests/E2E/tests.js

+88-8
Original file line numberDiff line numberDiff line change
@@ -55,15 +55,36 @@ var tt = (function () {
5555
this.dom.suiteContainer.appendChild(newLi);
5656
};
5757

58-
my.checkAttrubutes = function (el, modeName, cloneCount, items) {
58+
my.checkAttributes = function (options) {
59+
var el = options.container,
60+
mode = options.mode || 'horizontal',
61+
slideCount = options.slideCount || 8,
62+
cloneCount = options.cloneCount || slideCount,
63+
items = options.items || 3,
64+
controls = options.controls || true,
65+
nav = options.nav || true,
66+
prevDisabled = options.prevDisabled || false;
67+
68+
// check wrapper
5969
my.createSuite(
60-
'wrapped into .tiny-slider',
70+
'Slider is wrapped into .tiny-slider.',
6171
el.parentNode.className === 'tiny-slider'
6272
);
73+
74+
// check container
6375
my.createSuite(
64-
'add class tiny-content and ' + modeName,
65-
el.className.indexOf('tiny-content ' + modeName) !== -1
76+
'Classes tiny-content and ' + mode + ' are added.',
77+
el.className.indexOf('tiny-content ' + mode) !== -1
6678
);
79+
80+
// // check transform
81+
// my.createSuite(
82+
// 'Transform is added.',
83+
// el.style.transitionDuration === '0s' &&
84+
// el.style.transform === 'translate3d(0px, 0px, 0px)'
85+
// );
86+
87+
// check slides' aria-hidden
6788
var ariaHiddenAdded = true,
6889
elChildren = el.children,
6990
elChildrenLen = el.children.length;
@@ -81,20 +102,82 @@ var tt = (function () {
81102
}
82103
}
83104
my.createSuite(
84-
'aria-hiddens are correctly added',
105+
'Aria-hidden attributes are correctly added.',
85106
ariaHiddenAdded
86107
);
108+
109+
// check controls
110+
if (controls) {
111+
var controlsContainer = el.nextSibling,
112+
prevBtn = controlsContainer.children[0],
113+
nextBtn = controlsContainer.children[1];
114+
115+
my.createSuite(
116+
'Class .tiny-controls and attribute aria-label are added to controls container.',
117+
controlsContainer.className.indexOf('tiny-controls') !== -1 &&
118+
controlsContainer.getAttribute('aria-label') === 'Carousel Navigation'
119+
);
120+
my.createSuite(
121+
'Attributes are correctly added to controls.',
122+
prevBtn.getAttribute('data-controls') === 'prev' &&
123+
prevBtn.getAttribute('tabindex') === '-1' &&
124+
prevBtn.getAttribute('aria-controls') === el.id &&
125+
prevBtn.hasAttribute('disabled') === prevDisabled &&
126+
nextBtn.getAttribute('data-controls') === 'next' &&
127+
nextBtn.getAttribute('tabindex') === '0' &&
128+
nextBtn.getAttribute('aria-controls') === el.id
129+
);
130+
}
131+
132+
// check nav
133+
if (nav) {
134+
var navContainer = el.nextSibling.nextSibling,
135+
allNavs = navContainer.querySelectorAll('[data-slide]'),
136+
navEnabled = true;
137+
138+
my.createSuite(
139+
'Class .tiny-nav and attribute aria-label are added to nav container.',
140+
navContainer.className.indexOf('tiny-nav') !== -1 &&
141+
navContainer.getAttribute('aria-label') === 'Carousel Pagination'
142+
);
143+
144+
var controlsName = el.id + 'item';
145+
for (var i = 0; i < slideCount; i++) {
146+
if (navEnabled) {
147+
var tabindex = (i !== 0) ? '-1' : '0',
148+
selected = (i !== 0) ? 'false' : 'true',
149+
thisNav = allNavs[i];
150+
151+
navEnabled = thisNav.getAttribute('data-slide') === i + '' && thisNav.getAttribute('tabindex') === tabindex && thisNav.getAttribute('aria-selected') === selected && thisNav.getAttribute('aria-controls') === controlsName + i;
152+
}
153+
}
154+
155+
my.createSuite(
156+
'Attributes are correctly added to navs.',
157+
allNavs.length === slideCount && navEnabled
158+
);
159+
}
87160
};
88161

89162
return my;
90163
})();
91164

92165
tt.createSliderHtml();
93166
tt.cacheSliders();
167+
tt.createSuiteContainer();
168+
169+
// # base
94170
tinySlider({
95171
container: tt.dom.sliders.base,
96172
items: 3,
97173
}).init();
174+
tt.createSuiteTitle('base');
175+
tt.checkAttributes({
176+
container: tt.dom.sliders.base,
177+
cloneCount: 8,
178+
items: 3,
179+
prevDisabled: false,
180+
});
98181

99182
tinySlider({
100183
container: tt.dom.sliders.responsive,
@@ -165,7 +248,4 @@ tinySlider({
165248
items: 1,
166249
}).init();
167250

168-
tt.createSuiteContainer();
169251

170-
tt.createSuiteTitle('base');
171-
tt.checkAttrubutes(tt.dom.sliders.base, 'horizontal', 8, 3);

0 commit comments

Comments
 (0)