@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.
Files changed (43) hide show
  1. package/package.json +15 -15
  2. package/src/Builder-option.ts +6 -8
  3. package/src/Builder-page.spec.ts +162 -320
  4. package/src/Builder-page.ts +182 -257
  5. package/src/Builder-question.spec.ts +57 -57
  6. package/src/Builder-question.ts +83 -82
  7. package/src/Builder-schema.spec.ts +96 -124
  8. package/src/Builder-schema.ts +25 -15
  9. package/src/Builder-text.spec.ts +11 -11
  10. package/src/Builder-text.ts +13 -13
  11. package/src/BuilderObject.ts +2 -33
  12. package/src/BuilderTag.ts +19 -20
  13. package/src/builder-compiler.ts +1 -1
  14. package/src/code-book/codebook-variable.ts +29 -0
  15. package/src/{codebook.ts → code-book/codebook.ts} +16 -16
  16. package/src/primitives/ID.spec.ts +39 -0
  17. package/src/primitives/ID.ts +138 -0
  18. package/src/primitives/page-prefix.ts +4 -3
  19. package/src/primitives/varID.ts +1 -0
  20. package/src/public-api.ts +28 -24
  21. package/src/rulebuilder/Builder-rule.spec.ts +3 -2
  22. package/src/rulebuilder/Builder-rule.ts +2 -1
  23. package/src/rulebuilder/RuleBuilder-test-utils.ts +12 -8
  24. package/src/rulebuilder/RuleInput.ts +30 -30
  25. package/src/rulebuilder/RuleVariable.ts +11 -26
  26. package/src/rulebuilder/SingleSelectItem.ts +9 -8
  27. package/src/rulebuilder/condition/Builder-condition-group.ts +14 -6
  28. package/src/rulebuilder/condition/Builder-condition.spec.ts +12 -12
  29. package/src/rulebuilder/condition/Builder-condition.ts +17 -13
  30. package/src/rulebuilder/index.ts +16 -3
  31. package/src/rulebuilder/page-action-manager.ts +4 -2
  32. package/src/rulebuilder/rule2/Rule2.ts +8 -8
  33. package/src/schema-config.ts +2 -2
  34. package/src/sum-score/sum-score-answer.ts +6 -0
  35. package/src/sum-score/sum-score-manager.spec.ts +189 -0
  36. package/src/sum-score/sum-score-manager.ts +154 -0
  37. package/src/sum-score/sum-score-membership.ts +45 -0
  38. package/src/sum-score/sum-score-variable.spec.ts +151 -0
  39. package/src/sum-score/sum-score-variable.ts +36 -0
  40. package/src/{variable → sum-score}/sum-score.ts +122 -138
  41. package/tsconfig.tsbuildinfo +1 -1
  42. package/src/variable/mq-variable.spec.ts +0 -146
  43. package/src/variable/mq-variable.ts +0 -68
@@ -1,101 +1,102 @@
1
1
  import type { BuilderOptionDto } from "./Builder-option";
2
2
  import { BuilderOption } from "./Builder-option";
3
- import { BuilderObject, BuilderObjectId } from "./BuilderObject";
3
+ import { BuilderObject } from "./BuilderObject";
4
+ import { QuestionID } from "./primitives/ID";
4
5
 
5
6
  export type BuilderQuestionType =
6
- | "select-one"
7
- | "select-many"
8
- | "text"
9
- | "color"
10
- | "radio"
11
- | "email"
12
- | "time"
13
- | "checkbox"
14
- | "textarea"
15
- | "date"
16
- | "numeric-range"
17
- | "duration";
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
- readonly id: BuilderObjectId.QuestionID;
21
- _type: BuilderQuestionType;
22
- text: string;
23
- options: ReadonlyArray<BuilderOptionDto>;
24
- prefix: string;
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
- readonly objectType = "builder-question";
29
- id: BuilderObjectId.QuestionID;
30
- type: BuilderQuestionType;
31
- questionText = "";
32
- options: BuilderOption[] = [];
33
- prefix = "";
29
+ readonly objectType = "builder-question";
30
+ id: QuestionID;
31
+ type: BuilderQuestionType;
32
+ questionText = "";
33
+ options: BuilderOption[] = [];
34
+ prefix = "";
34
35
 
35
- static create = (type: BuilderQuestionType) => {
36
- const id = BuilderObjectId.questionId();
36
+ static create = (type: BuilderQuestionType) => {
37
+ const id = QuestionID.create();
37
38
 
38
- return new BuilderQuestion({
39
- id,
40
- _type: type,
41
- text: "",
42
- options: [],
43
- prefix: "",
44
- });
45
- };
39
+ return new BuilderQuestion({
40
+ id,
41
+ _type: type,
42
+ text: "",
43
+ options: [],
44
+ prefix: "",
45
+ });
46
+ };
46
47
 
47
- public static fromJson(dto: BuilderQuestionDto): BuilderQuestion {
48
- const question = new BuilderQuestion(dto);
49
- return question;
50
- }
48
+ public static fromJson(dto: BuilderQuestionDto): BuilderQuestion {
49
+ const question = new BuilderQuestion(dto);
50
+ return question;
51
+ }
51
52
 
52
- private constructor(dto: BuilderQuestionDto) {
53
- super(dto);
54
- this.id = dto.id as BuilderObjectId.QuestionID;
55
- this.type = dto._type;
56
- this.questionText = dto.text;
57
- this.prefix = dto.prefix;
58
- this.options = dto.options.map((o) => BuilderOption.fromJson(o));
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
- addOption(label: string, value: number, atIndex = -1) {
62
- const option = BuilderOption.create(value, label);
63
- if (atIndex >= 0 && atIndex < this.options.length) {
64
- this.options.splice(atIndex, 0, option);
65
- } else {
66
- this.options.push(option);
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
- deleteOption(option: BuilderOption): boolean {
72
- const filtered = this.options.filter((o) => o.id !== option.id);
73
- const didDelete = filtered.length === this.options.length - 1;
74
- this.options = filtered;
75
- return didDelete;
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
- toJson() {
79
- const optionsJson = this.options.map((o) => o.toJson());
80
- const dto: BuilderQuestionDto = {
81
- id: this.id,
82
- prefix: this.prefix,
83
- _type: this.type,
84
- text: this.questionText,
85
- options: optionsJson,
86
- };
87
- return dto;
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
- clone(): BuilderQuestionDto {
91
- const cloneId = BuilderObjectId.questionId();
92
- const dto = this.toJson();
93
- const optionsClone = this.options.map((o) => o.clone());
94
- const clonedDto: BuilderQuestionDto = {
95
- ...dto,
96
- id: cloneId,
97
- options: optionsClone,
98
- };
99
- return clonedDto;
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
- import { SumScoreVariable } from "./variable/sum-score";
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
- kind: "numeric-variable",
28
- origin: "sum-score",
29
- label: "label for dummy variable",
30
- initialValue: 0,
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.ensure("a".repeat(24)),
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 BuilderObjectId.QuestionOptionID,
47
+ id: "next-button-text-id" as OptionID,
49
48
  label: "Neste",
50
49
  value: -1,
51
50
  },
52
51
  defaultQuestion: {
53
- id: "q1" as BuilderObjectId.QuestionID,
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 BuilderObjectId.QuestionOptionID,
58
+ id: "opt-nei" as OptionID,
60
59
  value: 0,
61
60
  label: "Nei",
62
61
  },
63
62
  {
64
- id: "opt-ja" as BuilderObjectId.QuestionOptionID,
63
+ id: "opt-ja" as OptionID,
65
64
  value: 1,
66
65
  label: "Ja",
67
66
  },
68
67
  {
69
- id: "opt-vet-ikke" as BuilderObjectId.QuestionOptionID,
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.ensure("b".repeat(24)),
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 BuilderObjectId.QuestionOptionID,
94
+ id: "next-button-id-page2" as OptionID,
97
95
  label: "Neste",
98
96
  value: -1,
99
97
  },
100
98
  defaultQuestion: {
101
- id: "default-q" as BuilderObjectId.QuestionID,
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 schemaPrefixA = SchemaPrefix.castOrCreateRandom("a").value;
142
- let builderSchema = BuilderSchema.create(SCHEMA_ID, "test", schemaPrefixA);
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
- builderSchema = BuilderSchema.create(SCHEMA_ID, "test-name", schemaPrefixA);
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
- builderSchema.addPage("question");
151
- builderSchema.addPage("info-page");
152
- expect(builderSchema.pages.length).toBe(2);
153
- const dto = builderSchema.compile().schema;
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(builderSchema.id);
156
- expect(dto.baseHeight).toBe(builderSchema.baseHeight);
157
- expect(dto.baseWidth).toBe(builderSchema.baseWidth);
158
- expect(dto.backgroundColor).toBe(builderSchema.backgroundColor);
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 = 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);
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 = builderSchema.deletePage(p2);
142
+ const result2 = s1.deletePage(p2);
170
143
  expect(result2).toBe(true);
171
- expect(builderSchema.pages.length).toBe(1);
172
- expect(builderSchema.pages[0]).toBe(p3);
173
- const result3 = builderSchema.deletePage(p2);
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 = builderSchema.deletePage(p3);
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 = builderSchema.addPage("form");
183
+ const p1 = s1.addPage("form");
210
184
  expect(p1.pageType).toBe("form");
211
- const p2 = builderSchema.addPage("multi-select", 0);
185
+ const p2 = s1.addPage("multi-select", 0);
212
186
  expect(p2.pageType).toBe("multi-select");
213
- const pages = builderSchema.pages;
187
+ const pages = s1.pages;
214
188
  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);
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 = 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);
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(builderSchema.movePage(p4, 4)).toBeTruthy();
233
- expect(builderSchema.movePage(p4, 5)).toBeFalsy();
234
- expect(builderSchema.movePage(p4, 10)).toBeFalsy();
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 = builderSchema.addPage("form");
240
- const p2 = builderSchema.addPage("form");
241
- const p3 = builderSchema.addPage("form");
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 = builderSchema.addPage("multi-select");
219
+ const p4 = s1.addPage("multi-select");
244
220
  p3.mainText.text = mainTextContent;
245
221
  const p1Clone = BuilderPage.fromJson(p1.clone());
246
- const beforeLen = builderSchema.pages.length;
247
- builderSchema.insertPage(p1Clone, 2);
248
- const pages = builderSchema.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 = 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;
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 = builderSchema.addPage("info-page");
265
- const p2 = builderSchema.addPage("question");
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
- builderSchema.backgroundColor = "red";
270
- builderSchema.baseHeight = 600;
271
- builderSchema.baseWidth = 500;
246
+ s1.backgroundColor = "red";
247
+ s1.baseHeight = 600;
248
+ s1.baseWidth = 500;
272
249
  // builderSchema.prefix = "as";
273
- builderSchema.name = "depressed";
274
- const schema = builderSchema.compile().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 = builderSchema.addPage("info-page");
267
+ const p0 = s1.addPage("info-page");
291
268
  // p0.prefix = "info_page_prefix_";
292
- const p1 = builderSchema.addPage("question");
269
+ const p1 = s1.addPage("question");
293
270
  // p1.prefix = "p1_prefix_";
294
- const p2 = builderSchema.addPage("question");
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 = builderSchema.getRuleInput();
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
- test.skip("Can add sum-variables - and save as json", () => {
294
+
295
+ test("Can add sum-variables, but not twice", () => {
318
296
  // p0.prefix = "info_page_prefix_";
319
- const p1 = builderSchema.addPage("question");
320
- const p2 = builderSchema.addPage("question");
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 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",
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
- builderSchema.addSumScoreVariable(ss1);
310
+ s1.addSumScoreVariable(ss1);
311
+ s1.addSumScoreVariable(ss1);
339
312
 
340
- expect(ruleInput.questionVars.length).toBe(2);
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);