Skip to content

Commit

Permalink
✅🐛添加所有测试用例并修复部分bug
Browse files Browse the repository at this point in the history
  • Loading branch information
proYang committed Nov 10, 2017
1 parent 15e57e6 commit 1dd016f
Show file tree
Hide file tree
Showing 29 changed files with 378 additions and 93 deletions.
4 changes: 2 additions & 2 deletions deepClone.js
Expand Up @@ -19,7 +19,7 @@ function deepClone(values) {
if (values instanceof Array) {
copy = [];
for (var i = 0, len = values.length; i < len; i++) {
copy[i] = cloneDeep(values[i]);
copy[i] = deepClone(values[i]);
}
return copy;
}
Expand All @@ -28,7 +28,7 @@ function deepClone(values) {
if (values instanceof Object) {
copy = {};
for (var attr in values) {
if (values.hasOwnProperty(attr)) copy[attr] = cloneDeep(values[attr]);
if (values.hasOwnProperty(attr)) copy[attr] = deepClone(values[attr]);
}
return copy;
}
Expand Down
4 changes: 2 additions & 2 deletions digitUppercase.js
Expand Up @@ -18,15 +18,15 @@ function digitUppercase(n) {
n = Math.abs(n);
var s = '';
for (var i = 0; i < fraction.length; i++) {
s += (digit[Math.floor(shiftRight(n, 1 + i)) % 10] + fraction[i]).replace(/零./, '');
s += (digit[Math.floor(n * 10 * Math.pow(10, i)) % 10] + fraction[i]).replace(/零./, '');
}
s = s || '整';
n = Math.floor(n);
for (var i = 0; i < unit[0].length && n > 0; i++) {
var p = '';
for (var j = 0; j < unit[1].length && n > 0; j++) {
p = digit[n % 10] + unit[1][j] + p;
n = Math.floor(shiftLeft(n, 1));
n = Math.floor(n / 10);
}
s = p.replace(/(零.)*零$/, '').replace(/^$/, '零') + unit[0][i] + s;
}
Expand Down
2 changes: 1 addition & 1 deletion formatRemainTime.js
Expand Up @@ -18,7 +18,7 @@ function formatRemainTime(endTime) {
m = Math.floor(t / 1000 / 60 % 60);
s = Math.floor(t / 1000 % 60);
}
return d + "天 " + h + "小时 " + m + " 分钟" + s + " 秒";
return d + "天 " + h + "小时 " + m + "分钟 " + s + "秒";
}

module.exports = formatRemainTime
14 changes: 0 additions & 14 deletions getClientHeight.js

This file was deleted.

14 changes: 0 additions & 14 deletions getClientWidth.js

This file was deleted.

4 changes: 3 additions & 1 deletion isIdCard.js
Expand Up @@ -6,4 +6,6 @@
*/
function isIdCard(str) {
return /^(^[1-9]\d{7}((0\d)|(1[0-2]))(([0|1|2]\d)|3[0-1])\d{3}$)|(^[1-9]\d{5}[1-9]\d{3}((0\d)|(1[0-2]))(([0|1|2]\d)|3[0-1])((\d{4})|\d{3}[Xx])$)$/.test(str)
}
}

module.exports = isIdCard
2 changes: 1 addition & 1 deletion isUrl.js
Expand Up @@ -5,7 +5,7 @@
* @return {Boolean}
*/
function isUrl(str) {
return /^(?:(?:https?|ftp):\/\/)?(?:(?!(?:10|127)(?:\.\d{1,3}){3})(?!(?:169\.254|192\.168)(?:\.\d{1,3}){2})(?!172\.(?:1[6-9]|2\d|3[0-1])(?:\.\d{1,3}){2})(?:[1-9]\d?|1\d\d|2[01]\d|22[0-3])(?:\.(?:1?\d{1,2}|2[0-4]\d|25[0-5])){2}(?:\.(?:[1-9]\d?|1\d\d|2[0-4]\d|25[0-4]))|(?:(?:[a-z\u00a1-\uffff0-9]-*)*[a-z\u00a1-\uffff0-9]+)(?:\.(?:[a-z\u00a1-\uffff0-9]-*)*[a-z\u00a1-\uffff0-9]+)*(?:\.(?:[a-z\u00a1-\uffff]{2,})))(?::\d{2,5})?(?:\/\S*)?$/i.test(str);
return /[-a-zA-Z0-9@:%._\+~#=]{2,256}\.[a-z]{2,6}\b([-a-zA-Z0-9@:%_\+.~#?&//=]*)/i.test(str);
}

module.exports = isUrl;
2 changes: 1 addition & 1 deletion min/outils.min.js

Large diffs are not rendered by default.

17 changes: 8 additions & 9 deletions scrollTo.js
Expand Up @@ -10,31 +10,30 @@ var requestAnimFrame = (function () {
})();
/**
*
* @desc 在${duration}时间内,滚动条平滑滚动到指定位置
* @desc 在${duration}时间内,滚动条平滑滚动到${to}指定位置
* @param {Number} to
* @param {Number} duration
*/
function scrollTo(to, duration) {
var to = 0;
var duration = 16;

if (duration < 0) return
if (duration < 0) {
setScrollTop(to);
return
}
var diff = to - getScrollTop();
if (diff === 0) return
var perTick = diff / duration * 10;
var step = diff / duration * 10;
requestAnimationFrame(
function () {
if (Math.abs(perTick) > Math.abs(diff)) {
if (Math.abs(step) > Math.abs(diff)) {
setScrollTop(getScrollTop() + diff);
return;
}
setScrollTop(getScrollTop() + perTick);
setScrollTop(getScrollTop() + step);
if (diff > 0 && getScrollTop() >= to || diff < 0 && getScrollTop() <= to) {
return;
}
scrollTo(to, duration - 16);
});

}

module.exports = scrollTo;
14 changes: 0 additions & 14 deletions src/dom/getClientHeight.js

This file was deleted.

14 changes: 0 additions & 14 deletions src/dom/getClientWidth.js

This file was deleted.

17 changes: 8 additions & 9 deletions src/dom/scrollTo.js
Expand Up @@ -10,31 +10,30 @@ var requestAnimFrame = (function () {
})();
/**
*
* @desc 在${duration}时间内,滚动条平滑滚动到指定位置
* @desc 在${duration}时间内,滚动条平滑滚动到${to}指定位置
* @param {Number} to
* @param {Number} duration
*/
function scrollTo(to, duration) {
var to = 0;
var duration = 16;

if (duration < 0) return
if (duration < 0) {
setScrollTop(to);
return
}
var diff = to - getScrollTop();
if (diff === 0) return
var perTick = diff / duration * 10;
var step = diff / duration * 10;
requestAnimationFrame(
function () {
if (Math.abs(perTick) > Math.abs(diff)) {
if (Math.abs(step) > Math.abs(diff)) {
setScrollTop(getScrollTop() + diff);
return;
}
setScrollTop(getScrollTop() + perTick);
setScrollTop(getScrollTop() + step);
if (diff > 0 && getScrollTop() >= to || diff < 0 && getScrollTop() <= to) {
return;
}
scrollTo(to, duration - 16);
});

}

module.exports = scrollTo;
4 changes: 0 additions & 4 deletions src/index.js
Expand Up @@ -14,8 +14,6 @@ const setCookie = require('./cookie/setCookie')
const getOS = require('./device/getOS')
const getExplore = require('./device/getExplore')

const getClientHeight = require('./dom/getClientHeight')
const getClientWidth = require('./dom/getClientWidth')
const getScrollTop = require('./dom/getScrollTop')
const offset = require('./dom/offset')
const scrollTo = require('./dom/scrollTo')
Expand Down Expand Up @@ -56,8 +54,6 @@ module.exports = {
getOS,
getExplore,

getClientHeight,
getClientWidth,
getScrollTop,
offset,
scrollTo,
Expand Down
4 changes: 2 additions & 2 deletions src/object/deepClone.js
Expand Up @@ -19,7 +19,7 @@ function deepClone(values) {
if (values instanceof Array) {
copy = [];
for (var i = 0, len = values.length; i < len; i++) {
copy[i] = cloneDeep(values[i]);
copy[i] = deepClone(values[i]);
}
return copy;
}
Expand All @@ -28,7 +28,7 @@ function deepClone(values) {
if (values instanceof Object) {
copy = {};
for (var attr in values) {
if (values.hasOwnProperty(attr)) copy[attr] = cloneDeep(values[attr]);
if (values.hasOwnProperty(attr)) copy[attr] = deepClone(values[attr]);
}
return copy;
}
Expand Down
4 changes: 3 additions & 1 deletion src/regexp/isIdCard.js
Expand Up @@ -6,4 +6,6 @@
*/
function isIdCard(str) {
return /^(^[1-9]\d{7}((0\d)|(1[0-2]))(([0|1|2]\d)|3[0-1])\d{3}$)|(^[1-9]\d{5}[1-9]\d{3}((0\d)|(1[0-2]))(([0|1|2]\d)|3[0-1])((\d{4})|\d{3}[Xx])$)$/.test(str)
}
}

module.exports = isIdCard
2 changes: 1 addition & 1 deletion src/regexp/isUrl.js
Expand Up @@ -5,7 +5,7 @@
* @return {Boolean}
*/
function isUrl(str) {
return /^(?:(?:https?|ftp):\/\/)?(?:(?!(?:10|127)(?:\.\d{1,3}){3})(?!(?:169\.254|192\.168)(?:\.\d{1,3}){2})(?!172\.(?:1[6-9]|2\d|3[0-1])(?:\.\d{1,3}){2})(?:[1-9]\d?|1\d\d|2[01]\d|22[0-3])(?:\.(?:1?\d{1,2}|2[0-4]\d|25[0-5])){2}(?:\.(?:[1-9]\d?|1\d\d|2[0-4]\d|25[0-4]))|(?:(?:[a-z\u00a1-\uffff0-9]-*)*[a-z\u00a1-\uffff0-9]+)(?:\.(?:[a-z\u00a1-\uffff0-9]-*)*[a-z\u00a1-\uffff0-9]+)*(?:\.(?:[a-z\u00a1-\uffff]{2,})))(?::\d{2,5})?(?:\/\S*)?$/i.test(str);
return /[-a-zA-Z0-9@:%._\+~#=]{2,256}\.[a-z]{2,6}\b([-a-zA-Z0-9@:%_\+.~#?&//=]*)/i.test(str);
}

module.exports = isUrl;
4 changes: 2 additions & 2 deletions src/string/digitUppercase.js
Expand Up @@ -18,15 +18,15 @@ function digitUppercase(n) {
n = Math.abs(n);
var s = '';
for (var i = 0; i < fraction.length; i++) {
s += (digit[Math.floor(shiftRight(n, 1 + i)) % 10] + fraction[i]).replace(/零./, '');
s += (digit[Math.floor(n * 10 * Math.pow(10, i)) % 10] + fraction[i]).replace(/零./, '');
}
s = s || '整';
n = Math.floor(n);
for (var i = 0; i < unit[0].length && n > 0; i++) {
var p = '';
for (var j = 0; j < unit[1].length && n > 0; j++) {
p = digit[n % 10] + unit[1][j] + p;
n = Math.floor(shiftLeft(n, 1));
n = Math.floor(n / 10);
}
s = p.replace(/(零.)*零$/, '').replace(/^$/, '零') + unit[0][i] + s;
}
Expand Down
2 changes: 1 addition & 1 deletion src/time/formatRemainTime.js
Expand Up @@ -18,7 +18,7 @@ function formatRemainTime(endTime) {
m = Math.floor(t / 1000 / 60 % 60);
s = Math.floor(t / 1000 % 60);
}
return d + "天 " + h + "小时 " + m + " 分钟" + s + " 秒";
return d + "天 " + h + "小时 " + m + "分钟 " + s + "秒";
}

module.exports = formatRemainTime
53 changes: 53 additions & 0 deletions test/class.test.js
@@ -0,0 +1,53 @@
describe('Class API:', function () {
describe('#addClass()', function () {
let $ele = null
before(function () {
let div = document.createElement('div')
div.id = 'J_addClass'
document.body.appendChild(div)
$ele = document.querySelector('#J_addClass')
})
it(`outils.addClass($ele, 'test') should return true`, function () {
outils.addClass($ele, 'test')
assert(outils.hasClass($ele, 'test'))
});
after(function () {
document.body.removeChild($ele)
})
});

describe('#hasClass()', function () {
let $ele = null
before(function () {
let div = document.createElement('div')
div.id = 'J_hasClass'
document.body.appendChild(div)
$ele = document.querySelector('#J_hasClass')
outils.addClass($ele, 'test')
})
it(`outils.hasClass($ele, 'test') should return true`, function () {
assert(outils.hasClass($ele, 'test'))
});
after(function () {
document.body.removeChild($ele)
})
});

describe('#removeClass()', function () {
let $ele = null
before(function () {
let div = document.createElement('div')
div.id = 'J_removeClass'
document.body.appendChild(div)
$ele = document.querySelector('#J_removeClass')
outils.addClass($ele, 'test')
})
it(`outils.removeClass($ele, 'test') should return false`, function () {
outils.removeClass($ele, 'test')
assert.notEqual(outils.hasClass($ele, 'test'))
});
after(function () {
document.body.removeChild($ele)
})
});
});
33 changes: 33 additions & 0 deletions test/cookie.test.js
@@ -0,0 +1,33 @@
describe('Cookie API:', function () {
describe('#getCookie()', function () {
before(function () {
outils.setCookie('test', 'getTestValue')
})
it(`outils.getCookie('test', 'getTestValue') should return true`, function () {
assert(outils.getCookie('test') === 'getTestValue')
})
after(function () {
outils.removeCookie('test')
})
})

describe('#removeCookie()', function () {
before(function () {
outils.setCookie('test', 'removeTestValue')
})
it(`outils.removeCookie('test') should return false`, function () {
outils.removeCookie('test')
assert.notEqual(outils.getCookie('test') === 'removeTestValue')
})
})

describe('#setCookie()', function () {
it(`outils.getCookie('test', 'setCookie') should return true`, function () {
outils.setCookie('test', 'setCookie')
assert(outils.getCookie('test') === 'setCookie')
})
after(function () {
outils.removeCookie('test')
})
})
})

0 comments on commit 1dd016f

Please sign in to comment.