@media-quest/builder 0.0.2 → 0.0.3
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/dist/public-api.d.mts +24 -6
- package/dist/public-api.d.ts +24 -6
- package/dist/public-api.js +58 -32
- package/dist/public-api.mjs +39 -32
- package/package.json +3 -4
- package/src/public-api.ts +3 -0
- package/src/rulebuilder/Builder-rule.spec.ts +182 -182
- package/src/rulebuilder/Builder-rule.ts +34 -65
- package/src/rulebuilder/RuleBuilder-test-utils.ts +228 -228
- package/src/rulebuilder/SingleSelectItem.ts +118 -118
- package/src/rulebuilder/{Builder-condition-group.ts → condition/Builder-condition-group.ts} +15 -33
- package/src/rulebuilder/condition/Builder-condition.spec.ts +169 -0
- package/src/rulebuilder/condition/Builder-condition.ts +186 -0
- package/src/rulebuilder/index.ts +11 -11
- package/src/rulebuilder/Builder-condition.spec.ts +0 -169
- package/src/rulebuilder/Builder-condition.ts +0 -186
- /package/src/rulebuilder/{Builder-condition-group.spec.ts → condition/Builder-condition-group.spec.ts} +0 -0
- /package/src/rulebuilder/{Builder-operator.spec.ts → condition/Builder-operator.spec.ts} +0 -0
- /package/src/rulebuilder/{Builder-operator.ts → condition/Builder-operator.ts} +0 -0
|
@@ -1,254 +1,254 @@
|
|
|
1
1
|
import { BuilderOption } from "../Builder-option";
|
|
2
2
|
import { type BuilderVariable, QuestionVariable } from "./RuleVariable";
|
|
3
3
|
import type { BuilderRuleDto } from "./Builder-rule";
|
|
4
|
-
import type { BuilderConditionGroupDto } from "./Builder-condition-group";
|
|
5
|
-
import type { BuilderConditionDto } from "./Builder-condition";
|
|
6
|
-
import type { BuilderOperator } from "./Builder-operator";
|
|
4
|
+
import type { BuilderConditionGroupDto } from "./condition/Builder-condition-group";
|
|
5
|
+
import type { BuilderConditionDto } from "./condition/Builder-condition";
|
|
6
|
+
import type { BuilderOperator } from "./condition/Builder-operator";
|
|
7
7
|
import type { ExcludeByPageAction, ExcludeByTagAction } from "./RuleAction";
|
|
8
8
|
import { ExcludeByPageIdSelectItem, ExcludeByTagSelectItem } from "./multi-select-item";
|
|
9
9
|
|
|
10
10
|
export namespace RuleBuilderTestUtils {
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
11
|
+
export const createOptions = () => [
|
|
12
|
+
BuilderOption.create(0, "Nei"),
|
|
13
|
+
BuilderOption.create(1, "Ja"),
|
|
14
|
+
BuilderOption.create(9, "Vet ikke"),
|
|
15
|
+
];
|
|
16
16
|
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
};
|
|
25
|
-
return action;
|
|
17
|
+
export const excludeByTagAction = (tag: string) => {
|
|
18
|
+
const pageCount = Math.floor(Math.random() * 10);
|
|
19
|
+
const action: ExcludeByTagAction = {
|
|
20
|
+
kind: "exclude-by-tag",
|
|
21
|
+
tag,
|
|
22
|
+
description: "Description for tag: " + tag,
|
|
23
|
+
pageCount,
|
|
26
24
|
};
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
25
|
+
return action;
|
|
26
|
+
};
|
|
27
|
+
export const excludeByPageIdAction = (pageId: string, pageNumber = 1) => {
|
|
28
|
+
const action: ExcludeByPageAction = {
|
|
29
|
+
kind: "exclude-by-pageId",
|
|
30
|
+
mainText: "",
|
|
31
|
+
pageId,
|
|
32
|
+
pageNumber,
|
|
35
33
|
};
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
34
|
+
return action;
|
|
35
|
+
};
|
|
36
|
+
export const excludeByTagActionList = () => {
|
|
37
|
+
const list = [
|
|
38
|
+
excludeByTagAction("tag1"),
|
|
39
|
+
excludeByTagAction("tag2"),
|
|
40
|
+
excludeByTagAction("tag3"),
|
|
41
|
+
excludeByTagAction("tag4"),
|
|
42
|
+
excludeByTagAction("tag5"),
|
|
43
|
+
excludeByTagAction("tag6"),
|
|
44
|
+
excludeByTagAction("tag7"),
|
|
45
|
+
excludeByTagAction("tag8"),
|
|
46
|
+
excludeByTagAction("tag9"),
|
|
47
|
+
excludeByTagAction("tag10"),
|
|
48
|
+
] as const;
|
|
49
|
+
return list;
|
|
50
|
+
};
|
|
51
|
+
export const createRuleVariable = (id: string, pageNumber: number): QuestionVariable =>
|
|
52
|
+
new QuestionVariable(id, "Har du " + id + "?", createOptions(), pageNumber);
|
|
53
53
|
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
54
|
+
/**
|
|
55
|
+
*
|
|
56
|
+
*/
|
|
57
|
+
export const createBuilderVariables_A_H = (): ReadonlyArray<QuestionVariable> => [
|
|
58
|
+
createRuleVariable("a", 3),
|
|
59
|
+
createRuleVariable("b", 4),
|
|
60
|
+
createRuleVariable("c", 5),
|
|
61
|
+
createRuleVariable("d", 6),
|
|
62
|
+
createRuleVariable("e", 7),
|
|
63
|
+
createRuleVariable("f", 8),
|
|
64
|
+
createRuleVariable("g", 9),
|
|
65
|
+
createRuleVariable("h", 10),
|
|
66
|
+
];
|
|
67
67
|
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
};
|
|
68
|
+
export const createConditionDto = (variable: BuilderVariable): BuilderConditionDto => {
|
|
69
|
+
const operator: BuilderOperator = Math.random() > 0 ? "equal" : "notEqual";
|
|
70
|
+
const opt = variable.options[0];
|
|
71
|
+
return {
|
|
72
|
+
kind: "condition",
|
|
73
|
+
name: "condition 1",
|
|
74
|
+
variableId: variable.varId,
|
|
75
|
+
operator,
|
|
76
|
+
value: opt.value,
|
|
78
77
|
};
|
|
78
|
+
};
|
|
79
79
|
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
};
|
|
80
|
+
export const createConditionGroupDto = (conditions: BuilderConditionDto[]): BuilderConditionGroupDto => {
|
|
81
|
+
return {
|
|
82
|
+
kind: "condition-group",
|
|
83
|
+
conditions,
|
|
84
|
+
type: "all",
|
|
85
|
+
name: "random-group-name",
|
|
87
86
|
};
|
|
87
|
+
};
|
|
88
88
|
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
};
|
|
105
|
-
return [];
|
|
89
|
+
export const createBuilderRuleDto = (): ReadonlyArray<BuilderRuleDto> => {
|
|
90
|
+
const variables = createBuilderVariables_A_H();
|
|
91
|
+
const condition0 = createConditionDto(variables[0]);
|
|
92
|
+
const condition1 = createConditionDto(variables[1]);
|
|
93
|
+
const condition3 = createConditionDto(variables[3]);
|
|
94
|
+
const condition5 = createConditionDto(variables[5]);
|
|
95
|
+
const group = createConditionGroupDto([condition0, condition3]);
|
|
96
|
+
// const action1: Exc
|
|
97
|
+
const rule: BuilderRuleDto = {
|
|
98
|
+
name: "rule-name",
|
|
99
|
+
conditions: [condition1, group, condition5],
|
|
100
|
+
excludeTags: [],
|
|
101
|
+
excludePages: [],
|
|
102
|
+
jumpToPage: false,
|
|
103
|
+
type: "all",
|
|
106
104
|
};
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
105
|
+
return [];
|
|
106
|
+
};
|
|
107
|
+
export const createExcludeByPageIdList = (): ReadonlyArray<ExcludeByPageIdSelectItem> => [
|
|
108
|
+
ExcludeByPageIdSelectItem.create(
|
|
109
|
+
{
|
|
110
|
+
kind: "exclude-by-pageId",
|
|
111
|
+
pageId: "page_a",
|
|
112
|
+
pageNumber: 5,
|
|
113
|
+
mainText: "Har du noen gang vært deprimeri?? ",
|
|
114
|
+
},
|
|
115
|
+
false,
|
|
116
|
+
),
|
|
117
117
|
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
118
|
+
ExcludeByPageIdSelectItem.create(
|
|
119
|
+
{
|
|
120
|
+
kind: "exclude-by-pageId",
|
|
121
|
+
pageId: "page_b",
|
|
122
|
+
pageNumber: 5,
|
|
123
|
+
mainText: "Har du noen gang vært deprimeri?? ",
|
|
124
|
+
},
|
|
125
|
+
true,
|
|
126
|
+
),
|
|
127
127
|
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
128
|
+
ExcludeByPageIdSelectItem.create(
|
|
129
|
+
{
|
|
130
|
+
kind: "exclude-by-pageId",
|
|
131
|
+
pageId: "page_c",
|
|
132
|
+
pageNumber: 5,
|
|
133
|
+
mainText: "Har du noen gang vært deprimeri?? ",
|
|
134
|
+
},
|
|
135
|
+
false,
|
|
136
|
+
),
|
|
137
137
|
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
138
|
+
ExcludeByPageIdSelectItem.create(
|
|
139
|
+
{
|
|
140
|
+
kind: "exclude-by-pageId",
|
|
141
|
+
pageId: "page_d",
|
|
142
|
+
pageNumber: 5,
|
|
143
|
+
mainText: "Har du noen gang vært deprimeri?? ",
|
|
144
|
+
},
|
|
145
|
+
false,
|
|
146
|
+
),
|
|
147
147
|
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
148
|
+
ExcludeByPageIdSelectItem.create(
|
|
149
|
+
{
|
|
150
|
+
kind: "exclude-by-pageId",
|
|
151
|
+
pageId: "page_e",
|
|
152
|
+
pageNumber: 5,
|
|
153
|
+
mainText: "Har du noen gang vært deprimeri?? ",
|
|
154
|
+
},
|
|
155
|
+
true,
|
|
156
|
+
),
|
|
157
|
+
ExcludeByPageIdSelectItem.create(
|
|
158
|
+
{
|
|
159
|
+
kind: "exclude-by-pageId",
|
|
160
|
+
pageId: "page_f",
|
|
161
|
+
pageNumber: 5,
|
|
162
|
+
mainText: "Har du noen gang vært deprimeri?? ",
|
|
163
|
+
},
|
|
164
|
+
false,
|
|
165
|
+
),
|
|
166
166
|
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
167
|
+
ExcludeByPageIdSelectItem.create(
|
|
168
|
+
{
|
|
169
|
+
kind: "exclude-by-pageId",
|
|
170
|
+
pageId: "page_g",
|
|
171
|
+
pageNumber: 5,
|
|
172
|
+
mainText: "Har du noen gang vært deprimeri?? ",
|
|
173
|
+
},
|
|
174
|
+
true,
|
|
175
|
+
),
|
|
176
176
|
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
177
|
+
ExcludeByPageIdSelectItem.create(
|
|
178
|
+
{
|
|
179
|
+
kind: "exclude-by-pageId",
|
|
180
|
+
pageId: "page_h",
|
|
181
|
+
pageNumber: 5,
|
|
182
|
+
mainText: "Har du noen gang vært deprimeri?? ",
|
|
183
|
+
},
|
|
184
|
+
false,
|
|
185
|
+
),
|
|
186
186
|
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
187
|
+
ExcludeByPageIdSelectItem.create(
|
|
188
|
+
{
|
|
189
|
+
kind: "exclude-by-pageId",
|
|
190
|
+
pageId: "page_i",
|
|
191
|
+
pageNumber: 5,
|
|
192
|
+
mainText: "Har du noen gang vært deprimeri?? ",
|
|
193
|
+
},
|
|
194
|
+
false,
|
|
195
|
+
),
|
|
196
196
|
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
197
|
+
ExcludeByPageIdSelectItem.create(
|
|
198
|
+
{
|
|
199
|
+
kind: "exclude-by-pageId",
|
|
200
|
+
pageId: "page_j",
|
|
201
|
+
pageNumber: 5,
|
|
202
|
+
mainText: "Har du noen gang vært deprimeri?? ",
|
|
203
|
+
},
|
|
204
|
+
true,
|
|
205
|
+
),
|
|
206
|
+
];
|
|
207
|
+
export const createExcludeByTagList = () => [
|
|
208
|
+
ExcludeByTagSelectItem.create(
|
|
209
|
+
{
|
|
210
|
+
kind: "exclude-by-tag",
|
|
211
|
+
tag: "Can_read",
|
|
212
|
+
pageCount: 5,
|
|
213
|
+
description: "",
|
|
214
|
+
},
|
|
215
|
+
false,
|
|
216
|
+
),
|
|
217
|
+
ExcludeByTagSelectItem.create(
|
|
218
|
+
{
|
|
219
|
+
kind: "exclude-by-tag",
|
|
220
|
+
tag: "Is grownup",
|
|
221
|
+
pageCount: 1,
|
|
222
|
+
description: "",
|
|
223
|
+
},
|
|
224
|
+
true,
|
|
225
|
+
),
|
|
226
|
+
ExcludeByTagSelectItem.create(
|
|
227
|
+
{
|
|
228
|
+
kind: "exclude-by-tag",
|
|
229
|
+
tag: "speaks english",
|
|
230
|
+
pageCount: 3,
|
|
231
|
+
description: "",
|
|
232
|
+
},
|
|
233
|
+
false,
|
|
234
|
+
),
|
|
235
|
+
ExcludeByTagSelectItem.create(
|
|
236
|
+
{
|
|
237
|
+
kind: "exclude-by-tag",
|
|
238
|
+
tag: "has work",
|
|
239
|
+
pageCount: 7,
|
|
240
|
+
description: "",
|
|
241
|
+
},
|
|
242
|
+
false,
|
|
243
|
+
),
|
|
244
|
+
ExcludeByTagSelectItem.create(
|
|
245
|
+
{
|
|
246
|
+
kind: "exclude-by-tag",
|
|
247
|
+
tag: "is-depressed",
|
|
248
|
+
pageCount: 2,
|
|
249
|
+
description: "",
|
|
250
|
+
},
|
|
251
|
+
false,
|
|
252
|
+
),
|
|
253
|
+
];
|
|
254
254
|
}
|