@media-quest/builder 0.0.6 → 0.0.8

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,3 +1,5 @@
1
+ import { PagePrefix, VarID, SchemaPrefix } from "../prefix";
2
+
1
3
  const BuilderVariableType = {
2
4
  numericWithOptions: true,
3
5
  numeric: true,
@@ -23,7 +25,9 @@ export class QuestionVariable {
23
25
  readonly kind: "question-variable" = "question-variable";
24
26
  readonly dataType: BuilderVariableType = "numericWithOptions";
25
27
  constructor(
26
- readonly varId: string,
28
+ // private schemaPrefix: SchemaPrefix,
29
+ // private pagePrefix: PagePrefix,
30
+ readonly varId: VarID,
27
31
  readonly label: string,
28
32
  readonly options: ReadonlyArray<BuilderVariableOption>,
29
33
  readonly pageNumber: number,
@@ -34,7 +38,7 @@ export class CustomVariable {
34
38
  readonly kind: "configuration-variable" = "configuration-variable";
35
39
  readonly dataType: BuilderVariableType = "numericWithOptions";
36
40
  constructor(
37
- readonly varId: string,
41
+ readonly varId: VarID,
38
42
  readonly label: string,
39
43
  readonly options: ReadonlyArray<BuilderVariableOption>,
40
44
  ) {}
@@ -82,7 +82,7 @@ export class BuilderConditionGroup extends BuilderObject<"builder-condition-grou
82
82
  };
83
83
  }
84
84
 
85
- toEngineConditionComplex(modulePrefix: string): Condition.Complex | false {
85
+ toEngineConditionComplex(): Condition.Complex | false {
86
86
  const comp: Condition.Complex = {
87
87
  kind: "complex-condition",
88
88
  all: [],
@@ -91,7 +91,7 @@ export class BuilderConditionGroup extends BuilderObject<"builder-condition-grou
91
91
  };
92
92
  const conditions: Condition.Simple[] = [];
93
93
  this.conditions.forEach((c) => {
94
- const maybeSimple = c.toEngineCondition(modulePrefix);
94
+ const maybeSimple = c.toEngineCondition();
95
95
  if (maybeSimple) {
96
96
  conditions.push(maybeSimple);
97
97
  }
@@ -2,6 +2,7 @@ import { BuilderCondition, type BuilderConditionDto } from "./Builder-condition"
2
2
  import { RuleBuilderTestUtils } from "../RuleBuilder-test-utils";
3
3
  import type { BuilderVariable, BuilderVariableOption } from "../RuleVariable";
4
4
  import { QuestionVariable } from "../RuleVariable";
5
+ import { SchemaPrefix } from "../../prefix";
5
6
 
6
7
  let condition = BuilderCondition.create([]);
7
8
 
@@ -9,13 +10,15 @@ beforeEach(() => {
9
10
  condition = BuilderCondition.create([]);
10
11
  });
11
12
 
13
+ const as = SchemaPrefix.fromValueOrThrow("as");
14
+
12
15
  describe("Builder Operator", () => {
13
16
  test("Can create", () => {
14
17
  expect(condition).toBeInstanceOf(BuilderCondition);
15
18
  });
16
19
  test("Can resolve dto from Variables in universe.", () => {
17
- const vs = RuleBuilderTestUtils.createBuilderVariables_A_H();
18
- const a = vs[0];
20
+ const vs = RuleBuilderTestUtils.createPagesAndVars_A_H(as);
21
+ const a = vs.items.a;
19
22
  const dto: BuilderConditionDto = {
20
23
  kind: "condition",
21
24
  name: "a",
@@ -23,15 +26,15 @@ describe("Builder Operator", () => {
23
26
  operator: "equal",
24
27
  value: 1,
25
28
  };
26
- const c = BuilderCondition.fromDto(dto, vs);
29
+ const c = BuilderCondition.fromDto(dto, vs.list);
27
30
  // c.setVariableList(vs);
28
31
  expect(c.operatorsSelectItems.length).toBe(2);
29
32
  expect(c.operator === "equal").toBe(true);
30
33
  expect(c.value).toBeTruthy();
31
34
  });
32
35
  test("Can not resolve value if invalid value", () => {
33
- const vs = RuleBuilderTestUtils.createBuilderVariables_A_H();
34
- const a = vs[0];
36
+ const vs = RuleBuilderTestUtils.createPagesAndVars_A_H(as);
37
+ const a = vs.items.a;
35
38
  const dto: BuilderConditionDto = {
36
39
  kind: "condition",
37
40
  name: "a",
@@ -39,14 +42,14 @@ describe("Builder Operator", () => {
39
42
  operator: "equal",
40
43
  value: 8,
41
44
  };
42
- const c = BuilderCondition.fromDto(dto, vs);
45
+ const c = BuilderCondition.fromDto(dto, vs.list);
43
46
  expect(c.operatorsSelectItems.length).toBe(2);
44
47
  expect(c.value).toBe(false);
45
48
  // expect(match).toBe(false);
46
49
  });
47
50
  test("Will nullify dto if not matchedFrom is called", () => {
48
- const vs = RuleBuilderTestUtils.createBuilderVariables_A_H();
49
- const a = vs[0];
51
+ const vs = RuleBuilderTestUtils.createPagesAndVars_A_H(as);
52
+ const a = vs.items.a;
50
53
  const dto: BuilderConditionDto = {
51
54
  kind: "condition",
52
55
  name: "a",
@@ -63,8 +66,8 @@ describe("Builder Operator", () => {
63
66
  // expect(match).toBe(false);
64
67
  });
65
68
  test("Will not nullify if created with valid universe", () => {
66
- const vs = RuleBuilderTestUtils.createBuilderVariables_A_H();
67
- const a = vs[0];
69
+ const vs = RuleBuilderTestUtils.createPagesAndVars_A_H(as);
70
+ const a = vs.items.a;
68
71
  const dto: BuilderConditionDto = {
69
72
  kind: "condition",
70
73
  name: "a",
@@ -72,7 +75,7 @@ describe("Builder Operator", () => {
72
75
  operator: "equal",
73
76
  value: 0,
74
77
  };
75
- const c = BuilderCondition.fromDto(dto, vs);
78
+ const c = BuilderCondition.fromDto(dto, vs.list);
76
79
  expect(c.variable).toBeInstanceOf(QuestionVariable);
77
80
  expect(c.operator === "equal").toBe(true);
78
81
  const value = c.value as BuilderVariableOption;
@@ -81,8 +84,8 @@ describe("Builder Operator", () => {
81
84
  expect(c.variable).toBe(a);
82
85
  });
83
86
  test("Condition is valid, when in sync with universe.", () => {
84
- const vs = RuleBuilderTestUtils.createBuilderVariables_A_H();
85
- const a = vs[0];
87
+ const vs = RuleBuilderTestUtils.createPagesAndVars_A_H(as);
88
+ const a = vs.items.a;
86
89
  const dto: BuilderConditionDto = {
87
90
  kind: "condition",
88
91
 
@@ -91,7 +94,7 @@ describe("Builder Operator", () => {
91
94
  operator: "equal",
92
95
  value: 0,
93
96
  };
94
- const c = BuilderCondition.fromDto(dto, vs);
97
+ const c = BuilderCondition.fromDto(dto, vs.list);
95
98
  expect(c.variable).toBeInstanceOf(QuestionVariable);
96
99
  expect(c.operator === "equal").toBe(true);
97
100
  const value = c.value as BuilderVariableOption;
@@ -111,7 +114,7 @@ describe("Builder Operator", () => {
111
114
  expect(c.validate().isValid).toBe(false);
112
115
  });
113
116
  test("Condition is invalid, when variable dont exist in universe.", () => {
114
- const universe = RuleBuilderTestUtils.createBuilderVariables_A_H();
117
+ const variables = RuleBuilderTestUtils.createPagesAndVars_A_H(as);
115
118
  const dto: BuilderConditionDto = {
116
119
  kind: "condition",
117
120
  name: "invalid variable name in dto",
@@ -119,12 +122,12 @@ describe("Builder Operator", () => {
119
122
  operator: "equal",
120
123
  value: 9,
121
124
  };
122
- const c = BuilderCondition.fromDto(dto, universe);
125
+ const c = BuilderCondition.fromDto(dto, variables.list);
123
126
  expect(c.variable).toBe(false);
124
127
  expect(c.validate().isValid).toBe(false);
125
128
  });
126
- test("Condition is invalid if not all set, when variable dont exist in universe.", () => {
127
- const universe = RuleBuilderTestUtils.createBuilderVariables_A_H();
129
+ test("Condition is invalid if not all set, when variable dont exist in variables.", () => {
130
+ const variables = RuleBuilderTestUtils.createPagesAndVars_A_H(as);
128
131
  const dto: BuilderConditionDto = {
129
132
  kind: "condition",
130
133
  name: "invalid variable name in dto",
@@ -132,34 +135,39 @@ describe("Builder Operator", () => {
132
135
  operator: "equal",
133
136
  value: 9,
134
137
  };
135
- const c = BuilderCondition.fromDto(dto, universe);
138
+ const c = BuilderCondition.fromDto(dto, variables.list);
136
139
  expect(c.variable).toBe(false);
137
140
  expect(c.validate().isValid).toBe(false);
138
141
  });
142
+
139
143
  test("Condition is invalid if operator is not set", () => {
140
- const universe = RuleBuilderTestUtils.createBuilderVariables_A_H();
144
+ const variables = RuleBuilderTestUtils.createPagesAndVars_A_H(as);
145
+ const a = variables.items.a;
141
146
  const dto: BuilderConditionDto = {
142
147
  kind: "condition",
143
148
  name: "invalid variable name in dto",
144
- variableId: "a",
149
+ variableId: a.varId,
145
150
  operator: "",
146
151
  value: 1,
147
152
  };
148
- const c = BuilderCondition.fromDto(dto, universe);
153
+ expect(a.varId).toBe("as_a");
154
+ const c = BuilderCondition.fromDto(dto, variables.list);
149
155
  expect(c.variable).toBeInstanceOf(QuestionVariable);
150
156
  expect(c.validate().isValid).toBe(false);
151
157
  expect(c.value).toBe(false);
152
158
  });
153
159
  test("Condition is invalid if value (from dto) is not found in variable", () => {
154
- const universe = RuleBuilderTestUtils.createBuilderVariables_A_H();
160
+ const { list, items } = RuleBuilderTestUtils.createPagesAndVars_A_H(as);
161
+ expect(items.a.varId).toBe("as_a");
155
162
  const dto: BuilderConditionDto = {
156
163
  kind: "condition",
157
164
  name: "invalid variable name in dto",
158
- variableId: "a",
165
+ variableId: items.a.varId,
159
166
  operator: "equal",
160
- value: 7,
167
+ value: 42,
161
168
  };
162
- const c = BuilderCondition.fromDto(dto, universe);
169
+ const c = BuilderCondition.fromDto(dto, list);
170
+ expect(c).toBeInstanceOf(BuilderCondition);
163
171
  expect(c.variable).toBeInstanceOf(QuestionVariable);
164
172
  expect(c.operator).toBe("equal");
165
173
  expect(c.operatorsSelectItems.length).toBe(BuilderCondition.NUMBER_OPERATORS.length);
@@ -167,15 +175,16 @@ describe("Builder Operator", () => {
167
175
  expect(c.validate().isValid).toBe(false);
168
176
  });
169
177
  test("toEngineConditionWorks", () => {
170
- const universe = RuleBuilderTestUtils.createBuilderVariables_A_H();
178
+ const variables = RuleBuilderTestUtils.createPagesAndVars_A_H(as);
179
+
171
180
  const dto: BuilderConditionDto = {
172
181
  kind: "condition",
173
182
  name: "invalid variable name in dto",
174
- variableId: "a",
183
+ variableId: variables.items.a.varId,
175
184
  operator: "equal",
176
185
  value: 7,
177
186
  };
178
- const c = BuilderCondition.fromDto(dto, universe);
187
+ const c = BuilderCondition.fromDto(dto, variables.list);
179
188
  expect(c.variable).toBeInstanceOf(QuestionVariable);
180
189
  expect(c.operator).toBe("equal");
181
190
  expect(c.operatorsSelectItems.length).toBe(BuilderCondition.NUMBER_OPERATORS.length);
@@ -103,7 +103,7 @@ export class BuilderCondition extends BuilderObject<"builder-condition", Builder
103
103
  return { isValid: true };
104
104
  }
105
105
 
106
- toEngineCondition(modulePrefix: string): Condition.Simple | false {
106
+ toEngineCondition(): Condition.Simple | false {
107
107
  const val = this.value;
108
108
  const op = this._operator;
109
109
  const v = this._variable;
@@ -115,7 +115,7 @@ export class BuilderCondition extends BuilderObject<"builder-condition", Builder
115
115
  kind: "numeric-condition",
116
116
  value: val.value,
117
117
  valueLabel: val.label,
118
- referenceId: modulePrefix + "_" + v.varId,
118
+ referenceId: v.varId,
119
119
  referenceLabel: v.label,
120
120
  operator: "eq",
121
121
  };
@@ -122,11 +122,11 @@ export const DefaultTheme: IDefaultTheme = {
122
122
  text: {
123
123
  css: {
124
124
  w: 80,
125
- y: 27,
125
+ y: 65,
126
126
  x: 10,
127
127
  textAlign: "center",
128
128
  textColor: "black",
129
- fontSize: { _unit: "px", value: 30 },
129
+ fontSize: { _unit: "px", value: 40 },
130
130
  },
131
131
  cssDisabled: {},
132
132
  cssEnabled: {},
@@ -40,7 +40,7 @@ export class DefaultThemeCompiler extends AbstractThemeCompiler<IDefaultTheme> {
40
40
  const ruleInput = builderSchema.getRuleInput();
41
41
  const pageQueRules: Rule<PageQueCommand, never>[] = [];
42
42
  source.rules.forEach((rule) => {
43
- const engineRule = BuilderRule.fromDto(rule, ruleInput).toEngineRule(source.prefix);
43
+ const engineRule = BuilderRule.fromDto(rule, ruleInput).toEngineRule();
44
44
  if (!Rule.isEmpty(engineRule)) {
45
45
  pageQueRules.push(engineRule);
46
46
  } else {
@@ -56,7 +56,7 @@ export class DefaultThemeCompiler extends AbstractThemeCompiler<IDefaultTheme> {
56
56
  compile(source: BuilderSchemaDto): SchemaDto {
57
57
  const pages = source.pages.map((p) => this.compilePage(p, source.prefix));
58
58
  const rules = this.compileRules(source);
59
- console.log(pages.map((p) => p.tags));
59
+ // console.log(pages.map((p) => p.tags));
60
60
 
61
61
  const dto: SchemaDto = {
62
62
  backgroundColor: source.backgroundColor,
@@ -66,7 +66,6 @@ export class DefaultThemeCompiler extends AbstractThemeCompiler<IDefaultTheme> {
66
66
  pageSequences: [],
67
67
  pages,
68
68
  predefinedFacts: [],
69
- prefix: source.prefix,
70
69
  rules,
71
70
  stateFromEvent: [
72
71
  {
@@ -148,11 +147,12 @@ export class DefaultThemeCompiler extends AbstractThemeCompiler<IDefaultTheme> {
148
147
  const nextBtnElement: DElementDto = this.compileButton(id, nextButton, {
149
148
  kind: "next-button",
150
149
  });
150
+ const textStyle = mainMedia ? DefaultTheme.mainText.withMedia.text.css : DefaultTheme.mainText.noMedia.text.css;
151
151
  const element: DElementDto = {
152
152
  text: infoText,
153
153
  _tag: "p",
154
154
  id: generateElementId(),
155
- style: DefaultTheme.mainText.withMedia.text.css,
155
+ style: textStyle,
156
156
  };
157
157
  elements.push(element);
158
158
  elements.push(nextBtnElement);
@@ -161,6 +161,7 @@ export class DefaultThemeCompiler extends AbstractThemeCompiler<IDefaultTheme> {
161
161
  const mainImageElement = this.compileImage(mainMedia);
162
162
  elements.push(mainImageElement);
163
163
  }
164
+
164
165
  if (mainMedia && mainMedia.kind === "main-video") {
165
166
  const videoOutput = this.compileVideo(mainMedia);
166
167
  mainVideo = videoOutput.videoDto;
@@ -343,7 +344,9 @@ export class DefaultThemeCompiler extends AbstractThemeCompiler<IDefaultTheme> {
343
344
  // console.log(page);
344
345
  const q = page.defaultQuestion;
345
346
  const text = page.mainText.text;
346
-
347
+ const questionStyle = page.mainMedia
348
+ ? DefaultTheme.mainText.withMedia.text.css
349
+ : DefaultTheme.mainText.noMedia.text.css;
347
350
  const question: DTextDto = {
348
351
  _tag: "p",
349
352
  text,
@@ -351,7 +354,7 @@ export class DefaultThemeCompiler extends AbstractThemeCompiler<IDefaultTheme> {
351
354
  id: U.randomString(30),
352
355
  onClick: [],
353
356
  onStateChange: [],
354
- style: DefaultTheme.mainText.withMedia.text.css,
357
+ style: questionStyle,
355
358
  };
356
359
  const buttons = q.options.map((o) => {
357
360
  const btns = this.compileButton(pageId, o, {