UNPKG

vimo-dt

Version:

A Vue2.x UI Project For Mobile & HyBrid

251 lines (200 loc) 7.59 kB
'use strict'; var _util = require('../util.js'); var _urlChange = require('../url-change'); var _urlChange2 = _interopRequireDefault(_urlChange); var _registerListener = require('../register-listener'); var _registerListener2 = _interopRequireDefault(_registerListener); var _type = require('../type'); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } describe('util', function () { it('isBoolean()', function () { expect((0, _type.isBoolean)(true)).toBeTruthy(); expect((0, _type.isBoolean)(false)).toBeTruthy(); }); it('isString()', function () { expect((0, _type.isString)('123')).toBeTruthy(); expect((0, _type.isString)(true)).toBeFalsy(); }); it('isNumber()', function () { expect((0, _type.isNumber)(123)).toBeTruthy(); expect((0, _type.isNumber)(true)).toBeFalsy(); }); it('isFunction()', function () { expect((0, _type.isFunction)(function () {})).toBeTruthy(); expect((0, _type.isFunction)(true)).toBeFalsy(); }); it('isDefined()', function () { expect((0, _type.isDefined)(1)).toBeTruthy(); expect((0, _type.isDefined)(undefined)).toBeFalsy(); }); it('isUndefined()', function () { expect((0, _type.isUndefined)(1)).toBeFalsy(); expect((0, _type.isUndefined)(undefined)).toBeTruthy(); }); it('isPresent()', function () { expect((0, _type.isPresent)(undefined)).toBeFalsy(); expect((0, _type.isPresent)(null)).toBeFalsy(); expect((0, _type.isPresent)('')).toBeFalsy(); }); it('isBlank()', function () { expect((0, _type.isBlank)(undefined)).toBeTruthy(); expect((0, _type.isBlank)(null)).toBeTruthy(); }); it('isObject()', function () { expect((0, _type.isObject)({})).toBeTruthy(); }); it('isDate()', function () { expect((0, _type.isDate)(new Date())).toBeTruthy(); }); it('isRegexp()', function () { expect((0, _type.isRegexp)(/w/)).toBeTruthy(); }); it('isArray()', function () { expect((0, _type.isArray)([])).toBeTruthy(); }); it('isPlainObject()', function () { expect((0, _type.isPlainObject)({})).toBeTruthy(); }); it('isPrimitive()', function () { expect((0, _type.isPrimitive)('123')).toBeTruthy(); expect((0, _type.isPrimitive)(123)).toBeTruthy(); expect((0, _type.isPrimitive)(false)).toBeTruthy(); expect((0, _type.isPrimitive)(true)).toBeTruthy(); }); it('isTrueProperty()', function () { expect((0, _type.isTrueProperty)('true')).toBeTruthy(); expect((0, _type.isTrueProperty)('on')).toBeTruthy(); expect((0, _type.isTrueProperty)('')).toBeTruthy(); }); it('isCheckedProperty()', function () { expect((0, _type.isCheckedProperty)(undefined, undefined)).toBeTruthy(); expect((0, _type.isCheckedProperty)(undefined, null)).toBeTruthy(); expect((0, _type.isCheckedProperty)(undefined, '')).toBeTruthy(); expect((0, _type.isCheckedProperty)(null, undefined)).toBeTruthy(); expect((0, _type.isCheckedProperty)(null, null)).toBeTruthy(); expect((0, _type.isCheckedProperty)(null, '')).toBeTruthy(); expect((0, _type.isCheckedProperty)('', undefined)).toBeTruthy(); expect((0, _type.isCheckedProperty)('', null)).toBeTruthy(); expect((0, _type.isCheckedProperty)('', '')).toBeTruthy(); expect((0, _type.isCheckedProperty)(true, true)).toBeTruthy(); expect((0, _type.isCheckedProperty)(true, 'true')).toBeTruthy(); expect((0, _type.isCheckedProperty)('true', true)).toBeTruthy(); expect((0, _type.isCheckedProperty)('true', 'true')).toBeTruthy(); expect((0, _type.isCheckedProperty)(false, false)).toBeTruthy(); expect((0, _type.isCheckedProperty)(false, 'false')).toBeTruthy(); expect((0, _type.isCheckedProperty)('false', false)).toBeTruthy(); expect((0, _type.isCheckedProperty)('false', 'false')).toBeTruthy(); expect((0, _type.isCheckedProperty)(0, 0)).toBeTruthy(); expect((0, _type.isCheckedProperty)(0, '0')).toBeTruthy(); expect((0, _type.isCheckedProperty)('0', 0)).toBeTruthy(); expect((0, _type.isCheckedProperty)('0', '0')).toBeTruthy(); expect((0, _type.isCheckedProperty)('123', '123')).toBeTruthy(); expect((0, _type.isCheckedProperty)('123', 123)).toBeTruthy(); }); it('transitionEnd()', function () { var res = (0, _util.transitionEnd)(window, function () {}); expect((0, _type.isFunction)(res)).toBeTruthy(); }); it('urlChange()', function () { var res = (0, _urlChange2.default)(function () {}); expect((0, _type.isFunction)(res)).toBeTruthy(); }); it('registerListener()', function () { var res = (0, _registerListener2.default)(window, 'onload', function () {}); expect((0, _type.isFunction)(res)).toBeTruthy(); }); it('docReady()', function () { var res = (0, _util.docReady)(); function getType(value) { return Object.prototype.toString.call(value).match(/^(\[object )(\w+)\]$/i)[2].toLowerCase(); } expect(getType(res)).toEqual('promise'); }); it('pointerCoord(ev):changedTouches', function () { var res = (0, _util.pointerCoord)({ changedTouches: [{ clientX: 1, clientY: 2 }] }); expect(JSON.stringify(res)).toEqual('{"x":1,"y":2}'); }); it('pointerCoord(ev):pageX', function () { var res = (0, _util.pointerCoord)({ pageX: 1, pageY: 2 }); expect(JSON.stringify(res)).toEqual('{"x":1,"y":2}'); }); it('pointerCoord()', function () { var res = (0, _util.pointerCoord)(); expect(JSON.stringify(res)).toEqual('{"x":0,"y":0}'); }); it('isActive()', function () { var res = (0, _util.isActive)(window); expect(res).toBeFalsy(); }); it('hasFocus()', function () { var res = (0, _util.hasFocus)(window); expect(res).toBeFalsy(); }); it('hasClass()', function () { var ele = { className: 'className' }; var res = (0, _util.hasClass)(ele, 'className'); expect(res).toBeTruthy(); }); it('addClass()', function () { var ele = { className: 'className' }; (0, _util.addClass)(ele, 'className12'); expect(ele.className).toEqual('className className12'); }); it('removeClass()', function () { var ele = { className: 'className className12' }; (0, _util.removeClass)(ele, 'className12'); expect(ele.className).toEqual('className'); }); it('setElementClass():add', function () { var ele = { className: 'className' }; (0, _util.setElementClass)(ele, 'className12', true); expect(ele.className).toEqual('className className12'); }); it('setElementClass():remove', function () { var ele = { className: 'className className12' }; (0, _util.setElementClass)(ele, 'className12', false); expect(ele.className).toEqual('className'); }); it('clamp():min', function () { var res = (0, _util.clamp)(1, -10, 10); expect(res).toEqual(1); }); it('clamp():mid', function () { var res = (0, _util.clamp)(1, 5, 10); expect(res).toEqual(5); }); it('clamp():max', function () { var res = (0, _util.clamp)(1, 100, 10); expect(res).toEqual(10); }); it('defaults()', function () { var res = (0, _util.defaults)({ a: 1 }, { b: 1, a: 2 }, { b: 10 }); expect(JSON.stringify(res)).toEqual('{"a":1,"b":10}'); }); it('firstUpperCase()', function () { var res = (0, _util.firstUpperCase)('helloWorld'); expect(res).toEqual('HelloWorld'); }); it('parsePxUnit()', function () { var res = (0, _util.parsePxUnit)('10px'); expect(res).toEqual(10); }); });