Test implementations + fixes

This commit is contained in:
Dennis Eichhorn 2018-06-30 22:49:09 +02:00
parent 8d63d48fe4
commit 953dad708a
16 changed files with 132 additions and 111 deletions

View File

@ -1,5 +1,5 @@
/**
* Account Manager.
* Account.
*
* @copyright Dennis Eichhorn
* @license OMS License 1.0

View File

@ -1,3 +1,11 @@
/**
* Math formula evaluator
*
* @copyright Dennis Eichhorn
* @license OMS License 1.0
* @version 1.0.0
* @since 1.0.0
*/
(function (jsOMS) {
"use strict";

View File

@ -1,23 +0,0 @@
/**
* Response result type enum.
*
* @copyright Dennis Eichhorn
* @license OMS License 1.0
* @version 1.0.0
* @since 1.0.0
*/
(function (jsOMS)
{
"use strict";
/** @namespace jsOMS.Message.Response */
jsOMS.Autoloader.defineNamespace('jsOMS.Message.Response');
jsOMS.Message.Response.ResponseResultType = Object.freeze({
MULTI: 0,
MESSAGE: 1,
INFO: 2,
DATA: 3,
LIST: 4
});
}(window.jsOMS = window.jsOMS || {}));

View File

@ -1,10 +0,0 @@
(function (jsOMS) {
"use strict";
jsOMS.Account = function () {
this.login = '';
this.password = '';
this.id = 0;
this.auth = null;
};
}(window.jsOMS = window.jsOMS || {}));

View File

@ -1,5 +1,5 @@
/**
* Module factory.
* Module manager.
*
* @copyright Dennis Eichhorn
* @license OMS License 1.0

View File

@ -13,7 +13,7 @@
"use strict";
/**
* Trim char from string
* Get value from array/object
*
* @param {string} path Array path
* @param {Object} data Object
@ -25,10 +25,10 @@
*
* @since 1.0.0
*/
jsOMS.getArray = function(path, data, delim)
jsOMS.getArray = function(path, data, delim = '/')
{
const pathParts = path.split(delim);
let current = data;
let pathParts = path.split(delim);
let current = data;
for (let key in pathParts) {
if (!pathParts.hasOwnProperty(key)) {
@ -39,7 +39,7 @@
return null;
}
current = current[key];
current = current[pathParts[key]];
}
return current;

View File

@ -79,14 +79,15 @@
str += '';
substr += '';
if (substr.length <= 0) {
const step = substr.length;
if (step <= 0) {
return (str.length + 1);
}
let n = 0,
pos = 0,
step = substr.length;
pos = 0;
while (true) {
pos = str.indexOf(substr, pos);
@ -126,14 +127,17 @@
jsOMS.strpbrk = function (haystack, chars)
{
const length = haystack.length;
const length = chars.length;
let found = haystack.length;
let min = haystack.length;
for (let i = 0; i < length; ++i) {
if (chars.indexOf(haystack.charAt(i)) >= 0) {
return haystack.slice(i);
if ((found = haystack.indexOf(chars.charAt(i))) >= 0 && min > found) {
min = found;
}
}
return false;
return haystack.slice(min);
};
jsOMS.htmlspecialchars = function (text, quotes) {

View File

@ -1,12 +0,0 @@
describe('ResponseResultTypeTest', function ()
{
"use strict";
beforeEach(function ()
{
});
afterEach(function ()
{
});
}

View File

@ -1,12 +0,0 @@
describe('ResponseTypeTest', function ()
{
"use strict";
beforeEach(function ()
{
});
afterEach(function ()
{
});
}

View File

@ -0,0 +1,22 @@
describe('ResponseTypeTest', function ()
{
"use strict";
describe('testEnum', function ()
{
it('Testing amount of enums', function ()
{
expect(Object.keys(jjsOMS.Message.Response.ResponseType).length).toBe(6);
});
it('Testing values of enums', function ()
{
expect(jjsOMS.Message.Response.ResponseType.TEXT).toBe('text');
expect(jjsOMS.Message.Response.ResponseType.JSON).toBe('json');
expect(jjsOMS.Message.Response.ResponseType.DOCUMENT).toBe('document');
expect(jjsOMS.Message.Response.ResponseType.BLOB).toBe('blob');
expect(jjsOMS.Message.Response.ResponseType.ARRAYBUFFER).toBe('arraybuffer');
expect(jjsOMS.Message.Response.ResponseType.DEFAULT).toBe('');
});
});
});

View File

@ -47,6 +47,10 @@
<script src="../Uri/Http.js"></script>
<script src="../Uri/UriFactory.js"></script>
<script src="../Utils/ArrayUtils.js"></script>
<script src="../Utils/GeneralUtils.js"></script>
<script src="../Utils/StringUtils.js"></script>
<!-- include spec files here... -->
<script src="Log/LoggerTest.js"></script>
<script src="Log/LogLevelTest.js"></script>
@ -74,6 +78,10 @@
<script src="Uri/HttpTest.js"></script>
<script src="Uri/UriFactoryTest.js"></script>
<script src="Utils/ArrayUtilsTest.js"></script>
<script src="Utils/GeneralUtilsTest.js"></script>
<script src="Utils/StringUtilsTest.js"></script>
</head>
<body>
</body>

View File

@ -0,0 +1,28 @@
describe('ArrayUtilsTest', function ()
{
"use strict";
describe('testGetArray', function ()
{
it('Testing get functionality', function ()
{
const expected = {
'a' : {
'aa' : 1,
'ab' : [
'aba',
'ab0',
[
3,
'c',
],
4,
],
},
2 : '2a',
};
expect(jsOMS.getArray('a/ab/1', expected)).toBe('ab0');
});
});
});

View File

@ -1,12 +0,0 @@
describe('GeneralUtilsTest', function ()
{
"use strict";
beforeEach(function ()
{
});
afterEach(function ()
{
});
}

View File

@ -1,12 +0,0 @@
describe('MarkdownTest', function ()
{
"use strict";
beforeEach(function ()
{
});
afterEach(function ()
{
});
});

View File

@ -2,11 +2,55 @@ describe('StringUtilsTest', function ()
{
"use strict";
beforeEach(function ()
describe('testTrim', function ()
{
it('Testing trim functionality', function ()
{
expect(jsOMS.trim(' hello ')).toBe('hello');
expect(jsOMS.trim(' hello')).toBe('hello');
expect(jsOMS.trim('hello ')).toBe('hello');
});
it('Testing rtrim functionality', function ()
{
expect(jsOMS.rtrim(' hello ')).toBe(' hello');
expect(jsOMS.rtrim(' hello')).toBe(' hello');
expect(jsOMS.rtrim('hello ')).toBe('hello');
});
it('Testing ltrim functionality', function ()
{
expect(jsOMS.ltrim(' hello ')).toBe('hello ');
expect(jsOMS.ltrim(' hello')).toBe('hello');
expect(jsOMS.ltrim('hello ')).toBe('hello ');
});
});
afterEach(function ()
describe('testStrpbrk', function ()
{
it('Testing strpbrk functionality', function ()
{
expect(jsOMS.strpbrk('This is a simple text.', 'ai')).toBe('is is a simple text.');
expect(jsOMS.strpbrk('This is a simple text.', 'mt')).toBe('mple text.');
expect(jsOMS.strpbrk('This is a simple text.', 'z')).toBe('');
});
});
}
describe('testSubstrCount', function ()
{
it('Testing substring cound functionality', function ()
{
expect(jsOMS.substr_count('This is a simple text.', 'is')).toBe(2);
expect(jsOMS.substr_count('This is a simple text.', 'text')).toBe(1);
expect(jsOMS.substr_count('This is a simple text.', 'imples')).toBe(0);
});
});
describe('testSpecialchars', function ()
{
it('Testing htmlspecialchars functionality', function ()
{
expect(jsOMS.htmlspecialchars('<a href="test">Test</a>')).toBe('&lt;a href=&quot;test&quot;&gt;Test&lt;/a&gt;');
});
});
});

View File

@ -1,12 +0,0 @@
describe('UiUtilsTest', function ()
{
"use strict";
beforeEach(function ()
{
});
afterEach(function ()
{
});
}