@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.
@@ -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
- export const createOptions = () => [
12
- BuilderOption.create(0, "Nei"),
13
- BuilderOption.create(1, "Ja"),
14
- BuilderOption.create(9, "Vet ikke"),
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
- 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,
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
- export const excludeByPageIdAction = (pageId: string, pageNumber = 1) => {
28
- const action: ExcludeByPageAction = {
29
- kind: "exclude-by-pageId",
30
- mainText: "",
31
- pageId,
32
- pageNumber,
33
- };
34
- return action;
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
- 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);
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
- 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
- ];
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
- 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,
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
- export const createConditionGroupDto = (conditions: BuilderConditionDto[]): BuilderConditionGroupDto => {
81
- return {
82
- kind: "condition-group",
83
- conditions,
84
- type: "all",
85
- name: "random-group-name",
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
- 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",
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
- 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
- ),
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
- 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
- ),
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
- 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
- ),
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
- 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
- ),
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
- 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
- ),
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
- 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
- ),
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
- 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
- ),
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
- 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
- ),
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
- 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
- ];
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
  }