cronapi-js 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +14 -0
- package/cronapi.js +8298 -0
- package/dist/cronapi.min.js +1 -0
- package/gulpfile.js +29 -0
- package/i18n/locale_en_us.json +2281 -0
- package/i18n/locale_pt_br.json +2283 -0
- package/include/modal.view.html +16 -0
- package/package.json +46 -0
- package/src/cronapi.async.ts +76 -0
- package/src/i18n/locale_en_us.json +6 -0
- package/src/i18n/locale_pt_br.json +6 -0
- package/test/src/test/cronapi/chart/chart.spec.ts +17 -0
- package/test/src/test/cronapi/cronversion/conversion.spec.ts +127 -0
- package/test/src/test/cronapi/json/json.spec.ts +59 -0
- package/test/src/test/cronapi/logic/logic.spec.ts +43 -0
- package/test/src/test/cronapi/map/map.spec.ts +52 -0
- package/test/src/test/cronapi/object/object.spec.ts +106 -0
- package/test/src/test/cronapi/regex/regex.spec.ts +44 -0
- package/test/src/test/cronapi/screen/screen.spec.ts +425 -0
- package/test/src/test/cronapi/text/text.spec.ts +57 -0
- package/test/src/test/cronapi/util/util.spec.ts +28 -0
- package/test/src/test/cronapi/xml/xml.spec.ts +86 -0
- package/tsconfig.json +23 -0
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
<div class="modal fade" id="modalTemplate" tabindex="-1" role="dialog" aria-labelledby="modalTemplateTitle" aria-hidden="true">
|
|
2
|
+
<div class="modal-dialog" role="document">
|
|
3
|
+
<div class="modal-content">
|
|
4
|
+
<div class="modal-header">
|
|
5
|
+
<button type="button" class="close" data-dismiss="modal" aria-label="Close" id="modalTemplateClose"><span aria-hidden="true">×</span></button>
|
|
6
|
+
<h2 class="modal-title" id="modalTemplateTitle">Title</h2>
|
|
7
|
+
</div>
|
|
8
|
+
<div class="modal-body" id="modalTemplateBody">
|
|
9
|
+
</div>
|
|
10
|
+
<div class="modal-footer">
|
|
11
|
+
<button type="button" class="btn btn-secondary" data-dismiss="modal" id="modalTemplateCancel">Cancel</button>
|
|
12
|
+
<button type="button" class="btn btn-primary" data-dismiss="modal" id="modalTemplateSave">Save</button>
|
|
13
|
+
</div>
|
|
14
|
+
</div>
|
|
15
|
+
</div>
|
|
16
|
+
</div>
|
package/package.json
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "cronapi-js",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "Public library for CronApp's users",
|
|
5
|
+
"main": "cronapi.js",
|
|
6
|
+
"type": "module",
|
|
7
|
+
"scripts": {
|
|
8
|
+
"test": "jest --coverage",
|
|
9
|
+
"build": "gulp"
|
|
10
|
+
},
|
|
11
|
+
"repository": {
|
|
12
|
+
"type": "git",
|
|
13
|
+
"url": "git+https://github.com/technecloud/cronapi-js.git"
|
|
14
|
+
},
|
|
15
|
+
"author": "Arthemus Cicotti Moreira",
|
|
16
|
+
"license": "MIT",
|
|
17
|
+
"bugs": {
|
|
18
|
+
"url": "https://github.com/technecloud/cronapi-js/issues"
|
|
19
|
+
},
|
|
20
|
+
"homepage": "https://github.com/technecloud/cronapi-js#readme",
|
|
21
|
+
"keywords": [
|
|
22
|
+
"cronapi",
|
|
23
|
+
"cronapp",
|
|
24
|
+
"javascript"
|
|
25
|
+
],
|
|
26
|
+
"devDependencies": {
|
|
27
|
+
"@types/chai": "^4.3.19",
|
|
28
|
+
"@types/jest": "^26.0.15",
|
|
29
|
+
"@types/node": "^14.14.6",
|
|
30
|
+
"chai": "^5.1.1",
|
|
31
|
+
"gulp": "^5.0.0",
|
|
32
|
+
"gulp-autoprefixer": "^9.0.0",
|
|
33
|
+
"gulp-concat": "2.6.1",
|
|
34
|
+
"gulp-notify": "^5.0.0",
|
|
35
|
+
"gulp-rename": "^2.0.0",
|
|
36
|
+
"gulp-terser": "^2.1.0",
|
|
37
|
+
"gulp-uglify": "^3.0.2",
|
|
38
|
+
"gulp-util": "^3.0.8",
|
|
39
|
+
"jest": "^26.6.3",
|
|
40
|
+
"jquery": "3.5.1"
|
|
41
|
+
},
|
|
42
|
+
"dependencies": {
|
|
43
|
+
"@zxing/library": "0.18.5",
|
|
44
|
+
"natives": "1.1.6"
|
|
45
|
+
}
|
|
46
|
+
}
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
declare var $: any;
|
|
2
|
+
|
|
3
|
+
(function() {
|
|
4
|
+
'use strict';
|
|
5
|
+
|
|
6
|
+
this.cronapi = this.cronapi||{};
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* @category CategoryType.UTIL
|
|
10
|
+
* @categoryTags Util
|
|
11
|
+
*/
|
|
12
|
+
this.cronapi.util = this.cronapi.util||{};
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* @type function
|
|
16
|
+
* @name {{callServerBlockly}}
|
|
17
|
+
* @nameTags callServerBlockly
|
|
18
|
+
* @description {{functionToCallServerBlockly}}
|
|
19
|
+
* @param {ObjectType.STRING} classNameWithMethod {{classNameWithMethod}}
|
|
20
|
+
* @param {ObjectType.OBJECT} params {{params}}
|
|
21
|
+
* @arbitraryParams true
|
|
22
|
+
* @wizard procedures_callblockly_callreturn
|
|
23
|
+
* @returns {ObjectType.OBJECT}
|
|
24
|
+
*/
|
|
25
|
+
this.cronapi.util.callServerBlockly = async function(classNameWithMethod, ...params: any[]) {
|
|
26
|
+
|
|
27
|
+
var serverUrl = 'api/cronapi/call/body/#classNameWithMethod#/'.replace('#classNameWithMethod#', classNameWithMethod);
|
|
28
|
+
var params = [];
|
|
29
|
+
|
|
30
|
+
var fields = this.cronapi.util.getScreenFields();
|
|
31
|
+
|
|
32
|
+
var dataCall = {
|
|
33
|
+
"fields": fields,
|
|
34
|
+
"inputs": params
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
var resultData;
|
|
38
|
+
|
|
39
|
+
let headerValues = window.isUsingCookie() ? {
|
|
40
|
+
'Content-Type' : 'application/json',
|
|
41
|
+
'toJS' : true
|
|
42
|
+
} : {
|
|
43
|
+
'Content-Type' : 'application/json',
|
|
44
|
+
'X-AUTH-TOKEN' : this.cronapi.util.getUserToken(),
|
|
45
|
+
'toJS' : true
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
try {
|
|
49
|
+
resultData = await $.ajax({
|
|
50
|
+
type: 'POST',
|
|
51
|
+
url: (window['hostApp'] || "") + serverUrl,
|
|
52
|
+
dataType: 'html',
|
|
53
|
+
data : JSON.stringify(dataCall),
|
|
54
|
+
async: true,
|
|
55
|
+
headers: headerValues
|
|
56
|
+
});
|
|
57
|
+
} catch(e) {
|
|
58
|
+
var message = this.cronapi.internal.getErrorMessage(e.responseText, e.statusText);
|
|
59
|
+
this.cronapi.$scope.Notification.error(message);
|
|
60
|
+
throw message;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
var result;
|
|
64
|
+
|
|
65
|
+
var objectConstructor = {}.constructor;
|
|
66
|
+
|
|
67
|
+
if (resultData.constructor === objectConstructor) {
|
|
68
|
+
result = resultData;
|
|
69
|
+
} else {
|
|
70
|
+
result = this.cronapi.evalInContext(resultData);
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
return result;
|
|
74
|
+
};
|
|
75
|
+
|
|
76
|
+
}).bind(window)();
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
describe('Test suit for category chart from Cronapi.js', function() {
|
|
2
|
+
const ch = require('chai');
|
|
3
|
+
ch.should();
|
|
4
|
+
|
|
5
|
+
let {window} = require('../../../../../cronapi');
|
|
6
|
+
const cronapi = window["cronapi"];
|
|
7
|
+
|
|
8
|
+
it('createChart', function() {
|
|
9
|
+
});
|
|
10
|
+
|
|
11
|
+
it('createDataset', function() {
|
|
12
|
+
var element = document.querySelector('#user');
|
|
13
|
+
let value = cronapi.chart.createDataset(element, element, element);
|
|
14
|
+
value.should.eql({"data": [], "label": "", "options": null});
|
|
15
|
+
});
|
|
16
|
+
|
|
17
|
+
});
|
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
describe('Test suit for category conversion from Cronapi.js',
|
|
2
|
+
function() {
|
|
3
|
+
const ch = require('chai');
|
|
4
|
+
let {window} = require('../../../../../cronapi');
|
|
5
|
+
ch.should();
|
|
6
|
+
const cronapi = window["cronapi"];
|
|
7
|
+
|
|
8
|
+
it('asciiToBinary', function() {
|
|
9
|
+
let value = cronapi.conversion.asciiToBinary.bind(window)('hello');
|
|
10
|
+
value.should.equal('0110100001100101011011000110110001101111');
|
|
11
|
+
|
|
12
|
+
value = cronapi.conversion.asciiToBinary.bind(window)('');
|
|
13
|
+
value.should.equal('');
|
|
14
|
+
});
|
|
15
|
+
|
|
16
|
+
it('toBoolean', function() {
|
|
17
|
+
let value = cronapi.conversion.toBoolean.bind(window)(true);
|
|
18
|
+
value.should.equal(true);
|
|
19
|
+
|
|
20
|
+
value = cronapi.conversion.toBoolean.bind(window)(false);
|
|
21
|
+
value.should.equal(false);
|
|
22
|
+
|
|
23
|
+
value = cronapi.conversion.toBoolean.bind(window)(null);
|
|
24
|
+
value.should.equal(false);
|
|
25
|
+
|
|
26
|
+
value = cronapi.conversion.toBoolean.bind(window)('1');
|
|
27
|
+
value.should.equal(true);
|
|
28
|
+
|
|
29
|
+
value = cronapi.conversion.toBoolean.bind(window)('true');
|
|
30
|
+
value.should.equal(true);
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
it('toBytes', function() {
|
|
34
|
+
let value = cronapi.conversion.toBytes.bind(window)();
|
|
35
|
+
value.should.equal('');
|
|
36
|
+
|
|
37
|
+
value = cronapi.conversion.toBytes.bind(window)(null);
|
|
38
|
+
value.should.equal('');
|
|
39
|
+
|
|
40
|
+
value = cronapi.conversion.toBytes.bind(window)(undefined);
|
|
41
|
+
value.should.equal('');
|
|
42
|
+
|
|
43
|
+
value = cronapi.conversion.toBytes.bind(window)(10);
|
|
44
|
+
value.should.equal('10');
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
it('chrToAscii ', function() {
|
|
48
|
+
let value = cronapi.conversion.chrToAscii.bind(window)();
|
|
49
|
+
(value === null).should.equal(true);
|
|
50
|
+
|
|
51
|
+
value = cronapi.conversion.chrToAscii.bind(window)(null);
|
|
52
|
+
(value === null).should.equal(true);
|
|
53
|
+
|
|
54
|
+
value = cronapi.conversion.chrToAscii.bind(window)(undefined);
|
|
55
|
+
(value === null).should.equal(true);
|
|
56
|
+
|
|
57
|
+
value = cronapi.conversion.chrToAscii.bind(window)('h');
|
|
58
|
+
value.should.equal(104);
|
|
59
|
+
|
|
60
|
+
value = cronapi.conversion.chrToAscii.bind(window)('hello');
|
|
61
|
+
value.should.equal(104);
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
it('stringToJs', function() {
|
|
65
|
+
let value = cronapi.conversion.stringToJs.bind(window)('{"usename": "admin", "password": 123}');
|
|
66
|
+
value.should.equal('{\\"usename\\": \\"admin\\", \\"password\\": 123}');
|
|
67
|
+
});
|
|
68
|
+
|
|
69
|
+
it('stringToDate', function() {
|
|
70
|
+
const validDate = new Date(2020, 10, 13);
|
|
71
|
+
|
|
72
|
+
let value = cronapi.conversion.stringToDate.bind(window)(validDate);
|
|
73
|
+
value.should.equal(validDate);
|
|
74
|
+
|
|
75
|
+
value = cronapi.conversion.stringToDate.bind(window)(null);
|
|
76
|
+
(value === null).should.equal(true);
|
|
77
|
+
|
|
78
|
+
value = cronapi.conversion.stringToDate.bind(window)(undefined);
|
|
79
|
+
(value === null).should.equal(true);
|
|
80
|
+
|
|
81
|
+
value = cronapi.conversion.stringToDate.bind(window)('2020-11');
|
|
82
|
+
(value.toUTCString()).should.equal(new Date("Sun Nov 01 2020 00:00:00 GMT-0000").toUTCString());
|
|
83
|
+
|
|
84
|
+
Object.defineProperty(window.navigator, 'language', { value: 'es-Es', writable: true, configurable: true });
|
|
85
|
+
value = cronapi.conversion.stringToDate.bind(window)('2020-11-13');
|
|
86
|
+
(value.toUTCString()).should.equal(new Date("Sun Nov 13 2020 00:00:00 GMT-0000").toUTCString());
|
|
87
|
+
|
|
88
|
+
// Os três casos abaixo contemplariam o restante da cobertura, não ficou totalmente
|
|
89
|
+
// funcional porque não foi possível mockar as funções internas chamadas
|
|
90
|
+
// pelo eval: cronapi.internal.enDate e cronapi.internal.enDate
|
|
91
|
+
|
|
92
|
+
Object.defineProperty(window.navigator, 'language', { value: 'en-Us' });
|
|
93
|
+
// value = cronapi.conversion.stringToDate.bind(window)('10-13-2020');
|
|
94
|
+
// value.should.equal(validDate);
|
|
95
|
+
|
|
96
|
+
// Object.defineProperty(window.navigator, 'language', { value: 'pt-BR', writable: true });
|
|
97
|
+
// value = cronapi.conversion.stringToDate.bind(window)('13-10-2020');
|
|
98
|
+
// value.should.equal(validDate);
|
|
99
|
+
|
|
100
|
+
// Object.defineProperty(window.navigator, 'language', { value: null });
|
|
101
|
+
// Object.defineProperty(window.navigator, 'userLanguage', { value: 'pt-BR', writable: true });
|
|
102
|
+
// value = cronapi.conversion.stringToDate.bind(window)('13-10-2020');
|
|
103
|
+
// value.should.equal(validDate);
|
|
104
|
+
});
|
|
105
|
+
|
|
106
|
+
it('intToHex', function() {
|
|
107
|
+
let value = cronapi.conversion.intToHex.bind(window)(10);
|
|
108
|
+
value.should.equal('A');
|
|
109
|
+
});
|
|
110
|
+
|
|
111
|
+
it('toLong', function() {
|
|
112
|
+
let value = cronapi.conversion.toLong.bind(window)('10');
|
|
113
|
+
value.should.equal(10);
|
|
114
|
+
});
|
|
115
|
+
|
|
116
|
+
it('toString', function() {
|
|
117
|
+
let value = cronapi.conversion.toString.bind(window)(10);
|
|
118
|
+
value.should.equal('10');
|
|
119
|
+
|
|
120
|
+
value = cronapi.conversion.toString.bind(window)(null);
|
|
121
|
+
value.should.equal('');
|
|
122
|
+
|
|
123
|
+
value = cronapi.conversion.toString.bind(window)(undefined);
|
|
124
|
+
value.should.equal('');
|
|
125
|
+
});
|
|
126
|
+
|
|
127
|
+
});
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
describe('Test suit for category json from Cronapi.js',
|
|
2
|
+
function() {
|
|
3
|
+
const ch = require('chai');
|
|
4
|
+
let {window} = require('../../../../../cronapi');
|
|
5
|
+
ch.should();
|
|
6
|
+
const cronapi = window["cronapi"];
|
|
7
|
+
|
|
8
|
+
it('createObjectFromString', function() {
|
|
9
|
+
let value = cronapi.json.createObjectFromString.bind(window)('{"user": {"username": "admin"}}');
|
|
10
|
+
(JSON.stringify(value)).should.equal('{"user":{"username":"admin"}}');
|
|
11
|
+
});
|
|
12
|
+
|
|
13
|
+
it('setProperty', function() {
|
|
14
|
+
let user = {};
|
|
15
|
+
user['username'] = 'admin';
|
|
16
|
+
user['password'] = '123';
|
|
17
|
+
user['info'] = {name: 'Administrator', birthday: '01/01/2000'};
|
|
18
|
+
|
|
19
|
+
cronapi.json.setProperty.bind(window)(user, 'username', 'john');
|
|
20
|
+
let value = cronapi.json.getProperty.bind(window)(user, 'username');
|
|
21
|
+
value.should.equal('john');
|
|
22
|
+
|
|
23
|
+
cronapi.json.setProperty.bind(window)(user, 'info.name', 'John');
|
|
24
|
+
value = cronapi.json.getProperty.bind(window)(user, 'info.name');
|
|
25
|
+
value.should.equal('John');
|
|
26
|
+
|
|
27
|
+
user['info'] = {name: 'Administrator', birthday: undefined};
|
|
28
|
+
cronapi.json.setProperty.bind(window)(user, 'info.birthday', undefined);
|
|
29
|
+
value = cronapi.json.getProperty.bind(window)(user, 'info.birthday');
|
|
30
|
+
(JSON.stringify(value)).should.equal('{}');
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
it('deleteProperty', function() {
|
|
34
|
+
let user = {};
|
|
35
|
+
user['username'] = 'admin';
|
|
36
|
+
user['password'] = '123';
|
|
37
|
+
user['info'] = {name: 'Administrator', birthday: '01/01/2000'};
|
|
38
|
+
|
|
39
|
+
cronapi.json.deleteProperty.bind(window)(user, "info");
|
|
40
|
+
let value = cronapi.json.getProperty.bind(window)(user, "info");
|
|
41
|
+
(value === undefined).should.equal(true);
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
it('getProperty', function() {
|
|
45
|
+
let user = {};
|
|
46
|
+
user['username'] = 'admin';
|
|
47
|
+
user['password'] = '123';
|
|
48
|
+
user['info'] = {name: 'Administrator', birthday: undefined};
|
|
49
|
+
|
|
50
|
+
let value = cronapi.json.getProperty.bind(window)(user, 'username');
|
|
51
|
+
value.should.equal('admin');
|
|
52
|
+
|
|
53
|
+
value = cronapi.json.getProperty.bind(window)(user, 'info.name');
|
|
54
|
+
value.should.equal('Administrator');
|
|
55
|
+
|
|
56
|
+
value = cronapi.json.getProperty.bind(window)(user, 'info.birthday');
|
|
57
|
+
(JSON.stringify(value)).should.equal('{}');
|
|
58
|
+
});
|
|
59
|
+
});
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
describe('Test suit for category logic from Cronapi.js', function() {
|
|
2
|
+
const ch = require('chai');
|
|
3
|
+
ch.should();
|
|
4
|
+
|
|
5
|
+
let {window} = require('../../../../../cronapi');
|
|
6
|
+
const cronapi = window["cronapi"];
|
|
7
|
+
|
|
8
|
+
it('isNull', function() {
|
|
9
|
+
let value = cronapi.logic.isNull.bind(window)(null);
|
|
10
|
+
value.should.eql(true);
|
|
11
|
+
|
|
12
|
+
value = cronapi.logic.isNull.bind(window)('undefined');
|
|
13
|
+
value.should.eql(false);
|
|
14
|
+
});
|
|
15
|
+
|
|
16
|
+
it('isEmpty', function() {
|
|
17
|
+
let value = cronapi.logic.isEmpty.bind(window)('');
|
|
18
|
+
value.should.eql(true);
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
it('isNullOrEmpty', function() {
|
|
22
|
+
let value = cronapi.logic.isNullOrEmpty.bind(window)(null);
|
|
23
|
+
value.should.eql(true);
|
|
24
|
+
|
|
25
|
+
value = cronapi.logic.isNullOrEmpty.bind(window)('undefined');
|
|
26
|
+
value.should.eql(false);
|
|
27
|
+
|
|
28
|
+
value = cronapi.logic.isNullOrEmpty.bind(window)('');
|
|
29
|
+
value.should.eql(true);
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
it('typeOf', function() {
|
|
33
|
+
let value = cronapi.logic.typeOf.bind(window)(null, 'array');
|
|
34
|
+
value.should.eql(false);
|
|
35
|
+
|
|
36
|
+
value = cronapi.logic.typeOf.bind(window)(new Array(), 'object');
|
|
37
|
+
value.should.eql(false);
|
|
38
|
+
|
|
39
|
+
value = cronapi.logic.typeOf.bind(window)(null, 'object');
|
|
40
|
+
value.should.eql(false);
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
});
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
|
|
2
|
+
describe('Test suit for category map from Cronapi.js',
|
|
3
|
+
function() {
|
|
4
|
+
|
|
5
|
+
const ch = require('chai');
|
|
6
|
+
let {window} = require('../../../../../cronapi');
|
|
7
|
+
ch.should();
|
|
8
|
+
const cronapi = window["cronapi"];
|
|
9
|
+
|
|
10
|
+
let mapCreated;
|
|
11
|
+
|
|
12
|
+
beforeAll(() => {
|
|
13
|
+
let map = [
|
|
14
|
+
{"param1" : {"name":"John", "age":30, "car":null}},
|
|
15
|
+
{"param2" : {"name":"Marie"}},
|
|
16
|
+
{"param3" : "Chic"},
|
|
17
|
+
]
|
|
18
|
+
mapCreated = cronapi.map.createMap.bind(window)(map);
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
it('createMap', function() {
|
|
22
|
+
(mapCreated[0].param1.car === null).should.equal(true);
|
|
23
|
+
(mapCreated[0].param1.age === 30).should.equal(true);
|
|
24
|
+
(mapCreated[1].param2.name === "Marie").should.equal(true);
|
|
25
|
+
(mapCreated[2].param3 === "Chic").should.equal(true);
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
it('setMapValueByKey', function() {
|
|
29
|
+
cronapi.map.setMapValueByKey.bind(window)(mapCreated, "param4", "Brasil");
|
|
30
|
+
(mapCreated[3].param4 === "Brasil").should.equal(true);
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
it('setMapValueByPath', function() {
|
|
34
|
+
cronapi.map.setMapValueByPath.bind(window)(mapCreated, "param5.lowcode.platform", "Cronapp");
|
|
35
|
+
(mapCreated[4].param5 !== null).should.equal(true);
|
|
36
|
+
(mapCreated[4].param5.lowcode !== null).should.equal(true);
|
|
37
|
+
(mapCreated[4].param5.lowcode.platform === "Cronapp").should.equal(true);
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
it('getMapValueByPath', function() {
|
|
41
|
+
const result = cronapi.map.getMapValueByPath.bind(window)(mapCreated, "param5.lowcode.platform");
|
|
42
|
+
(result !== null).should.equal(true);
|
|
43
|
+
(result === "Cronapp").should.equal(true);
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
it('getMapValueByKey', function() {
|
|
47
|
+
const result = cronapi.map.getMapValueByKey.bind(window)(mapCreated, "param3");
|
|
48
|
+
(result !== null).should.equal(true);
|
|
49
|
+
(result === "Chic").should.equal(true);
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
});
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
describe('Test suit for category object from Cronapi.js',
|
|
2
|
+
function() {
|
|
3
|
+
const ch = require('chai');
|
|
4
|
+
let {window} = require('../../../../../cronapi');
|
|
5
|
+
ch.should();
|
|
6
|
+
const cronapi = window["cronapi"];
|
|
7
|
+
|
|
8
|
+
it('getProperty', function() {
|
|
9
|
+
let user = {};
|
|
10
|
+
user['username'] = 'admin';
|
|
11
|
+
user['password'] = '123';
|
|
12
|
+
user['info'] = {name: 'Administrator', birthday: undefined};
|
|
13
|
+
|
|
14
|
+
let value = cronapi.object.getProperty.bind(window)(user, 'username');
|
|
15
|
+
value.should.equal('admin');
|
|
16
|
+
|
|
17
|
+
value = cronapi.object.getProperty.bind(window)(user, 'info.name');
|
|
18
|
+
value.should.equal('Administrator');
|
|
19
|
+
|
|
20
|
+
value = cronapi.object.getProperty.bind(window)(user, 'info.birthday');
|
|
21
|
+
(JSON.stringify(value)).should.equal('{}');
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
it('setProperty', function() {
|
|
25
|
+
let user = {};
|
|
26
|
+
user['username'] = 'admin';
|
|
27
|
+
user['password'] = '123';
|
|
28
|
+
user['info'] = {name: 'Administrator', birthday: '01/01/2000'};
|
|
29
|
+
|
|
30
|
+
cronapi.object.setProperty.bind(window)(user, 'username', 'john');
|
|
31
|
+
let value = cronapi.object.getProperty.bind(window)(user, 'username');
|
|
32
|
+
value.should.equal('john');
|
|
33
|
+
|
|
34
|
+
cronapi.object.setProperty.bind(window)(user, 'info.name', 'John');
|
|
35
|
+
value = cronapi.object.getProperty.bind(window)(user, 'info.name');
|
|
36
|
+
value.should.equal('John');
|
|
37
|
+
|
|
38
|
+
user['info'] = {name: 'Administrator', birthday: undefined};
|
|
39
|
+
cronapi.object.setProperty.bind(window)(user, 'info.birthday', undefined);
|
|
40
|
+
value = cronapi.object.getProperty.bind(window)(user, 'info.birthday');
|
|
41
|
+
(JSON.stringify(value)).should.equal('{}');
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
it('createObjectFromString', function() {
|
|
45
|
+
let value = cronapi.object.createObjectFromString.bind(window)('{"user": {"username": "admin"}}');
|
|
46
|
+
(JSON.stringify(value)).should.equal('{"user":{"username":"admin"}}');
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
it('createObjectLoginFromString', function() {
|
|
50
|
+
let value = cronapi.object.createObjectLoginFromString.bind(window)("admin", 123);
|
|
51
|
+
(JSON.stringify(value)).should.equal('{"username":"admin","password":123}');
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
it('serializeObject', function() {
|
|
55
|
+
let value = cronapi.object.serializeObject.bind(window)({username:"admin", password: 123});
|
|
56
|
+
value.should.equal('{"username":"admin","password":123}');
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
it('deleteProperty', function() {
|
|
60
|
+
let user = {};
|
|
61
|
+
user['username'] = 'admin';
|
|
62
|
+
user['password'] = '123';
|
|
63
|
+
user['info'] = {name: 'Administrator', birthday: '01/01/2000'};
|
|
64
|
+
|
|
65
|
+
cronapi.object.deleteProperty.bind(window)(user, "info");
|
|
66
|
+
let value = cronapi.object.getProperty(user, "info");
|
|
67
|
+
(value === undefined).should.equal(true);
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
it('newObject', function() {
|
|
71
|
+
let user = {};
|
|
72
|
+
user['username'] = 'admin';
|
|
73
|
+
user['password'] = '123';
|
|
74
|
+
user['info'] = {name: 'Administrator', birthday: '01/01/2000'};
|
|
75
|
+
|
|
76
|
+
let value = cronapi.object.newObject.bind(window)();
|
|
77
|
+
(JSON.stringify(value)).should.equal('{}');
|
|
78
|
+
|
|
79
|
+
value = cronapi.object.newObject.bind(window)({username: 'admin'});
|
|
80
|
+
(JSON.stringify(value)).should.equal('{}');
|
|
81
|
+
|
|
82
|
+
value = cronapi.object.newObject.bind(window)({name: 'username', value: 'admin'});
|
|
83
|
+
(JSON.stringify(value)).should.equal('{"username":"admin"}');
|
|
84
|
+
});
|
|
85
|
+
|
|
86
|
+
it('getObjectField', function() {
|
|
87
|
+
let user = {};
|
|
88
|
+
user['username'] = 'admin';
|
|
89
|
+
|
|
90
|
+
let value = cronapi.object.getObjectField.bind(window)(user, null);
|
|
91
|
+
(value === undefined).should.equal(true);
|
|
92
|
+
|
|
93
|
+
value = cronapi.object.getObjectField.bind(window)(user, undefined);
|
|
94
|
+
(value === undefined).should.equal(true);
|
|
95
|
+
|
|
96
|
+
value = cronapi.object.getObjectField.bind(window)(null, 'username');
|
|
97
|
+
(value === undefined).should.equal(true);
|
|
98
|
+
|
|
99
|
+
value = cronapi.object.getObjectField.bind(window)(undefined, 'username');
|
|
100
|
+
(value === undefined).should.equal(true);
|
|
101
|
+
|
|
102
|
+
value = cronapi.object.getObjectField.bind(window)(user, 'username');
|
|
103
|
+
value.should.equal('admin');
|
|
104
|
+
});
|
|
105
|
+
|
|
106
|
+
});
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
describe('Test suit for category regex from Cronapi.js', function() {
|
|
2
|
+
|
|
3
|
+
const chai = require('chai');
|
|
4
|
+
chai.should();
|
|
5
|
+
let expect = chai.expect;
|
|
6
|
+
let {window} = require('../../../../../cronapi');
|
|
7
|
+
const cronapi = window["cronapi"];
|
|
8
|
+
|
|
9
|
+
it('extractTextByRegex', function() {
|
|
10
|
+
let result;
|
|
11
|
+
|
|
12
|
+
result = cronapi.regex.extractTextByRegex.bind(window)(null, '[0-9]', 'g');
|
|
13
|
+
expect(result).to.be.empty;
|
|
14
|
+
|
|
15
|
+
result = cronapi.regex.extractTextByRegex.bind(window)('abcde1234', null, 'g');
|
|
16
|
+
expect(result).to.be.empty;
|
|
17
|
+
|
|
18
|
+
result = cronapi.regex.extractTextByRegex.bind(window)('20/dec/2018', '$[0-9]{4}', null);
|
|
19
|
+
expect(result).to.be.empty;
|
|
20
|
+
|
|
21
|
+
// For sem a declaração correta da variável
|
|
22
|
+
// A Interação com o matches.length só pega a partir da segunda sequencia
|
|
23
|
+
// O retorno vem dentro de 2 Arrays sem necessidade
|
|
24
|
+
result = cronapi.regex.extractTextByRegex.bind(window)('cdbbdbsbz', 'd(b+)d', 'g');
|
|
25
|
+
expect(result).to.be.an.instanceof(Array);
|
|
26
|
+
expect(result).to.be.an('array').that.includes('bb');
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
it('validateTextWithRegex', function() {
|
|
30
|
+
let result;
|
|
31
|
+
result = cronapi.regex.validateTextWithRegex.bind(window)(null, '[0-9]', 'g');
|
|
32
|
+
expect(result).to.be.false;
|
|
33
|
+
|
|
34
|
+
result = cronapi.regex.validateTextWithRegex.bind(window)('12345', null, 'g');
|
|
35
|
+
expect(result).to.be.false;
|
|
36
|
+
|
|
37
|
+
result = cronapi.regex.validateTextWithRegex.bind(window)('Olá Cronapp', '^Ol', null);
|
|
38
|
+
expect(result).to.be.true;
|
|
39
|
+
|
|
40
|
+
result = cronapi.regex.validateTextWithRegex.bind(window)('Cronapp is the BEST low code', 'best', 'gi');
|
|
41
|
+
expect(result).to.be.true;
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
});
|