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