@legalplace/tagextractor 2.1.0 → 2.3.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/.eslintignore +2 -0
- package/.eslintrc +2 -58
- package/CHANGELOG.md +17 -0
- package/dist/index.d.ts +3 -3
- package/dist/index.js +1 -1
- package/dist/libs/Extractor.d.ts +5 -5
- package/dist/libs/Extractor.js +99 -100
- package/dist/libs/Extractor.test.d.ts +1 -0
- package/dist/libs/Extractor.test.js +274 -0
- package/dist/libs/fixtures/inputs.json +60 -0
- package/dist/libs/fixtures/model.json +291 -0
- package/dist/libs/fixtures/ovc.json +15 -0
- package/dist/libs/fixtures/references.json +946 -0
- package/jest.config.ts +205 -0
- package/package.json +25 -22
- package/setupJest.ts +8 -0
- package/src/index.ts +4 -4
- package/src/libs/Extractor.test.ts +360 -0
- package/src/libs/Extractor.ts +127 -72
- package/src/libs/fixtures/inputs.json +60 -0
- package/src/libs/fixtures/model.json +291 -0
- package/src/libs/fixtures/ovc.json +15 -0
- package/src/libs/fixtures/references.json +946 -0
- package/src/types/tags.type.ts +15 -15
- package/tsconfig.json +21 -8
- package/.gitlab-ci.yml +0 -43
- package/.prettierrc.js +0 -10
- package/tsconfig.eslint.json +0 -12
package/.eslintignore
ADDED
package/.eslintrc
CHANGED
|
@@ -1,59 +1,3 @@
|
|
|
1
1
|
{
|
|
2
|
-
"
|
|
3
|
-
|
|
4
|
-
"commonjs": true,
|
|
5
|
-
"es6": true,
|
|
6
|
-
"jest": true,
|
|
7
|
-
"node": true
|
|
8
|
-
},
|
|
9
|
-
|
|
10
|
-
"extends": [
|
|
11
|
-
"airbnb-base",
|
|
12
|
-
"plugin:prettier/recommended"
|
|
13
|
-
],
|
|
14
|
-
|
|
15
|
-
"parser": "@typescript-eslint/parser",
|
|
16
|
-
"parserOptions": {
|
|
17
|
-
"project": "./tsconfig.eslint.json"
|
|
18
|
-
},
|
|
19
|
-
|
|
20
|
-
"plugins": [
|
|
21
|
-
"prettier", "@typescript-eslint"
|
|
22
|
-
],
|
|
23
|
-
|
|
24
|
-
"rules": {
|
|
25
|
-
"prettier/prettier": ["error"],
|
|
26
|
-
"no-unused-vars": "off",
|
|
27
|
-
"@typescript-eslint/no-unused-vars": ["error", {
|
|
28
|
-
"vars": "all",
|
|
29
|
-
"args": "after-used",
|
|
30
|
-
"ignoreRestSiblings": false
|
|
31
|
-
}],
|
|
32
|
-
"import/no-extraneous-dependencies": ["error", {
|
|
33
|
-
"devDependencies": true
|
|
34
|
-
}],
|
|
35
|
-
"no-continue": 0,
|
|
36
|
-
"class-methods-use-this": 0,
|
|
37
|
-
"no-underscore-dangle": 0,
|
|
38
|
-
"import/prefer-default-export": "warn",
|
|
39
|
-
"camelcase": "error",
|
|
40
|
-
"no-undef": 0,
|
|
41
|
-
"no-dupe-class-members": "off",
|
|
42
|
-
"import/extensions": ["error", "ignorePackages", {
|
|
43
|
-
"js": "never",
|
|
44
|
-
"jsx": "never",
|
|
45
|
-
"ts": "never",
|
|
46
|
-
"tsx": "never",
|
|
47
|
-
"mjs": "never"
|
|
48
|
-
}]
|
|
49
|
-
},
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
"settings": {
|
|
53
|
-
"import/resolver": {
|
|
54
|
-
"node": {
|
|
55
|
-
"extensions": [".js", ".jsx", ".ts", ".tsx"]
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
}
|
|
2
|
+
"extends": ["@legalplace/eslint-config"]
|
|
3
|
+
}
|
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
# Change Log
|
|
2
|
+
|
|
3
|
+
All notable changes to this project will be documented in this file.
|
|
4
|
+
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
|
5
|
+
|
|
6
|
+
# 2.3.0 (2022-01-10)
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
### Bug Fixes
|
|
10
|
+
|
|
11
|
+
* fix test version api[#4631](https://git.legalplace.eu/legalplace/tagextractor/issues/4631) ([f5f15c2](https://git.legalplace.eu/legalplace/tagextractor/commits/f5f15c2e5fdd9b0d98edb822f1aeb02d3823a6ca))
|
|
12
|
+
* remove unneeded gitlab-ci file api[#4631](https://git.legalplace.eu/legalplace/tagextractor/issues/4631) ([97b8424](https://git.legalplace.eu/legalplace/tagextractor/commits/97b8424281d804720438061bec2a7c0171f79b3b))
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
### Features
|
|
16
|
+
|
|
17
|
+
* add the tagExtractor package api[#4631](https://git.legalplace.eu/legalplace/tagextractor/issues/4631) ([70c502a](https://git.legalplace.eu/legalplace/tagextractor/commits/70c502a734ea8bf1df842d4d44c89f360d96d7db))
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import TagExtractor from
|
|
2
|
-
import TagsType, { OptionTagType, VariableTagType } from
|
|
3
|
-
export { TagsType, OptionTagType, VariableTagType };
|
|
1
|
+
import TagExtractor from "./libs/Extractor";
|
|
2
|
+
import TagsType, { OptionTagType, VariableTagType } from "./types/tags.type";
|
|
3
|
+
export type { TagsType, OptionTagType, VariableTagType };
|
|
4
4
|
export default TagExtractor;
|
package/dist/index.js
CHANGED
|
@@ -3,5 +3,5 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
|
|
6
|
+
const Extractor_1 = __importDefault(require("./libs/Extractor"));
|
|
7
7
|
exports.default = Extractor_1.default;
|
package/dist/libs/Extractor.d.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { ModelV3 } from
|
|
2
|
-
import { ReferencesType } from
|
|
3
|
-
import InputsType from
|
|
4
|
-
import OvcType from
|
|
5
|
-
import TagsType from
|
|
1
|
+
import { ModelV3 } from "@legalplace/models-v3-types";
|
|
2
|
+
import { ReferencesType } from "@legalplace/referencesparser/dist/libs/References.type";
|
|
3
|
+
import type InputsType from "@legalplace/types/dist/inputs";
|
|
4
|
+
import type OvcType from "@legalplace/types/dist/ovc";
|
|
5
|
+
import TagsType from "../types/tags.type";
|
|
6
6
|
declare class TagExtractor {
|
|
7
7
|
private references;
|
|
8
8
|
private inputs;
|
package/dist/libs/Extractor.js
CHANGED
|
@@ -1,130 +1,129 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __spreadArrays = (this && this.__spreadArrays) || function () {
|
|
3
|
-
for (var s = 0, i = 0, il = arguments.length; i < il; i++) s += arguments[i].length;
|
|
4
|
-
for (var r = Array(s), k = 0, i = 0; i < il; i++)
|
|
5
|
-
for (var a = arguments[i], j = 0, jl = a.length; j < jl; j++, k++)
|
|
6
|
-
r[k] = a[j];
|
|
7
|
-
return r;
|
|
8
|
-
};
|
|
9
2
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
10
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
11
4
|
};
|
|
12
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
6
|
+
const referencesparser_1 = require("@legalplace/referencesparser");
|
|
7
|
+
const conditions_runner_1 = __importDefault(require("@legalplace/conditions-runner"));
|
|
8
|
+
const ovc_converter_1 = __importDefault(require("@legalplace/ovc-converter"));
|
|
9
|
+
class TagExtractor {
|
|
10
|
+
constructor(modelOrReferences, ovc) {
|
|
18
11
|
this.tags = {
|
|
19
12
|
options: {},
|
|
20
|
-
variables: {}
|
|
21
|
-
};
|
|
22
|
-
this.isReferencesType = function (_obj) {
|
|
23
|
-
return Object.keys(_obj).some(function (key) { return key === 'boxes'; });
|
|
13
|
+
variables: {},
|
|
24
14
|
};
|
|
25
|
-
this.
|
|
26
|
-
this.
|
|
15
|
+
this.isReferencesType = (_obj) => Object.keys(_obj).some((key) => key === "boxes");
|
|
16
|
+
this.references = this.isReferencesType(modelOrReferences)
|
|
17
|
+
? modelOrReferences
|
|
18
|
+
: new referencesparser_1.ReferencesParser(modelOrReferences).references;
|
|
19
|
+
this.inputs = ovc_converter_1.default.isOptionsVariables(ovc)
|
|
20
|
+
? ovc
|
|
21
|
+
: ovc_converter_1.default.convertToOptionsVariables(ovc, this.references);
|
|
27
22
|
this.conditionsRunner = new conditions_runner_1.default(this.references, this.inputs);
|
|
28
23
|
this.extractFromOptions();
|
|
29
24
|
this.extractFromVariables();
|
|
30
25
|
}
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
_this.inputs.options[id].forEach(function (v, index) {
|
|
44
|
-
tags.forEach(function (tag) {
|
|
45
|
-
if (_this.tags.options[tag] === undefined)
|
|
46
|
-
_this.tags.options[tag] = [];
|
|
47
|
-
_this.tags.options[tag].push({
|
|
26
|
+
get getTags() {
|
|
27
|
+
return this.tags;
|
|
28
|
+
}
|
|
29
|
+
extractFromOptions() {
|
|
30
|
+
Object.keys(this.references.options).forEach((id) => {
|
|
31
|
+
const { tags, label } = this.references.options[id].meta;
|
|
32
|
+
if (Array.isArray(tags) && tags.length > 0 && this.inputs.options[id]) {
|
|
33
|
+
this.inputs.options[id].forEach((v, index) => {
|
|
34
|
+
tags.forEach((tag) => {
|
|
35
|
+
if (this.tags.options[tag] === undefined)
|
|
36
|
+
this.tags.options[tag] = [];
|
|
37
|
+
this.tags.options[tag].push({
|
|
48
38
|
id: parseInt(id, 10),
|
|
49
|
-
index
|
|
50
|
-
label
|
|
51
|
-
condition:
|
|
52
|
-
visible:
|
|
53
|
-
value:
|
|
39
|
+
index,
|
|
40
|
+
label,
|
|
41
|
+
condition: this.getOptionCondition(parseInt(id, 10), index),
|
|
42
|
+
visible: this.isOptionDisplayed(parseInt(id, 10), index),
|
|
43
|
+
value: this.inputs.options[id][index],
|
|
54
44
|
});
|
|
55
45
|
});
|
|
56
46
|
});
|
|
57
47
|
}
|
|
58
48
|
});
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
_this.tags.variables[tag].push({
|
|
49
|
+
}
|
|
50
|
+
extractFromVariables() {
|
|
51
|
+
Object.keys(this.references.variables).forEach((id) => {
|
|
52
|
+
const { tags, label } = this.references.variables[id];
|
|
53
|
+
if (Array.isArray(tags) && tags.length > 0 && this.inputs.variables[id]) {
|
|
54
|
+
this.inputs.variables[id].forEach((v, index) => {
|
|
55
|
+
tags.forEach((tag) => {
|
|
56
|
+
if (this.tags.variables[tag] === undefined)
|
|
57
|
+
this.tags.variables[tag] = [];
|
|
58
|
+
this.tags.variables[tag].push({
|
|
70
59
|
id: parseInt(id, 10),
|
|
71
|
-
index
|
|
72
|
-
label
|
|
73
|
-
condition:
|
|
74
|
-
visible:
|
|
75
|
-
value:
|
|
60
|
+
index,
|
|
61
|
+
label,
|
|
62
|
+
condition: this.getVariableCondition(parseInt(id, 10), index) !== false,
|
|
63
|
+
visible: this.isVariableDisplayed(parseInt(id, 10), index),
|
|
64
|
+
value: this.inputs.variables[id][index],
|
|
76
65
|
});
|
|
77
66
|
});
|
|
78
67
|
});
|
|
79
68
|
}
|
|
80
69
|
});
|
|
81
|
-
}
|
|
82
|
-
|
|
70
|
+
}
|
|
71
|
+
isVariableDisplayed(id, index) {
|
|
83
72
|
var _a, _b;
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
return [
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
73
|
+
const variableCondition = this.getVariableCondition(id, index);
|
|
74
|
+
const variableParents = ((_a = this.references.relations.variables[id]) === null || _a === void 0 ? void 0 : _a.parents) || [];
|
|
75
|
+
const parentOptionIsDisplayed = this.isOptionDisplayed(variableParents[0], index);
|
|
76
|
+
const parentOptionIsTruethful = ((_b = this.inputs.options[variableParents[0]]) === null || _b === void 0 ? void 0 : _b[index]) === true;
|
|
77
|
+
return ([
|
|
78
|
+
variableCondition,
|
|
79
|
+
parentOptionIsDisplayed,
|
|
80
|
+
parentOptionIsTruethful,
|
|
81
|
+
].filter((c) => c !== true).length === 0);
|
|
82
|
+
}
|
|
83
|
+
isOptionDisplayed(id, index) {
|
|
92
84
|
var _a;
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
return conditionObject === undefined
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
85
|
+
const optionCondition = this.getOptionCondition(id, index);
|
|
86
|
+
const optionParents = ((_a = this.references.relations.options[id]) === null || _a === void 0 ? void 0 : _a.parents) || [];
|
|
87
|
+
const parentsConditions = optionParents.map((optionId) => this.getOptionCondition(optionId, index) !== false);
|
|
88
|
+
const parentsInputs = optionParents.map((optionId) => this.inputs.options[optionId]
|
|
89
|
+
? this.inputs.options[optionId][index]
|
|
90
|
+
: false);
|
|
91
|
+
const parentSectionId = this.getOptionParentSection(id);
|
|
92
|
+
const parentSectionCondition = this.getSectionCondition(parentSectionId) !== false;
|
|
93
|
+
return ([
|
|
94
|
+
optionCondition,
|
|
95
|
+
parentSectionCondition,
|
|
96
|
+
...parentsConditions,
|
|
97
|
+
...parentsInputs,
|
|
98
|
+
].filter((c) => c !== true).length === 0);
|
|
99
|
+
}
|
|
100
|
+
getVariableCondition(id, index) {
|
|
101
|
+
const conditionObject = this.references.conditions.variables[id];
|
|
102
|
+
return conditionObject === undefined
|
|
103
|
+
? true
|
|
104
|
+
: this.conditionsRunner.executeCondition(conditionObject, id, index, "variables");
|
|
105
|
+
}
|
|
106
|
+
getOptionCondition(id, index) {
|
|
107
|
+
const conditionObject = this.references.conditions.options[id];
|
|
108
|
+
return conditionObject === undefined
|
|
109
|
+
? true
|
|
110
|
+
: this.conditionsRunner.executeCondition(conditionObject, id, index, "options");
|
|
111
|
+
}
|
|
112
|
+
getSectionCondition(id) {
|
|
113
|
+
const conditionObject = this.references.conditions.sections.main[id];
|
|
114
|
+
return conditionObject === undefined
|
|
115
|
+
? true
|
|
116
|
+
: this.conditionsRunner.executeCondition(conditionObject, id, 0, "sections");
|
|
117
|
+
}
|
|
118
|
+
getOptionParentSection(id) {
|
|
119
|
+
const { parents } = this.references.relations.options[id];
|
|
120
|
+
const rootId = parents.length > 0 ? parents[parents.length - 1] : id;
|
|
121
|
+
const sections = Object.values(this.references.sections.main);
|
|
122
|
+
for (let i = 0; i < sections.length; i += 1) {
|
|
123
123
|
if (sections[i].options.includes(rootId))
|
|
124
124
|
return sections[i].id;
|
|
125
125
|
}
|
|
126
|
-
throw new Error(
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
}());
|
|
126
|
+
throw new Error(`Cannot find parent section for option ${id} (Root option id: ${rootId})`);
|
|
127
|
+
}
|
|
128
|
+
}
|
|
130
129
|
exports.default = TagExtractor;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,274 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const Extractor_1 = __importDefault(require("./Extractor"));
|
|
7
|
+
const ovc_json_1 = __importDefault(require("./fixtures/ovc.json"));
|
|
8
|
+
const inputs_json_1 = __importDefault(require("./fixtures/inputs.json"));
|
|
9
|
+
const references_json_1 = __importDefault(require("./fixtures/references.json"));
|
|
10
|
+
const model_json_1 = __importDefault(require("./fixtures/model.json"));
|
|
11
|
+
const simpleReferences = references_json_1.default;
|
|
12
|
+
const simpleModel = model_json_1.default;
|
|
13
|
+
const simpleOvc = ovc_json_1.default;
|
|
14
|
+
const simpleInputs = inputs_json_1.default;
|
|
15
|
+
describe("TagsExtractor", () => {
|
|
16
|
+
const tagExtractor = new Extractor_1.default(simpleReferences, simpleInputs);
|
|
17
|
+
afterEach(() => {
|
|
18
|
+
jest.clearAllMocks();
|
|
19
|
+
jest.restoreAllMocks();
|
|
20
|
+
});
|
|
21
|
+
describe("IsVariableDisplayed", () => {
|
|
22
|
+
it("should return false when variable condition is false", () => {
|
|
23
|
+
const getVariableCondition = jest.spyOn(Extractor_1.default.prototype, "getVariableCondition");
|
|
24
|
+
getVariableCondition.mockImplementation(() => false);
|
|
25
|
+
expect(tagExtractor.isVariableDisplayed(1, 0)).toBeFalsy();
|
|
26
|
+
expect(getVariableCondition).toHaveBeenCalledWith(1, 0);
|
|
27
|
+
});
|
|
28
|
+
it("should return false when parent Option is not displayed", () => {
|
|
29
|
+
const isOptionDisplayed = jest.spyOn(Extractor_1.default.prototype, "isOptionDisplayed");
|
|
30
|
+
isOptionDisplayed.mockImplementation(() => false);
|
|
31
|
+
expect(tagExtractor.isVariableDisplayed(1, 0)).toBeFalsy();
|
|
32
|
+
expect(isOptionDisplayed).toHaveBeenCalledWith(6, 0);
|
|
33
|
+
});
|
|
34
|
+
it("should return false when parent Option is not truthful", () => {
|
|
35
|
+
const inputsWithParentsFalse = {
|
|
36
|
+
...simpleInputs,
|
|
37
|
+
options: { ...simpleInputs.options, "6": [false] },
|
|
38
|
+
};
|
|
39
|
+
const customTagExtractor = new Extractor_1.default(simpleReferences, inputsWithParentsFalse);
|
|
40
|
+
expect(customTagExtractor.isVariableDisplayed(1, 0)).toBeFalsy();
|
|
41
|
+
});
|
|
42
|
+
it("should return true when all checks are okay", () => {
|
|
43
|
+
const inputsWithAllChecks = {
|
|
44
|
+
...simpleInputs,
|
|
45
|
+
options: { ...simpleInputs.options, "8": [true] },
|
|
46
|
+
};
|
|
47
|
+
const customTagExtractor = new Extractor_1.default(simpleReferences, inputsWithAllChecks);
|
|
48
|
+
expect(customTagExtractor.isVariableDisplayed(1, 0)).toBeTruthy();
|
|
49
|
+
});
|
|
50
|
+
});
|
|
51
|
+
describe("IsOptionDisplayed", () => {
|
|
52
|
+
it("should return false when option condition is false", () => {
|
|
53
|
+
const getOptionCondition = jest.spyOn(Extractor_1.default.prototype, "getOptionCondition");
|
|
54
|
+
getOptionCondition.mockImplementation((id, index) => !(id === 24 && index === 0));
|
|
55
|
+
expect(tagExtractor.isOptionDisplayed(24, 0)).toBeFalsy();
|
|
56
|
+
expect(getOptionCondition).toHaveBeenCalledWith(24, 0);
|
|
57
|
+
});
|
|
58
|
+
it("should return false when parentSectionCondition is false", () => {
|
|
59
|
+
const getSectionCondition = jest.spyOn(Extractor_1.default.prototype, "getSectionCondition");
|
|
60
|
+
getSectionCondition.mockImplementation(() => false);
|
|
61
|
+
expect(tagExtractor.isOptionDisplayed(24, 0)).toBeFalsy();
|
|
62
|
+
expect(getSectionCondition).toHaveBeenCalledWith(1);
|
|
63
|
+
});
|
|
64
|
+
it("should return false when parentCondition contains false value", () => {
|
|
65
|
+
const getOptionCondition = jest.spyOn(Extractor_1.default.prototype, "getOptionCondition");
|
|
66
|
+
getOptionCondition.mockImplementation((id, index) => !(id === 6 && index === 0));
|
|
67
|
+
expect(tagExtractor.isOptionDisplayed(24, 0)).toBeFalsy();
|
|
68
|
+
expect(getOptionCondition).toHaveBeenCalledWith(24, 0);
|
|
69
|
+
});
|
|
70
|
+
it("should return false when parentsInputs list contains false value", () => {
|
|
71
|
+
const inputsWithParentsInputsFalse = {
|
|
72
|
+
...simpleInputs,
|
|
73
|
+
options: { ...simpleInputs.options, "6": [false] },
|
|
74
|
+
};
|
|
75
|
+
const customTagExtractor = new Extractor_1.default(simpleReferences, inputsWithParentsInputsFalse);
|
|
76
|
+
expect(customTagExtractor.isOptionDisplayed(24, 0)).toBeFalsy();
|
|
77
|
+
});
|
|
78
|
+
it("should not return errors when parentsInputs is undefined", () => {
|
|
79
|
+
const inputsWithParentsInputsUndefined = {
|
|
80
|
+
...simpleInputs,
|
|
81
|
+
options: { ...simpleInputs.options },
|
|
82
|
+
};
|
|
83
|
+
delete inputsWithParentsInputsUndefined.options["6"];
|
|
84
|
+
const customTagExtractor = new Extractor_1.default(simpleReferences, inputsWithParentsInputsUndefined);
|
|
85
|
+
expect(customTagExtractor.isOptionDisplayed(24, 0)).toBeFalsy();
|
|
86
|
+
});
|
|
87
|
+
it("should return true when all checks are okay", () => {
|
|
88
|
+
expect(tagExtractor.isOptionDisplayed(24, 0)).toBeTruthy();
|
|
89
|
+
});
|
|
90
|
+
});
|
|
91
|
+
describe("convertToOptionVariables", () => {
|
|
92
|
+
it("should tag extraction match when instanciating TagExtractor with ovc or inputs", () => {
|
|
93
|
+
const customTagExtractor = new Extractor_1.default(simpleReferences, simpleOvc);
|
|
94
|
+
const expectedTags = new Extractor_1.default(simpleReferences, simpleInputs)
|
|
95
|
+
.getTags;
|
|
96
|
+
expect(customTagExtractor.getTags).toMatchObject(expectedTags);
|
|
97
|
+
});
|
|
98
|
+
});
|
|
99
|
+
describe("ReferenceParser", () => {
|
|
100
|
+
it("should tag extraction match when instanciating TagExtractor with model or references", () => {
|
|
101
|
+
const customTagExtractor = new Extractor_1.default(simpleModel, simpleInputs);
|
|
102
|
+
const expectedTags = new Extractor_1.default(simpleReferences, simpleInputs)
|
|
103
|
+
.getTags;
|
|
104
|
+
expect(customTagExtractor.getTags).toMatchObject(expectedTags);
|
|
105
|
+
});
|
|
106
|
+
});
|
|
107
|
+
describe("extractFromOptions", () => {
|
|
108
|
+
it("should return empty tag object when tags are undefined", () => {
|
|
109
|
+
const referencesWithoutOptionTagArray = {
|
|
110
|
+
...simpleReferences,
|
|
111
|
+
options: {
|
|
112
|
+
...simpleReferences.options,
|
|
113
|
+
"7": {
|
|
114
|
+
...simpleReferences.options["7"],
|
|
115
|
+
meta: { ...simpleReferences.options["7"].meta, tags: undefined },
|
|
116
|
+
},
|
|
117
|
+
},
|
|
118
|
+
};
|
|
119
|
+
const customTagExtractor = new Extractor_1.default(referencesWithoutOptionTagArray, simpleInputs);
|
|
120
|
+
expect(customTagExtractor.getTags.options).toMatchObject({});
|
|
121
|
+
});
|
|
122
|
+
it("should return empty tag object when options tags are empty", () => {
|
|
123
|
+
const referencesWithoutOptionTags = {
|
|
124
|
+
...simpleReferences,
|
|
125
|
+
options: {
|
|
126
|
+
...simpleReferences.options,
|
|
127
|
+
"7": {
|
|
128
|
+
...simpleReferences.options["7"],
|
|
129
|
+
meta: { ...simpleReferences.options["7"].meta, tags: [] },
|
|
130
|
+
},
|
|
131
|
+
},
|
|
132
|
+
};
|
|
133
|
+
const customTagExtractor = new Extractor_1.default(referencesWithoutOptionTags, simpleInputs);
|
|
134
|
+
expect(customTagExtractor.getTags.options).toMatchObject({});
|
|
135
|
+
});
|
|
136
|
+
it("should return empty tags when input's option is undefined", () => {
|
|
137
|
+
const inputsWithoutOptionTaggedAnswer = {
|
|
138
|
+
...simpleInputs,
|
|
139
|
+
options: { ...simpleInputs.options },
|
|
140
|
+
};
|
|
141
|
+
delete inputsWithoutOptionTaggedAnswer.options["7"];
|
|
142
|
+
const customTagExtractor = new Extractor_1.default(simpleReferences, inputsWithoutOptionTaggedAnswer);
|
|
143
|
+
expect(customTagExtractor.getTags.options).toMatchObject({});
|
|
144
|
+
});
|
|
145
|
+
it("should return option tag when champ multiples", () => {
|
|
146
|
+
const inputWithChampMultiple = {
|
|
147
|
+
...simpleInputs,
|
|
148
|
+
options: { ...simpleInputs.options, "7": [true, false] },
|
|
149
|
+
};
|
|
150
|
+
const customTagExtractor = new Extractor_1.default(simpleReferences, inputWithChampMultiple);
|
|
151
|
+
const expectedOptionTags = {
|
|
152
|
+
LP_fan: [
|
|
153
|
+
{
|
|
154
|
+
id: 7,
|
|
155
|
+
index: 0,
|
|
156
|
+
label: "Connaissiez-vous déjà LegalPlace ?",
|
|
157
|
+
condition: true,
|
|
158
|
+
visible: true,
|
|
159
|
+
value: true,
|
|
160
|
+
},
|
|
161
|
+
{
|
|
162
|
+
id: 7,
|
|
163
|
+
index: 1,
|
|
164
|
+
label: "Connaissiez-vous déjà LegalPlace ?",
|
|
165
|
+
condition: true,
|
|
166
|
+
visible: true,
|
|
167
|
+
value: false,
|
|
168
|
+
},
|
|
169
|
+
],
|
|
170
|
+
};
|
|
171
|
+
expect(customTagExtractor.getTags.options).toMatchObject(expectedOptionTags);
|
|
172
|
+
});
|
|
173
|
+
it("should return option tags", () => {
|
|
174
|
+
const expectedOptionTags = {
|
|
175
|
+
LP_fan: [
|
|
176
|
+
{
|
|
177
|
+
id: 7,
|
|
178
|
+
index: 0,
|
|
179
|
+
label: "Connaissiez-vous déjà LegalPlace ?",
|
|
180
|
+
condition: true,
|
|
181
|
+
visible: true,
|
|
182
|
+
value: true,
|
|
183
|
+
},
|
|
184
|
+
],
|
|
185
|
+
};
|
|
186
|
+
expect(tagExtractor.getTags.options).toMatchObject(expectedOptionTags);
|
|
187
|
+
});
|
|
188
|
+
});
|
|
189
|
+
describe("extractFromVariables", () => {
|
|
190
|
+
it("should return empty tag object when tags are undefined", () => {
|
|
191
|
+
const referenceWithoutVariableTagArray = {
|
|
192
|
+
...simpleReferences,
|
|
193
|
+
variables: {
|
|
194
|
+
...simpleReferences.variables,
|
|
195
|
+
"1": { ...simpleReferences.variables["1"], tags: undefined },
|
|
196
|
+
},
|
|
197
|
+
};
|
|
198
|
+
const customTagExtractor = new Extractor_1.default(referenceWithoutVariableTagArray, simpleInputs);
|
|
199
|
+
expect(customTagExtractor.getTags.variables).toMatchObject({});
|
|
200
|
+
});
|
|
201
|
+
it("should return empty tag object when variables tags are empty", () => {
|
|
202
|
+
const referenceWithoutTags = {
|
|
203
|
+
...simpleReferences,
|
|
204
|
+
variables: {
|
|
205
|
+
...simpleReferences.variables,
|
|
206
|
+
"1": { ...simpleReferences.variables["1"], tags: [] },
|
|
207
|
+
},
|
|
208
|
+
};
|
|
209
|
+
const customTagExtractor = new Extractor_1.default(referenceWithoutTags, simpleInputs);
|
|
210
|
+
expect(customTagExtractor.getTags.variables).toMatchObject({});
|
|
211
|
+
});
|
|
212
|
+
it("should return empty tags when input's variable is undefined", () => {
|
|
213
|
+
const inputsWithoutVariableTaggedAnswer = {
|
|
214
|
+
...simpleInputs,
|
|
215
|
+
variables: { ...simpleInputs.variables },
|
|
216
|
+
};
|
|
217
|
+
delete inputsWithoutVariableTaggedAnswer.variables[1];
|
|
218
|
+
const customTagExtractor = new Extractor_1.default(simpleReferences, inputsWithoutVariableTaggedAnswer);
|
|
219
|
+
expect(customTagExtractor.getTags.variables).toMatchObject({});
|
|
220
|
+
});
|
|
221
|
+
it("should not throw error when input's variable does not match any references variable", () => {
|
|
222
|
+
const referenceWithoutMatchingVariable = {
|
|
223
|
+
...simpleReferences,
|
|
224
|
+
variables: { ...simpleReferences.variables },
|
|
225
|
+
};
|
|
226
|
+
delete referenceWithoutMatchingVariable.variables["2"];
|
|
227
|
+
const customTagExtractor = new Extractor_1.default(referenceWithoutMatchingVariable, simpleInputs);
|
|
228
|
+
const expectedVariableTags = {
|
|
229
|
+
Company_name: [
|
|
230
|
+
{
|
|
231
|
+
id: 1,
|
|
232
|
+
index: 0,
|
|
233
|
+
label: "Nom de l'entreprise",
|
|
234
|
+
condition: false,
|
|
235
|
+
visible: false,
|
|
236
|
+
value: "Company",
|
|
237
|
+
},
|
|
238
|
+
],
|
|
239
|
+
};
|
|
240
|
+
expect(customTagExtractor.getTags.variables).toMatchObject(expectedVariableTags);
|
|
241
|
+
});
|
|
242
|
+
it("should return variable tag when champ multiples", () => {
|
|
243
|
+
const inputVariableWithChampMultiple = {
|
|
244
|
+
...simpleInputs,
|
|
245
|
+
variables: {
|
|
246
|
+
...simpleInputs.variables,
|
|
247
|
+
"1": ["Nom de la companie", "Testing Company"],
|
|
248
|
+
},
|
|
249
|
+
};
|
|
250
|
+
const customTagExtractor = new Extractor_1.default(simpleReferences, inputVariableWithChampMultiple);
|
|
251
|
+
const expectedVariableTags = {
|
|
252
|
+
Company_name: [
|
|
253
|
+
{
|
|
254
|
+
id: 1,
|
|
255
|
+
index: 0,
|
|
256
|
+
label: "Nom de l'entreprise",
|
|
257
|
+
condition: false,
|
|
258
|
+
visible: false,
|
|
259
|
+
value: "Nom de la companie",
|
|
260
|
+
},
|
|
261
|
+
{
|
|
262
|
+
id: 1,
|
|
263
|
+
index: 1,
|
|
264
|
+
label: "Nom de l'entreprise",
|
|
265
|
+
condition: false,
|
|
266
|
+
visible: false,
|
|
267
|
+
value: "Testing Company",
|
|
268
|
+
},
|
|
269
|
+
],
|
|
270
|
+
};
|
|
271
|
+
expect(customTagExtractor.getTags.variables).toMatchObject(expectedVariableTags);
|
|
272
|
+
});
|
|
273
|
+
});
|
|
274
|
+
});
|