Skip to content

Commit

Permalink
update tests.js, disable prevButton on non-loop
Browse files Browse the repository at this point in the history
  • Loading branch information
ganlanyuan committed Oct 16, 2016
1 parent 40d2e35 commit 3b6c972
Show file tree
Hide file tree
Showing 7 changed files with 112 additions and 24 deletions.
2 changes: 1 addition & 1 deletion dist/min/tiny-slider.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/min/tiny-slider.native.js

Large diffs are not rendered by default.

29 changes: 16 additions & 13 deletions dist/tiny-slider.js
Original file line number Diff line number Diff line change
Expand Up @@ -407,7 +407,7 @@ var gn = (function (g) {
return g;
})(window.gn || {});
// extend
// @require "/src/gn/gn.js"
// @require "/src/gn/base.js"

gn.extend = function () {
var obj, name, copy,
Expand All @@ -431,19 +431,19 @@ gn.extend = function () {
return target;
};
// isInViewport
// @require "/src/gn/gn.js"
// @require "/src/gn/base.js"

gn.isInViewport = function ( elem ) {
var rect = elem.getBoundingClientRect();
return (
rect.bottom >= 0 &&
rect.right >= 0 &&
rect.top <= (window.innerHeight || document.documentElement.clientHeight) &&
rect.left <= (window.innerWidth || document.documentElement.clientWidth)
rect.bottom > 0 &&
rect.right > 0 &&
rect.top < document.documentElement.clientHeight &&
rect.left < document.documentElement.clientWidth
);
};
// indexOf
// @require "/src/gn/gn.js"
// @require "/src/gn/base.js"

gn.indexOf = function (array, item) {
for (var i = 0; i < array.length; i++) {
Expand All @@ -452,7 +452,7 @@ gn.indexOf = function (array, item) {
return -1;
};
// get supported property
// @require "/src/gn/gn.js"
// @require "/src/gn/base.js"

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

gn.ready = function ( fn ) {

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

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

// append
// @require "/src/gn/gn.js"
// @require "/src/gn/base.js"
// @require "/src/gn/isNodeList.js"

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


// wrap
// @require "/src/gn/gn.js"
// @require "/src/gn/base.js"
// @require "/src/gn/isNodeList.js"

gn.wrap = function (els, obj) {
Expand Down Expand Up @@ -548,7 +548,7 @@ gn.wrap = function (els, obj) {


// unwrap
// @require "/src/gn/gn.js"
// @require "/src/gn/base.js"
// @require "/src/gn/isNodeList.js"

gn.unwrap = function (els) {
Expand Down Expand Up @@ -891,6 +891,9 @@ var tinySlider = (function () {
}
if (controls) {
_setAttrs(nextButton, {'tabindex': '0'});
if (index === 0 && !loop || rewind) {
prevButton.disabled = true;
}
}
if (nav) {
_setAttrs(allNavs[0], {'tabindex': '0', 'aria-selected': 'true'});
Expand Down
3 changes: 3 additions & 0 deletions dist/tiny-slider.native.js
Original file line number Diff line number Diff line change
Expand Up @@ -321,6 +321,9 @@ var tinySlider = (function () {
}
if (controls) {
_setAttrs(nextButton, {'tabindex': '0'});
if (index === 0 && !loop || rewind) {
prevButton.disabled = true;
}
}
if (nav) {
_setAttrs(allNavs[0], {'tabindex': '0', 'aria-selected': 'true'});
Expand Down
1 change: 0 additions & 1 deletion gulpfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,6 @@ var inject = require('gulp-inject');
var browserSync = require('browser-sync').create();
var rename = require('gulp-rename');
var mergeStream = require('merge-stream');
var nightwatch = require('gulp-nightwatch');

function errorlog (error) {
console.error.bind(error);
Expand Down
3 changes: 3 additions & 0 deletions src/tiny-slider.native.js
Original file line number Diff line number Diff line change
Expand Up @@ -321,6 +321,9 @@ var tinySlider = (function () {
}
if (controls) {
_setAttrs(nextButton, {'tabindex': '0'});
if (index === 0 && !loop || rewind) {
prevButton.disabled = true;
}
}
if (nav) {
_setAttrs(allNavs[0], {'tabindex': '0', 'aria-selected': 'true'});
Expand Down
96 changes: 88 additions & 8 deletions tests/E2E/tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,15 +55,36 @@ var tt = (function () {
this.dom.suiteContainer.appendChild(newLi);
};

my.checkAttrubutes = function (el, modeName, cloneCount, items) {
my.checkAttributes = function (options) {
var el = options.container,
mode = options.mode || 'horizontal',
slideCount = options.slideCount || 8,
cloneCount = options.cloneCount || slideCount,
items = options.items || 3,
controls = options.controls || true,
nav = options.nav || true,
prevDisabled = options.prevDisabled || false;

// check wrapper
my.createSuite(
'wrapped into .tiny-slider',
'Slider is wrapped into .tiny-slider.',
el.parentNode.className === 'tiny-slider'
);

// check container
my.createSuite(
'add class tiny-content and ' + modeName,
el.className.indexOf('tiny-content ' + modeName) !== -1
'Classes tiny-content and ' + mode + ' are added.',
el.className.indexOf('tiny-content ' + mode) !== -1
);

// // check transform
// my.createSuite(
// 'Transform is added.',
// el.style.transitionDuration === '0s' &&
// el.style.transform === 'translate3d(0px, 0px, 0px)'
// );

// check slides' aria-hidden
var ariaHiddenAdded = true,
elChildren = el.children,
elChildrenLen = el.children.length;
Expand All @@ -81,20 +102,82 @@ var tt = (function () {
}
}
my.createSuite(
'aria-hiddens are correctly added',
'Aria-hidden attributes are correctly added.',
ariaHiddenAdded
);

// check controls
if (controls) {
var controlsContainer = el.nextSibling,
prevBtn = controlsContainer.children[0],
nextBtn = controlsContainer.children[1];

my.createSuite(
'Class .tiny-controls and attribute aria-label are added to controls container.',
controlsContainer.className.indexOf('tiny-controls') !== -1 &&
controlsContainer.getAttribute('aria-label') === 'Carousel Navigation'
);
my.createSuite(
'Attributes are correctly added to controls.',
prevBtn.getAttribute('data-controls') === 'prev' &&
prevBtn.getAttribute('tabindex') === '-1' &&
prevBtn.getAttribute('aria-controls') === el.id &&
prevBtn.hasAttribute('disabled') === prevDisabled &&
nextBtn.getAttribute('data-controls') === 'next' &&
nextBtn.getAttribute('tabindex') === '0' &&
nextBtn.getAttribute('aria-controls') === el.id
);
}

// check nav
if (nav) {
var navContainer = el.nextSibling.nextSibling,
allNavs = navContainer.querySelectorAll('[data-slide]'),
navEnabled = true;

my.createSuite(
'Class .tiny-nav and attribute aria-label are added to nav container.',
navContainer.className.indexOf('tiny-nav') !== -1 &&
navContainer.getAttribute('aria-label') === 'Carousel Pagination'
);

var controlsName = el.id + 'item';
for (var i = 0; i < slideCount; i++) {
if (navEnabled) {
var tabindex = (i !== 0) ? '-1' : '0',
selected = (i !== 0) ? 'false' : 'true',
thisNav = allNavs[i];

navEnabled = thisNav.getAttribute('data-slide') === i + '' && thisNav.getAttribute('tabindex') === tabindex && thisNav.getAttribute('aria-selected') === selected && thisNav.getAttribute('aria-controls') === controlsName + i;
}
}

my.createSuite(
'Attributes are correctly added to navs.',
allNavs.length === slideCount && navEnabled
);
}
};

return my;
})();

tt.createSliderHtml();
tt.cacheSliders();
tt.createSuiteContainer();

// # base
tinySlider({
container: tt.dom.sliders.base,
items: 3,
}).init();
tt.createSuiteTitle('base');
tt.checkAttributes({
container: tt.dom.sliders.base,
cloneCount: 8,
items: 3,
prevDisabled: false,
});

tinySlider({
container: tt.dom.sliders.responsive,
Expand Down Expand Up @@ -165,7 +248,4 @@ tinySlider({
items: 1,
}).init();

tt.createSuiteContainer();

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

0 comments on commit 3b6c972

Please sign in to comment.