cronapi-js 2.8.33 → 2.9.1-SP.1

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/package.json CHANGED
@@ -1,10 +1,11 @@
1
1
  {
2
2
  "name": "cronapi-js",
3
- "version": "2.8.33",
3
+ "version": "2.9.1-SP.1",
4
4
  "description": "Public library for CronApp's users",
5
5
  "main": "cronapi.js",
6
6
  "scripts": {
7
- "test": "echo \"Error: no test specified\" && exit 1"
7
+ "test": "jest --coverage",
8
+ "build": "gulp"
8
9
  },
9
10
  "repository": {
10
11
  "type": "git",
@@ -22,14 +23,20 @@
22
23
  "javascript"
23
24
  ],
24
25
  "devDependencies": {
26
+ "@types/chai": "^4.2.14",
27
+ "@types/jest": "^26.0.15",
28
+ "@types/node": "^14.14.6",
29
+ "chai": "^4.2.0",
25
30
  "gulp": "^3.9.1",
26
31
  "gulp-autoprefixer": "^3.1.1",
27
32
  "gulp-babel-minify": "^0.5.0",
33
+ "gulp-cli": "2.2.0",
28
34
  "gulp-notify": "^3.0.0",
29
35
  "gulp-rename": "^1.2.2",
30
36
  "gulp-uglify": "^2.1.2",
31
37
  "gulp-util": "^3.0.8",
32
- "gulp-cli": "2.2.0",
38
+ "jest": "^26.6.3",
39
+ "jquery": "3.5.1",
33
40
  "gulp-concat": "2.6.1"
34
41
  },
35
42
  "dependencies": {
@@ -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
+ });