@media-quest/builder 0.0.22 → 0.0.23
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 +1 -1
- package/src/Builder-option.ts +66 -66
- package/src/Builder-page.spec.ts +320 -320
- package/src/Builder-page.ts +257 -257
- package/src/Builder-question.spec.ts +68 -68
- package/src/Builder-question.ts +101 -101
- package/src/Builder-schema.spec.ts +357 -306
- package/src/Builder-schema.ts +287 -254
- package/src/Builder-text.spec.ts +24 -24
- package/src/Builder-text.ts +57 -57
- package/src/BuilderMainImageDto.ts +7 -7
- package/src/BuilderMainText.ts +81 -81
- package/src/BuilderMainVideoDto.ts +10 -10
- package/src/BuilderObject.ts +61 -61
- package/src/BuilderTag.ts +97 -97
- package/src/builder-compiler.ts +14 -0
- package/src/codebook.ts +72 -72
- package/src/media-files.ts +28 -28
- package/src/primitives/page-prefix.ts +58 -58
- package/src/primitives/prefix.spec.ts +5 -5
- package/src/primitives/schema-prefix.ts +52 -52
- package/src/primitives/varID.ts +11 -11
- package/src/public-api.ts +3 -1
- package/src/rulebuilder/Builder-rule.spec.ts +322 -322
- package/src/rulebuilder/Builder-rule.ts +190 -190
- package/src/rulebuilder/RuleAction.ts +106 -106
- package/src/rulebuilder/RuleBuilder-test-utils.ts +316 -316
- package/src/rulebuilder/RuleInput.ts +44 -44
- package/src/rulebuilder/RuleVariable.ts +49 -49
- package/src/rulebuilder/SingleSelectItem.ts +135 -135
- package/src/rulebuilder/condition/Builder-condition-group.spec.ts +47 -47
- package/src/rulebuilder/condition/Builder-condition-group.ts +118 -118
- package/src/rulebuilder/condition/Builder-condition.spec.ts +195 -195
- package/src/rulebuilder/condition/Builder-condition.ts +208 -208
- package/src/rulebuilder/condition/Builder-operator.spec.ts +9 -9
- package/src/rulebuilder/condition/Builder-operator.ts +31 -31
- package/src/rulebuilder/index.ts +22 -22
- package/src/rulebuilder/jump-to-action-manager.ts +33 -33
- package/src/rulebuilder/multi-select-item.ts +73 -73
- package/src/rulebuilder/page-action-manager.ts +31 -31
- package/src/rulebuilder/rule2/Rule2.ts +211 -211
- package/src/rulebuilder/tag-action-manager.spec.ts +44 -44
- package/src/rulebuilder/tag-action-manager.ts +28 -28
- package/src/schema-config.ts +25 -25
- package/src/theme/AbstractThemeCompiler.ts +7 -7
- package/src/theme/IDefaultTheme.ts +226 -226
- package/src/theme/css-theme.ts +7 -7
- package/src/theme/default-theme-compiler.ts +358 -358
- package/src/theme/icon-urls.ts +29 -29
- package/src/theme/theme-utils.ts +57 -57
- package/src/theme/theme1.spec.ts +52 -52
- package/src/variable/mq-variable.spec.ts +91 -0
- package/src/{mq-variable.ts → variable/mq-variable.ts} +63 -61
- package/src/variable/sum-score-variable.ts +56 -0
- package/tsconfig.json +15 -15
- package/tsconfig.tsbuildinfo +1 -1
|
@@ -1,306 +1,357 @@
|
|
|
1
|
-
import type { BuilderSchemaDto } from "./Builder-schema";
|
|
2
|
-
import { BuilderSchema } from "./Builder-schema";
|
|
3
|
-
import { BuilderPage } from "./Builder-page";
|
|
4
|
-
import type { BuilderTagDto } from "./BuilderTag";
|
|
5
|
-
import { BuilderTag } from "./BuilderTag";
|
|
6
|
-
import type { BuilderObjectId } from "./BuilderObject";
|
|
7
|
-
import { PageID, SchemaID } from "@media-quest/engine";
|
|
8
|
-
import { PagePrefix } from "./primitives/page-prefix";
|
|
9
|
-
import { SchemaPrefix } from "./primitives/schema-prefix";
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
const
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
const
|
|
154
|
-
expect(
|
|
155
|
-
|
|
156
|
-
expect(
|
|
157
|
-
expect(
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
const
|
|
163
|
-
|
|
164
|
-
const
|
|
165
|
-
expect(
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
const
|
|
170
|
-
expect(
|
|
171
|
-
expect(
|
|
172
|
-
expect(
|
|
173
|
-
|
|
174
|
-
expect(
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
expect(
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
expect(
|
|
187
|
-
|
|
188
|
-
expect(
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
const
|
|
194
|
-
const
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
expect(
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
const
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
const
|
|
218
|
-
builderSchema.
|
|
219
|
-
|
|
220
|
-
expect(pages[
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
const
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
const
|
|
243
|
-
const
|
|
244
|
-
|
|
245
|
-
const
|
|
246
|
-
const
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
expect(
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
test("
|
|
253
|
-
const p1 = builderSchema.addPage("
|
|
254
|
-
const p2 = builderSchema.addPage("
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
//
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
const
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
ruleInput.jumpToPageActions.
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
1
|
+
import type { BuilderSchemaDto } from "./Builder-schema";
|
|
2
|
+
import { BuilderSchema } from "./Builder-schema";
|
|
3
|
+
import { BuilderPage } from "./Builder-page";
|
|
4
|
+
import type { BuilderTagDto } from "./BuilderTag";
|
|
5
|
+
import { BuilderTag } from "./BuilderTag";
|
|
6
|
+
import type { BuilderObjectId } from "./BuilderObject";
|
|
7
|
+
import { PageID, SchemaID } from "@media-quest/engine";
|
|
8
|
+
import { PagePrefix } from "./primitives/page-prefix";
|
|
9
|
+
import { SchemaPrefix } from "./primitives/schema-prefix";
|
|
10
|
+
import { SumScoreVariable } from "./variable/sum-score-variable";
|
|
11
|
+
|
|
12
|
+
const tag1: BuilderTagDto = BuilderTag.create("tag1", "This tag is defined in schemaDto1").toJson();
|
|
13
|
+
|
|
14
|
+
const tag2: BuilderTagDto = BuilderTag.create("tag2", "This tag is defined in schemaDto1").toJson();
|
|
15
|
+
const tag3: BuilderTagDto = BuilderTag.create("tag3", "This tag is defined in schemaDto1").toJson();
|
|
16
|
+
|
|
17
|
+
const schemaDto1: BuilderSchemaDto = {
|
|
18
|
+
backgroundColor: "gray",
|
|
19
|
+
baseHeight: 1200,
|
|
20
|
+
baseWidth: 1022,
|
|
21
|
+
mainImage: false,
|
|
22
|
+
id: SchemaID.create(),
|
|
23
|
+
name: "dto1-name",
|
|
24
|
+
tags: [tag1, tag2, tag3],
|
|
25
|
+
sumScoreVariables: [
|
|
26
|
+
{
|
|
27
|
+
kind: "numeric-variable",
|
|
28
|
+
origin: "sum-score",
|
|
29
|
+
label: "label for dummy variable",
|
|
30
|
+
initialValue: 0,
|
|
31
|
+
varId: "testId",
|
|
32
|
+
basedOn: [],
|
|
33
|
+
},
|
|
34
|
+
],
|
|
35
|
+
pages: [
|
|
36
|
+
{
|
|
37
|
+
id: PageID.ensure("a".repeat(24)),
|
|
38
|
+
_type: "info-page",
|
|
39
|
+
prefix: PagePrefix.fromStringOrThrow("p1"),
|
|
40
|
+
mainText: {
|
|
41
|
+
text: "hello from test",
|
|
42
|
+
autoplay: false,
|
|
43
|
+
autoplayDelay: 0,
|
|
44
|
+
audioFile: false,
|
|
45
|
+
},
|
|
46
|
+
|
|
47
|
+
nextButton: {
|
|
48
|
+
id: "next-button-text-id" as BuilderObjectId.QuestionOptionID,
|
|
49
|
+
label: "Neste",
|
|
50
|
+
value: -1,
|
|
51
|
+
},
|
|
52
|
+
defaultQuestion: {
|
|
53
|
+
id: "q1" as BuilderObjectId.QuestionID,
|
|
54
|
+
prefix: "one-prefix",
|
|
55
|
+
_type: "select-one",
|
|
56
|
+
text: "q1-text",
|
|
57
|
+
options: [
|
|
58
|
+
{
|
|
59
|
+
id: "opt-nei" as BuilderObjectId.QuestionOptionID,
|
|
60
|
+
value: 0,
|
|
61
|
+
label: "Nei",
|
|
62
|
+
},
|
|
63
|
+
{
|
|
64
|
+
id: "opt-ja" as BuilderObjectId.QuestionOptionID,
|
|
65
|
+
value: 1,
|
|
66
|
+
label: "Ja",
|
|
67
|
+
},
|
|
68
|
+
{
|
|
69
|
+
id: "opt-vet-ikke" as BuilderObjectId.QuestionOptionID,
|
|
70
|
+
value: 9,
|
|
71
|
+
label: "Vet ikke",
|
|
72
|
+
},
|
|
73
|
+
],
|
|
74
|
+
},
|
|
75
|
+
tags: [
|
|
76
|
+
tag1.tag,
|
|
77
|
+
tag2.tag,
|
|
78
|
+
// { tag: 'can_read', description: 'The patient can read' },
|
|
79
|
+
// { tag: 'is grown up', description: 'Is grownUp.' }
|
|
80
|
+
],
|
|
81
|
+
questions: [],
|
|
82
|
+
autoplaySequence: [],
|
|
83
|
+
},
|
|
84
|
+
{
|
|
85
|
+
id: PageID.ensure("b".repeat(24)),
|
|
86
|
+
_type: "multi-select",
|
|
87
|
+
prefix: PagePrefix.fromStringOrThrow("page2-prefix"),
|
|
88
|
+
tags: [tag3.tag],
|
|
89
|
+
mainText: {
|
|
90
|
+
text: "hello from test",
|
|
91
|
+
autoplay: false,
|
|
92
|
+
autoplayDelay: 0,
|
|
93
|
+
audioFile: false,
|
|
94
|
+
},
|
|
95
|
+
nextButton: {
|
|
96
|
+
id: "next-button-id-page2" as BuilderObjectId.QuestionOptionID,
|
|
97
|
+
label: "Neste",
|
|
98
|
+
value: -1,
|
|
99
|
+
},
|
|
100
|
+
defaultQuestion: {
|
|
101
|
+
id: "default-q" as BuilderObjectId.QuestionID,
|
|
102
|
+
prefix: "one-prefix",
|
|
103
|
+
_type: "select-one",
|
|
104
|
+
text: "q1",
|
|
105
|
+
options: [],
|
|
106
|
+
},
|
|
107
|
+
questions: [
|
|
108
|
+
{
|
|
109
|
+
id: "q1" as BuilderObjectId.QuestionID,
|
|
110
|
+
prefix: "one-prefix",
|
|
111
|
+
_type: "select-one",
|
|
112
|
+
text: "q1-text",
|
|
113
|
+
options: [
|
|
114
|
+
{
|
|
115
|
+
id: "opt-nei" as BuilderObjectId.QuestionOptionID,
|
|
116
|
+
value: 0,
|
|
117
|
+
label: "Nei",
|
|
118
|
+
},
|
|
119
|
+
{
|
|
120
|
+
id: "opt-ja" as BuilderObjectId.QuestionOptionID,
|
|
121
|
+
value: 1,
|
|
122
|
+
label: "Ja",
|
|
123
|
+
},
|
|
124
|
+
{
|
|
125
|
+
id: "opt-vet-ikke" as BuilderObjectId.QuestionOptionID,
|
|
126
|
+
value: 9,
|
|
127
|
+
label: "Vet ikke",
|
|
128
|
+
},
|
|
129
|
+
],
|
|
130
|
+
},
|
|
131
|
+
],
|
|
132
|
+
autoplaySequence: [],
|
|
133
|
+
},
|
|
134
|
+
],
|
|
135
|
+
predefinedVariables: [],
|
|
136
|
+
rules: [],
|
|
137
|
+
prefix: SchemaPrefix.fromValueOrThrow("d1").value,
|
|
138
|
+
};
|
|
139
|
+
|
|
140
|
+
const SCHEMA_ID = SchemaID.create();
|
|
141
|
+
const schemaPrefixA = SchemaPrefix.castOrCreateRandom("a").value;
|
|
142
|
+
let builderSchema = BuilderSchema.create(SCHEMA_ID, "test", schemaPrefixA);
|
|
143
|
+
|
|
144
|
+
beforeEach(() => {
|
|
145
|
+
builderSchema = BuilderSchema.create(SCHEMA_ID, "test-name", schemaPrefixA);
|
|
146
|
+
});
|
|
147
|
+
|
|
148
|
+
describe("Builder schema", () => {
|
|
149
|
+
test("Can add pages.", () => {
|
|
150
|
+
builderSchema.addPage("question");
|
|
151
|
+
builderSchema.addPage("info-page");
|
|
152
|
+
expect(builderSchema.pages.length).toBe(2);
|
|
153
|
+
const dto = builderSchema.compile().schema;
|
|
154
|
+
expect(dto.pages.length).toBe(2);
|
|
155
|
+
expect(dto.id).toBe(builderSchema.id);
|
|
156
|
+
expect(dto.baseHeight).toBe(builderSchema.baseHeight);
|
|
157
|
+
expect(dto.baseWidth).toBe(builderSchema.baseWidth);
|
|
158
|
+
expect(dto.backgroundColor).toBe(builderSchema.backgroundColor);
|
|
159
|
+
});
|
|
160
|
+
|
|
161
|
+
test("Can delete page by passing reference", () => {
|
|
162
|
+
const p1 = builderSchema.addPage("question");
|
|
163
|
+
const p2 = builderSchema.addPage("question");
|
|
164
|
+
const p3 = builderSchema.addPage("info-page");
|
|
165
|
+
expect(builderSchema.pages.length).toBe(3);
|
|
166
|
+
const result = builderSchema.deletePage(p1);
|
|
167
|
+
expect(builderSchema.pages.length).toBe(2);
|
|
168
|
+
expect(result).toBe(true);
|
|
169
|
+
const result2 = builderSchema.deletePage(p2);
|
|
170
|
+
expect(result2).toBe(true);
|
|
171
|
+
expect(builderSchema.pages.length).toBe(1);
|
|
172
|
+
expect(builderSchema.pages[0]).toBe(p3);
|
|
173
|
+
const result3 = builderSchema.deletePage(p2);
|
|
174
|
+
expect(result3).toBe(false);
|
|
175
|
+
const result4 = builderSchema.deletePage(p3);
|
|
176
|
+
expect(result4).toBe(true);
|
|
177
|
+
});
|
|
178
|
+
|
|
179
|
+
test("Can create Schema from dto", () => {
|
|
180
|
+
const s = BuilderSchema.fromJson(schemaDto1);
|
|
181
|
+
expect(s.id).toBe(schemaDto1.id);
|
|
182
|
+
expect(s.prefix.value).toBe(schemaDto1.prefix);
|
|
183
|
+
expect(s.baseHeight).toBe(schemaDto1.baseHeight);
|
|
184
|
+
expect(s.baseWidth).toBe(schemaDto1.baseWidth);
|
|
185
|
+
expect(s.backgroundColor).toBe(schemaDto1.backgroundColor);
|
|
186
|
+
expect(s.pages.length).toBe(schemaDto1.pages.length);
|
|
187
|
+
const p1Dto = schemaDto1.pages[0];
|
|
188
|
+
expect(s.pages[0].id).toBe(p1Dto.id);
|
|
189
|
+
const defaultQuestion = s.pages[0].defaultQuestion;
|
|
190
|
+
expect(defaultQuestion).toBeDefined();
|
|
191
|
+
expect(defaultQuestion.id).toBe(p1Dto.defaultQuestion.id);
|
|
192
|
+
expect(defaultQuestion.options.length).toBe(p1Dto.defaultQuestion.options.length);
|
|
193
|
+
const options = defaultQuestion.options;
|
|
194
|
+
const nei = options[0];
|
|
195
|
+
const ja = options[1];
|
|
196
|
+
const vetIkke = options[2];
|
|
197
|
+
expect(nei.label).toBe("Nei");
|
|
198
|
+
expect(ja.label).toBe("Ja");
|
|
199
|
+
expect(vetIkke.label).toBe("Vet ikke");
|
|
200
|
+
expect(vetIkke.id).toBe(p1Dto.defaultQuestion.options[2].id);
|
|
201
|
+
});
|
|
202
|
+
|
|
203
|
+
test("fromJson === toJson", () => {
|
|
204
|
+
const s = BuilderSchema.fromJson(schemaDto1);
|
|
205
|
+
const json = s.toJson();
|
|
206
|
+
expect(schemaDto1).toStrictEqual(json);
|
|
207
|
+
});
|
|
208
|
+
test("Can add page at concrete index", () => {
|
|
209
|
+
const p1 = builderSchema.addPage("form");
|
|
210
|
+
expect(p1.pageType).toBe("form");
|
|
211
|
+
const p2 = builderSchema.addPage("multi-select", 0);
|
|
212
|
+
expect(p2.pageType).toBe("multi-select");
|
|
213
|
+
const pages = builderSchema.pages;
|
|
214
|
+
expect(pages[0].id).toBe(p2.id);
|
|
215
|
+
builderSchema.addPage("form");
|
|
216
|
+
builderSchema.addPage("form");
|
|
217
|
+
const last = builderSchema.addPage("form");
|
|
218
|
+
expect(builderSchema.pages[builderSchema.pages.length - 1]).toBe(last);
|
|
219
|
+
const p3 = builderSchema.addPage("info-page", 4);
|
|
220
|
+
expect(pages[4].id).toBe(p3.id);
|
|
221
|
+
});
|
|
222
|
+
test("Can move page up and down", () => {
|
|
223
|
+
const p1 = builderSchema.addPage("form");
|
|
224
|
+
const p2 = builderSchema.addPage("form");
|
|
225
|
+
const p3 = builderSchema.addPage("form");
|
|
226
|
+
const p4 = builderSchema.addPage("multi-select");
|
|
227
|
+
const last = builderSchema.addPage("form");
|
|
228
|
+
const pages = builderSchema.pages;
|
|
229
|
+
builderSchema.movePage(p2, 0);
|
|
230
|
+
expect(pages[0]).toBe(p2);
|
|
231
|
+
expect(pages[1]).toBe(p1);
|
|
232
|
+
expect(builderSchema.movePage(p4, 4)).toBeTruthy();
|
|
233
|
+
expect(builderSchema.movePage(p4, 5)).toBeFalsy();
|
|
234
|
+
expect(builderSchema.movePage(p4, 10)).toBeFalsy();
|
|
235
|
+
|
|
236
|
+
// expect(pages[0].id).toBe(p4.id);
|
|
237
|
+
});
|
|
238
|
+
test("Can clone a page and insert at index", () => {
|
|
239
|
+
const p1 = builderSchema.addPage("form");
|
|
240
|
+
const p2 = builderSchema.addPage("form");
|
|
241
|
+
const p3 = builderSchema.addPage("form");
|
|
242
|
+
const mainTextContent = "Hello from test";
|
|
243
|
+
const p4 = builderSchema.addPage("multi-select");
|
|
244
|
+
p3.mainText.text = mainTextContent;
|
|
245
|
+
const p1Clone = BuilderPage.fromJson(p1.clone());
|
|
246
|
+
const beforeLen = builderSchema.pages.length;
|
|
247
|
+
builderSchema.insertPage(p1Clone, 2);
|
|
248
|
+
const pages = builderSchema.pages;
|
|
249
|
+
expect(beforeLen + 1).toBe(pages.length);
|
|
250
|
+
expect(pages[2]).toBe(p1Clone);
|
|
251
|
+
});
|
|
252
|
+
test("Will not insert a page that is already in array.", () => {
|
|
253
|
+
const p1 = builderSchema.addPage("form");
|
|
254
|
+
const p2 = builderSchema.addPage("form");
|
|
255
|
+
const p3 = builderSchema.addPage("form");
|
|
256
|
+
const beforeLen = builderSchema.pages.length;
|
|
257
|
+
const result = builderSchema.insertPage(p1, 0);
|
|
258
|
+
const pages = builderSchema.pages;
|
|
259
|
+
expect(beforeLen).toBe(pages.length);
|
|
260
|
+
expect(result).toBe(false);
|
|
261
|
+
});
|
|
262
|
+
|
|
263
|
+
test("Can generate a info-page", () => {
|
|
264
|
+
const p1 = builderSchema.addPage("info-page");
|
|
265
|
+
const p2 = builderSchema.addPage("question");
|
|
266
|
+
p2.defaultQuestion.addOption("Ja", 1, 0);
|
|
267
|
+
p2.defaultQuestion.addOption("Nei", 0);
|
|
268
|
+
p1.nextButton.label = "Neste";
|
|
269
|
+
builderSchema.backgroundColor = "red";
|
|
270
|
+
builderSchema.baseHeight = 600;
|
|
271
|
+
builderSchema.baseWidth = 500;
|
|
272
|
+
// builderSchema.prefix = "as";
|
|
273
|
+
builderSchema.name = "depressed";
|
|
274
|
+
const schema = builderSchema.compile().schema;
|
|
275
|
+
expect(schema.backgroundColor).toBe("red");
|
|
276
|
+
expect(schema.baseHeight).toBe(600);
|
|
277
|
+
expect(schema.baseWidth).toBe(500);
|
|
278
|
+
expect(schema.pages.length).toBe(2);
|
|
279
|
+
const schemaP1 = schema.pages[0];
|
|
280
|
+
const schemaP2 = schema.pages[1];
|
|
281
|
+
expect(schemaP1.id).toBe(p1.id);
|
|
282
|
+
expect(schemaP2.id).toBe(p2.id);
|
|
283
|
+
// expect(schemaP1.elements.length).toBe(2);
|
|
284
|
+
|
|
285
|
+
// Has Buttons
|
|
286
|
+
const options = p2.defaultQuestion.options;
|
|
287
|
+
// expect(schemaP2.elements.length).toBe(options.length + 1);
|
|
288
|
+
});
|
|
289
|
+
test("Can get ruleInput!", () => {
|
|
290
|
+
const p0 = builderSchema.addPage("info-page");
|
|
291
|
+
// p0.prefix = "info_page_prefix_";
|
|
292
|
+
const p1 = builderSchema.addPage("question");
|
|
293
|
+
// p1.prefix = "p1_prefix_";
|
|
294
|
+
const p2 = builderSchema.addPage("question");
|
|
295
|
+
// p2.prefix = "p2_prefix_";
|
|
296
|
+
p1.defaultQuestion.addOption("Ja", 1, 0);
|
|
297
|
+
p1.defaultQuestion.addOption("Nei", 0, 0);
|
|
298
|
+
p2.defaultQuestion.addOption("Ja", 1, 0);
|
|
299
|
+
p2.defaultQuestion.addOption("Nei", 0);
|
|
300
|
+
const ruleInput = builderSchema.getRuleInput();
|
|
301
|
+
expect(ruleInput.questionVars.length).toBe(2);
|
|
302
|
+
expect(ruleInput.jumpToPageActions.length).toBe(3);
|
|
303
|
+
// TODO add TAGS!!
|
|
304
|
+
expect(ruleInput.excludeByTagActions.length).toBe(0);
|
|
305
|
+
expect(ruleInput.excludeByPageIdActions.length).toBe(3);
|
|
306
|
+
const allPageIds = new Set(ruleInput.jumpToPageActions.map((a) => a.pageId));
|
|
307
|
+
expect(allPageIds.has(p0.id)).toBe(true);
|
|
308
|
+
expect(allPageIds.has(p1.id)).toBe(true);
|
|
309
|
+
expect(allPageIds.has(p2.id)).toBe(true);
|
|
310
|
+
// ruleInput.questionVars.forEach((v) => {
|
|
311
|
+
// expect(allPageIds.has(v.varId)).toBe(true);
|
|
312
|
+
// });
|
|
313
|
+
ruleInput.jumpToPageActions.forEach((v) => {
|
|
314
|
+
expect(allPageIds.has(v.pageId)).toBe(true);
|
|
315
|
+
});
|
|
316
|
+
});
|
|
317
|
+
test.skip("Can add sum-variables - and save as json", () => {
|
|
318
|
+
// p0.prefix = "info_page_prefix_";
|
|
319
|
+
const p1 = builderSchema.addPage("question");
|
|
320
|
+
const p2 = builderSchema.addPage("question");
|
|
321
|
+
p1.prefix = PagePrefix.fromStringOrThrow("p1_prefix");
|
|
322
|
+
p2.prefix = PagePrefix.fromStringOrThrow("p2_prefix");
|
|
323
|
+
p1.defaultQuestion.addOption("Ja", 1, 0);
|
|
324
|
+
p1.defaultQuestion.addOption("Nei", 0, 0);
|
|
325
|
+
p2.defaultQuestion.addOption("Ja", 1, 0);
|
|
326
|
+
p2.defaultQuestion.addOption("Nei", 0);
|
|
327
|
+
|
|
328
|
+
const ruleInput = builderSchema.getRuleInput();
|
|
329
|
+
const ss1: SumScoreVariable = {
|
|
330
|
+
label: "ss1",
|
|
331
|
+
varId: "ss1_var_id",
|
|
332
|
+
initialValue: 0,
|
|
333
|
+
kind: "numeric-variable",
|
|
334
|
+
origin: "sum-score",
|
|
335
|
+
basedOn: [],
|
|
336
|
+
};
|
|
337
|
+
|
|
338
|
+
builderSchema.addSumScoreVariable(ss1);
|
|
339
|
+
|
|
340
|
+
expect(ruleInput.questionVars.length).toBe(2);
|
|
341
|
+
expect(ruleInput.jumpToPageActions.length).toBe(3);
|
|
342
|
+
|
|
343
|
+
// TODO add TAGS!!
|
|
344
|
+
// expect(ruleInput.excludeByTagActions.length).toBe(0);
|
|
345
|
+
// expect(ruleInput.excludeByPageIdActions.length).toBe(3);
|
|
346
|
+
// const allPageIds = new Set(ruleInput.jumpToPageActions.map((a) => a.pageId));
|
|
347
|
+
// expect(allPageIds.has(p0.id)).toBe(true);
|
|
348
|
+
// expect(allPageIds.has(p1.id)).toBe(true);
|
|
349
|
+
// expect(allPageIds.has(p2.id)).toBe(true);
|
|
350
|
+
// ruleInput.questionVars.forEach((v) => {
|
|
351
|
+
// expect(allPageIds.has(v.varId)).toBe(true);
|
|
352
|
+
// });
|
|
353
|
+
// ruleInput.jumpToPageActions.forEach((v) => {
|
|
354
|
+
// expect(allPageIds.has(v.pageId)).toBe(true);
|
|
355
|
+
// });
|
|
356
|
+
});
|
|
357
|
+
});
|