@media-quest/builder 0.0.2 → 0.0.4

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.
Files changed (27) hide show
  1. package/dist/public-api.d.mts +35 -11
  2. package/dist/public-api.d.ts +35 -11
  3. package/dist/public-api.js +455 -47
  4. package/dist/public-api.mjs +427 -37
  5. package/package.json +3 -4
  6. package/src/Builder-option.ts +51 -52
  7. package/src/Builder-schema.ts +1 -0
  8. package/src/public-api.ts +3 -0
  9. package/src/rulebuilder/Builder-rule.spec.ts +266 -182
  10. package/src/rulebuilder/Builder-rule.ts +106 -67
  11. package/src/rulebuilder/Rule2.ts +87 -0
  12. package/src/rulebuilder/RuleBuilder-test-utils.ts +250 -239
  13. package/src/rulebuilder/RuleVariable.ts +13 -9
  14. package/src/rulebuilder/SingleSelectItem.ts +118 -118
  15. package/src/rulebuilder/{Builder-condition-group.ts → condition/Builder-condition-group.ts} +42 -33
  16. package/src/rulebuilder/condition/Builder-condition.spec.ts +185 -0
  17. package/src/rulebuilder/condition/Builder-condition.ts +208 -0
  18. package/src/rulebuilder/index.ts +11 -11
  19. package/src/rulebuilder/jump-to-action-manager.ts +26 -26
  20. package/src/rulebuilder/page-action-manager.ts +23 -13
  21. package/src/rulebuilder/tag-action-manager.ts +23 -13
  22. package/src/theme/default-theme-compiler.ts +26 -1
  23. package/src/rulebuilder/Builder-condition.spec.ts +0 -169
  24. package/src/rulebuilder/Builder-condition.ts +0 -186
  25. /package/src/rulebuilder/{Builder-condition-group.spec.ts → condition/Builder-condition-group.spec.ts} +0 -0
  26. /package/src/rulebuilder/{Builder-operator.spec.ts → condition/Builder-operator.spec.ts} +0 -0
  27. /package/src/rulebuilder/{Builder-operator.ts → condition/Builder-operator.ts} +0 -0
@@ -4,64 +4,63 @@ import { DefaultTheme } from "./theme/IDefaultTheme";
4
4
  import { AudioFile } from "./media-files";
5
5
 
6
6
  export interface BuilderOptionDto {
7
- readonly id: BuilderObjectId.QuestionOptionID;
8
- readonly value: number;
9
- readonly label: string;
10
- readonly labelAudio?: AudioFile;
11
- // readonly theme: BuilderPageTheme['nextButtonTheme'];
7
+ readonly id: BuilderObjectId.QuestionOptionID;
8
+ readonly value: number;
9
+ readonly label: string;
10
+ readonly labelAudio?: AudioFile;
12
11
  }
13
12
 
14
13
  export class BuilderOption extends BuilderObject<"builder-question-option", BuilderOptionDto> {
15
- readonly objectType = "builder-question-option";
16
- theme: BuilderOptionTheme = DefaultTheme.responseButtons;
14
+ readonly objectType = "builder-question-option";
15
+ theme: BuilderOptionTheme = DefaultTheme.responseButtons;
17
16
 
18
- id: BuilderObjectId.QuestionOptionID;
19
- value: number;
20
- label = "";
21
- private _labelAudioFile: AudioFile | false = false;
22
- get labelAudioFile() {
23
- return this._labelAudioFile;
24
- }
25
- set labelAudioFile(audioFile: AudioFile | false) {
26
- this._labelAudioFile = audioFile;
27
- }
17
+ id: BuilderObjectId.QuestionOptionID;
18
+ value: number;
19
+ label = "";
20
+ private _labelAudioFile: AudioFile | false = false;
21
+ get labelAudioFile() {
22
+ return this._labelAudioFile;
23
+ }
24
+ set labelAudioFile(audioFile: AudioFile | false) {
25
+ this._labelAudioFile = audioFile;
26
+ }
28
27
 
29
- private constructor(dto: BuilderOptionDto) {
30
- super(dto);
31
- this.id = dto.id;
32
- this.value = dto.value;
33
- this.label = dto.label;
34
- // this.theme = dto.theme;
35
- }
36
- public static create(value: number, label: string) {
37
- const id = BuilderObjectId.questionOptionId();
38
- const dto: BuilderOptionDto = {
39
- id,
40
- value,
41
- label,
42
- };
43
- const instance = new BuilderOption(dto);
44
- return instance;
45
- }
28
+ private constructor(dto: BuilderOptionDto) {
29
+ super(dto);
30
+ this.id = dto.id;
31
+ this.value = dto.value;
32
+ this.label = dto.label;
33
+ // this.theme = dto.theme;
34
+ }
35
+ public static create(value: number, label: string) {
36
+ const id = BuilderObjectId.questionOptionId();
37
+ const dto: BuilderOptionDto = {
38
+ id,
39
+ value,
40
+ label,
41
+ };
42
+ const instance = new BuilderOption(dto);
43
+ return instance;
44
+ }
46
45
 
47
- public static fromJson(dto: BuilderOptionDto) {
48
- const instance = new BuilderOption(dto);
49
- return instance;
50
- }
46
+ public static fromJson(dto: BuilderOptionDto) {
47
+ const instance = new BuilderOption(dto);
48
+ return instance;
49
+ }
51
50
 
52
- toJson(): BuilderOptionDto {
53
- const dto: BuilderOptionDto = {
54
- id: this.id,
55
- value: this.value,
56
- label: this.label,
57
- };
58
- return dto;
59
- }
51
+ toJson(): BuilderOptionDto {
52
+ const dto: BuilderOptionDto = {
53
+ id: this.id,
54
+ value: this.value,
55
+ label: this.label,
56
+ };
57
+ return dto;
58
+ }
60
59
 
61
- clone(): BuilderOptionDto {
62
- const cloneId = BuilderObjectId.questionOptionId();
63
- const dto = this.toJson();
64
- const cloneDto: BuilderOptionDto = { ...dto, id: cloneId };
65
- return cloneDto;
66
- }
60
+ clone(): BuilderOptionDto {
61
+ const cloneId = BuilderObjectId.questionOptionId();
62
+ const dto = this.toJson();
63
+ const cloneDto: BuilderOptionDto = { ...dto, id: cloneId };
64
+ return cloneDto;
65
+ }
67
66
  }
@@ -135,6 +135,7 @@ export class BuilderSchema {
135
135
  input,
136
136
  );
137
137
  this._rules.push(rule);
138
+ return rule;
138
139
  }
139
140
  deleteRule(rule: BuilderRule) {
140
141
  this._rules = this._rules.filter((r) => r !== rule);
package/src/public-api.ts CHANGED
@@ -8,3 +8,6 @@ export { BuilderMainText, type BuilderMainTextDto } from "./BuilderMainText";
8
8
  export { type BuilderMainVideoDto } from "./BuilderMainVideoDto";
9
9
  export { type BuilderTagDto, BuilderTag, TagCollection } from "./BuilderTag";
10
10
  export { type AudioFile, type ImageFile, type VideoFile } from "./media-files";
11
+
12
+ // Public Api of rule-builder
13
+ export * from "./rulebuilder";
@@ -1,207 +1,291 @@
1
1
  import { BuilderRule, type BuilderRuleDto } from "./Builder-rule";
2
2
  import { RuleBuilderTestUtils as U } from "./RuleBuilder-test-utils";
3
3
  import { RuleInput } from "./RuleInput";
4
- import type { BuilderConditionGroupDto } from "./Builder-condition-group";
4
+ import type { BuilderConditionGroupDto } from "./condition/Builder-condition-group";
5
+ import { BuilderConditionDto } from "./condition/Builder-condition";
6
+ import { Condition } from "@media-quest/engine";
5
7
 
6
8
  const { createBuilderVariables_A_H } = U;
7
9
  let questionVariables = createBuilderVariables_A_H();
8
10
  const createDto = (): {
9
- ruleInput: RuleInput;
10
- builderRuleDto: BuilderRuleDto;
11
+ ruleInput: RuleInput;
12
+ builderRuleDto: BuilderRuleDto;
11
13
  } => {
12
- const v1 = U.createRuleVariable("v1", 2);
13
- const v2 = U.createRuleVariable("v2", 2);
14
- const v3 = U.createRuleVariable("v3", 2);
15
- const v4 = U.createRuleVariable("v4", 2);
16
- const vg1 = U.createRuleVariable("vg1", 2);
17
- const vg2 = U.createRuleVariable("vg2", 2);
18
- const vg3 = U.createRuleVariable("vg3", 2);
19
- const vg4 = U.createRuleVariable("vg4", 2);
20
- const variableList = [v1, v2, v3, v4, vg1, vg2, vg3, vg4];
21
- const tagAction1 = U.excludeByTagAction("tag1");
22
- const tagAction2 = U.excludeByTagAction("tag2");
23
- const tagAction3 = U.excludeByTagAction("tag3");
24
- const tagAction4 = U.excludeByTagAction("tag4");
25
- const pageAction1 = U.excludeByPageIdAction(v1.varId);
26
- const pageAction2 = U.excludeByPageIdAction(v2.varId);
27
- const pageAction3 = U.excludeByPageIdAction(v3.varId);
28
- const pageAction4 = U.excludeByPageIdAction(v4.varId);
29
-
30
- // const pageAction =
31
- // const excludeByTagList = [];
32
- const ruleInput = new RuleInput(
33
- variableList,
34
- [],
35
- [pageAction1, pageAction2, pageAction3, pageAction4],
36
- [tagAction1, tagAction2, tagAction3, tagAction4],
37
- []
38
- );
39
- const c1 = U.createConditionDto(v1);
40
- const c2 = U.createConditionDto(v2);
41
- const c3 = U.createConditionDto(v3);
42
- const c4 = U.createConditionDto(v4);
43
- const cg1 = U.createConditionDto(vg1);
44
- const cg2 = U.createConditionDto(vg2);
45
- const cg3 = U.createConditionDto(vg3);
46
- const cg4 = U.createConditionDto(vg4);
47
- const group3: BuilderConditionGroupDto = {
48
- kind: "condition-group",
49
- name: "group3",
50
- type: "all",
51
- conditions: [cg1, cg2, cg3, cg4],
52
- };
14
+ const v1 = U.createRuleVariable("v1", 1);
15
+ const v2 = U.createRuleVariable("v2", 2);
16
+ const v3 = U.createRuleVariable("v3", 3);
17
+ const v4 = U.createRuleVariable("v4", 4);
18
+ const vg1 = U.createRuleVariable("vg1", 5);
19
+ const vg2 = U.createRuleVariable("vg2", 6);
20
+ const vg3 = U.createRuleVariable("vg3", 7);
21
+ const vg4 = U.createRuleVariable("vg4", 8);
22
+ const variableList = [v1, v2, v3, v4, vg1, vg2, vg3, vg4];
23
+ const tagAction1 = U.excludeByTagAction("tag1");
24
+ const tagAction2 = U.excludeByTagAction("tag2");
25
+ const tagAction3 = U.excludeByTagAction("tag3");
26
+ const tagAction4 = U.excludeByTagAction("tag4");
27
+ const pageAction1 = U.excludeByPageIdAction(v1.varId, v1.pageNumber);
28
+ const pageAction2 = U.excludeByPageIdAction(v2.varId, v2.pageNumber);
29
+ const pageAction3 = U.excludeByPageIdAction(v3.varId, v3.pageNumber);
30
+ const pageAction4 = U.excludeByPageIdAction(v4.varId, v4.pageNumber);
31
+ const jumpToPageAction1 = U.jumpToPageAction(v1.varId, v1.pageNumber);
32
+ const jumpToPageAction2 = U.jumpToPageAction(v2.varId, v2.pageNumber);
33
+ const jumpToPageAction3 = U.jumpToPageAction(v3.varId, v3.pageNumber);
34
+ const jumpToPageAction4 = U.jumpToPageAction(v4.varId, v1.pageNumber);
53
35
 
54
- const builderRuleDto1: BuilderRuleDto = {
55
- type: "any",
56
- jumpToPage: false,
57
- excludePages: [v1.varId, v3.varId],
58
- excludeTags: [tagAction1.tag, tagAction2.tag],
59
- name: "kitchen-sink",
60
- conditions: [c1, c2, group3, c3, c4],
61
- };
36
+ // const pageAction =
37
+ // const excludeByTagList = [];
38
+ const ruleInput = new RuleInput(
39
+ variableList,
40
+ [],
41
+ [pageAction1, pageAction2, pageAction3, pageAction4],
42
+ [tagAction1, tagAction2, tagAction3, tagAction4],
43
+ [jumpToPageAction1, jumpToPageAction2, jumpToPageAction3, jumpToPageAction4],
44
+ );
45
+ const c1 = U.createConditionDto(v1);
46
+ const c2 = U.createConditionDto(v2);
47
+ const c3 = U.createConditionDto(v3);
48
+ const c4 = U.createConditionDto(v4);
49
+ const cg1 = U.createConditionDto(vg1);
50
+ const cg2 = U.createConditionDto(vg2);
51
+ const cg3 = U.createConditionDto(vg3);
52
+ const cg4 = U.createConditionDto(vg4);
53
+ const group3: BuilderConditionGroupDto = {
54
+ kind: "condition-group",
55
+ name: "group3",
56
+ type: "all",
57
+ conditions: [cg1, cg2, cg3, cg4],
58
+ };
59
+
60
+ const builderRuleDto1: BuilderRuleDto = {
61
+ type: "any",
62
+ jumpToPage: false,
63
+ excludePages: [v1.varId, v3.varId],
64
+ excludeTags: [tagAction1.tag, tagAction2.tag],
65
+ name: "kitchen-sink",
66
+ conditions: [c1, c2, group3, c3, c4],
67
+ };
62
68
 
63
- return { ruleInput, builderRuleDto: builderRuleDto1 };
69
+ return { ruleInput, builderRuleDto: builderRuleDto1 };
64
70
  };
65
71
  let dto: BuilderRuleDto = {
66
- name: "test-rule",
67
- conditions: [],
68
- type: "all",
69
- excludePages: [],
70
- excludeTags: [],
71
- jumpToPage: false,
72
+ name: "test-rule",
73
+ conditions: [],
74
+ type: "all",
75
+ excludePages: [],
76
+ excludeTags: [],
77
+ jumpToPage: false,
72
78
  };
73
79
 
74
80
  const excludeByTagActionList = U.excludeByTagActionList();
75
81
  const pageActions = questionVariables.map((q) => U.excludeByPageIdAction(q.varId, q.pageNumber));
82
+
76
83
  let ruleInput = new RuleInput(questionVariables, [], [...pageActions], excludeByTagActionList, []);
77
84
 
78
85
  let rule: BuilderRule = BuilderRule.fromDto(dto, ruleInput);
79
86
 
80
87
  beforeEach(() => {
81
- rule = BuilderRule.fromDto(dto, ruleInput);
88
+ rule = BuilderRule.fromDto(dto, ruleInput);
82
89
  });
83
90
 
84
91
  describe("Builder Rule", () => {
85
- test("Can create rule", () => {
86
- expect(rule).toBeInstanceOf(BuilderRule);
87
- });
88
- test("Can add condition", () => {
89
- rule.addCondition();
90
- expect(rule.conditions.length).toBe(1);
91
- });
92
- test("Can delete condition", () => {
93
- const r1 = rule.addCondition();
94
- const r2 = rule.addCondition();
95
- const r3 = rule.addCondition();
96
- const r4 = rule.addCondition();
97
- const r5 = rule.addCondition();
98
- expect(rule.conditionCount).toBe(5);
99
- const result = rule.deleteCondition(r3);
100
- expect(result).toBeTruthy();
101
- expect(rule.conditionCount).toBe(4);
102
- expect(rule.conditions[0]).toBe(r1);
103
- expect(rule.conditions[1]).toBe(r2);
104
- expect(rule.conditions[2]).toBe(r4);
105
- expect(rule.conditions[3]).toBe(r5);
106
- expect(rule.deleteCondition(r3)).toBeFalsy();
107
- // expect(rule.conditions[0]).toBe(r1);
108
- });
109
- test("Can delete condition-group", () => {
110
- const r1 = rule.addCondition();
111
- const r2 = rule.addConditionGroup();
112
- const r3 = rule.addConditionGroup();
113
- const r4 = rule.addCondition();
114
- const r5 = rule.addConditionGroup();
115
- expect(rule.conditionCount).toBe(5);
116
- const result = rule.deleteCondition(r2);
117
- expect(result).toBeTruthy();
118
- expect(rule.conditionCount).toBe(4);
119
- expect(rule.conditions[0]).toBe(r1);
120
- expect(rule.conditions[1]).toBe(r3);
121
- expect(rule.conditions[2]).toBe(r4);
122
- expect(rule.conditions[3]).toBe(r5);
123
- expect(rule.deleteCondition(r2)).toBeFalsy();
124
- expect(rule.deleteCondition(r1)).toBeTruthy();
125
- expect(rule.deleteCondition(r5)).toBeTruthy();
126
- expect(rule.conditionCount).toBe(2);
127
- });
128
-
129
- test("Conditions have no operators available before variable is set.", () => {
130
- const c1 = rule.addCondition();
131
- expect(c1.operatorsSelectItems.length).toBe(0);
132
-
133
- const a = c1.variableSelectItemsInUniverse[0]?.data ?? false;
134
- c1.variable = a;
135
- expect(c1.operatorsSelectItems.length).toBe(2);
136
- });
137
-
138
- test("Conditions and actions in dto will exist: ", () => {
139
- const v1 = ruleInput.questionVars[0];
140
- const v2 = ruleInput.questionVars[1];
141
- const tag1 = ruleInput.excludeByTagActions[0];
142
- const pageAction1 = ruleInput.excludeByPageIdActions[0];
143
-
144
- const dtoWithOneCondition: BuilderRuleDto = {
145
- ...dto,
146
- excludePages: [pageAction1.pageId],
147
- excludeTags: [tag1.tag],
148
- jumpToPage: v1.varId,
149
- conditions: [
150
- {
151
- kind: "condition",
152
- name: "condition 1",
153
- variableId: v1.varId,
154
- operator: "equal",
155
- value: v1.options[0].value,
156
- },
157
- {
158
- kind: "condition-group",
159
- type: "all",
160
- name: "condtion-grup-from-testing.",
161
- conditions: [
162
- {
163
- name: "nested-condition",
164
- kind: "condition",
165
- value: v2.options[0].value,
166
- operator: "equal",
167
- variableId: v2.varId,
168
- },
169
- ],
170
- },
171
- ],
172
- };
173
-
174
- const rule = BuilderRule.fromDto(dtoWithOneCondition, ruleInput);
175
- // console.log(rule);
176
- expect(rule.conditions.length).toBe(2);
177
- const excludeTags = rule.toJson().excludeTags;
178
- expect(excludeTags.length).toBe(1);
179
- expect(rule.jumpToActionManager).toBeTruthy();
180
- });
181
-
182
- test("fromJSON -> toJSON -> are equal.", () => {
183
- const data = createDto();
184
-
185
- const localRule = BuilderRule.fromDto(data.builderRuleDto, data.ruleInput);
186
-
187
- const json = localRule.toJson();
188
- expect(data.builderRuleDto).toStrictEqual(json);
189
- });
190
-
191
- test("invalid tags will be removed.", () => {
192
- const ruleInput = new RuleInput([], [], [], U.excludeByTagActionList(), []);
193
- const dto: BuilderRuleDto = {
194
- conditions: [],
195
- excludePages: [],
196
- excludeTags: ["tag3", "tag1"],
197
- jumpToPage: false,
198
- name: "Rule-name-in-test",
199
- type: "all",
200
- };
201
-
202
- const localRule = BuilderRule.fromDto(dto, ruleInput);
203
-
204
- expect(ruleInput.excludeByTagActions.length).toStrictEqual(10);
205
- expect(ruleInput.excludeByTagActions.length).toStrictEqual(10);
206
- });
92
+ test("Can create rule", () => {
93
+ expect(rule).toBeInstanceOf(BuilderRule);
94
+ });
95
+ test("Can add condition", () => {
96
+ rule.addCondition();
97
+ expect(rule.conditions.length).toBe(1);
98
+ });
99
+ test("Can delete condition", () => {
100
+ const r1 = rule.addCondition();
101
+ const r2 = rule.addCondition();
102
+ const r3 = rule.addCondition();
103
+ const r4 = rule.addCondition();
104
+ const r5 = rule.addCondition();
105
+ expect(rule.conditionCount).toBe(5);
106
+ const result = rule.deleteCondition(r3);
107
+ expect(result).toBeTruthy();
108
+ expect(rule.conditionCount).toBe(4);
109
+ expect(rule.conditions[0]).toBe(r1);
110
+ expect(rule.conditions[1]).toBe(r2);
111
+ expect(rule.conditions[2]).toBe(r4);
112
+ expect(rule.conditions[3]).toBe(r5);
113
+ expect(rule.deleteCondition(r3)).toBeFalsy();
114
+ // expect(rule.conditions[0]).toBe(r1);
115
+ });
116
+ test("Can delete condition-group", () => {
117
+ const r1 = rule.addCondition();
118
+ const r2 = rule.addConditionGroup();
119
+ const r3 = rule.addConditionGroup();
120
+ const r4 = rule.addCondition();
121
+ const r5 = rule.addConditionGroup();
122
+ expect(rule.conditionCount).toBe(5);
123
+ const result = rule.deleteCondition(r2);
124
+ expect(result).toBeTruthy();
125
+ expect(rule.conditionCount).toBe(4);
126
+ expect(rule.conditions[0]).toBe(r1);
127
+ expect(rule.conditions[1]).toBe(r3);
128
+ expect(rule.conditions[2]).toBe(r4);
129
+ expect(rule.conditions[3]).toBe(r5);
130
+ expect(rule.deleteCondition(r2)).toBeFalsy();
131
+ expect(rule.deleteCondition(r1)).toBeTruthy();
132
+ expect(rule.deleteCondition(r5)).toBeTruthy();
133
+ expect(rule.conditionCount).toBe(2);
134
+ });
135
+
136
+ test("Conditions have no operators available before variable is set.", () => {
137
+ const c1 = rule.addCondition();
138
+ expect(c1.operatorsSelectItems.length).toBe(0);
139
+
140
+ const a = c1.variableSelectItemsInUniverse[0]?.data ?? false;
141
+ c1.variable = a;
142
+ expect(c1.operatorsSelectItems.length).toBe(2);
143
+ });
144
+
145
+ test("Conditions and actions in dto will exist: ", () => {
146
+ const v1 = ruleInput.questionVars[0];
147
+ const v2 = ruleInput.questionVars[1];
148
+ const tag1 = ruleInput.excludeByTagActions[0];
149
+ const pageAction1 = ruleInput.excludeByPageIdActions[0];
150
+
151
+ const dtoWithOneCondition: BuilderRuleDto = {
152
+ ...dto,
153
+ excludePages: [pageAction1.pageId],
154
+ excludeTags: [tag1.tag],
155
+ jumpToPage: v1.varId,
156
+ conditions: [
157
+ {
158
+ kind: "condition",
159
+ name: "condition 1",
160
+ variableId: v1.varId,
161
+ operator: "equal",
162
+ value: v1.options[0].value,
163
+ },
164
+ {
165
+ kind: "condition-group",
166
+ type: "all",
167
+ name: "condtion-grup-from-testing.",
168
+ conditions: [
169
+ {
170
+ name: "nested-condition",
171
+ kind: "condition",
172
+ value: v2.options[0].value,
173
+ operator: "equal",
174
+ variableId: v2.varId,
175
+ },
176
+ ],
177
+ },
178
+ ],
179
+ };
180
+
181
+ const rule = BuilderRule.fromDto(dtoWithOneCondition, ruleInput);
182
+ // console.log(rule);
183
+ expect(rule.conditions.length).toBe(2);
184
+ const excludeTags = rule.toJson().excludeTags;
185
+ expect(excludeTags.length).toBe(1);
186
+ expect(rule.jumpToActionManager).toBeTruthy();
187
+ });
188
+
189
+ test("fromJSON -> toJSON -> are equal.", () => {
190
+ const data = createDto();
191
+
192
+ const localRule = BuilderRule.fromDto(data.builderRuleDto, data.ruleInput);
193
+
194
+ const json = localRule.toJson();
195
+ expect(data.builderRuleDto).toStrictEqual(json);
196
+ });
197
+
198
+ test("invalid tags will be removed.", () => {
199
+ const ruleInput = new RuleInput([], [], [], U.excludeByTagActionList(), []);
200
+ const dto: BuilderRuleDto = {
201
+ conditions: [],
202
+ excludePages: [],
203
+ excludeTags: ["tag3", "tag1"],
204
+ jumpToPage: false,
205
+ name: "Rule-name-in-test",
206
+ type: "all",
207
+ };
208
+
209
+ const localRule = BuilderRule.fromDto(dto, ruleInput);
210
+
211
+ expect(ruleInput.excludeByTagActions.length).toStrictEqual(10);
212
+ expect(ruleInput.excludeByTagActions.length).toStrictEqual(10);
213
+ });
214
+
215
+ test("toEngineRuleWorks: ", () => {
216
+ const input = createDto().ruleInput;
217
+ const v1 = input.questionVars[0];
218
+ const v2 = input.questionVars[1];
219
+ const tag1 = input.excludeByTagActions[0];
220
+ const pageAction1 = input.excludeByPageIdActions[0];
221
+
222
+ const c1: BuilderConditionDto = {
223
+ kind: "condition",
224
+ name: "condition 1",
225
+ variableId: v1.varId,
226
+ operator: "equal",
227
+ value: v1.options[0].value,
228
+ };
229
+ const c2: BuilderConditionDto = {
230
+ name: "nested-condition",
231
+ kind: "condition",
232
+ value: v2.options[0].value,
233
+ operator: "equal",
234
+ variableId: v2.varId,
235
+ };
236
+ const conditionGroupANY: BuilderConditionGroupDto = {
237
+ kind: "condition-group",
238
+ conditions: [c1, c2],
239
+ name: "or-condition",
240
+ type: "any",
241
+ };
242
+
243
+ const conditionGroupALL: BuilderConditionGroupDto = {
244
+ kind: "condition-group",
245
+ conditions: [c2],
246
+ name: "condition group ALL - in testing.",
247
+ type: "all",
248
+ };
249
+
250
+ const dtoWithOneCondition: BuilderRuleDto = {
251
+ type: "all",
252
+ name: "dto-with-one-condition",
253
+ excludePages: [pageAction1.pageId],
254
+ excludeTags: [tag1.tag],
255
+ jumpToPage: v1.varId,
256
+ conditions: [c1, conditionGroupALL, conditionGroupANY],
257
+ };
258
+
259
+ const actionCount =
260
+ dtoWithOneCondition.excludeTags.length +
261
+ dtoWithOneCondition.excludePages.length +
262
+ (dtoWithOneCondition.jumpToPage ? 1 : 0);
263
+
264
+ const rule = BuilderRule.fromDto(dtoWithOneCondition, input);
265
+ const engineRule = rule.toEngineRule();
266
+
267
+ // console.log(rule);
268
+ expect(engineRule.all.length).toBe(3);
269
+ expect(engineRule.some.length).toBe(0);
270
+
271
+ const simple1 = engineRule.all.find(
272
+ (c) => c.kind === "numeric-condition" && c.referenceId === c1.variableId,
273
+ ) as Condition.Numeric;
274
+ const complex1 = engineRule.all.find(
275
+ (c) => c.kind === "complex-condition" && c.all.length === 1,
276
+ ) as Condition.Complex;
277
+
278
+ const complexChild1 = complex1.all[0] as Condition.Numeric;
279
+ expect(simple1).toBeTruthy();
280
+ expect(simple1.operator === "eq").toBeTruthy();
281
+ expect(simple1.value === c1.value).toBeTruthy();
282
+ expect(simple1.referenceLabel).toBe(v1.label);
283
+ expect(complex1).toBeTruthy();
284
+ expect(complexChild1).toBeTruthy();
285
+ expect(complexChild1.referenceId).toBe(c2.variableId);
286
+ expect(complexChild1.value).toBe(c2.value);
287
+ expect(complexChild1.referenceLabel).toBe(v2.label);
288
+ expect(complexChild1.operator === "eq").toBeTruthy();
289
+ expect(engineRule.onSuccess.length).toBe(actionCount);
290
+ });
207
291
  });