@media-quest/builder 0.0.1 → 0.0.2
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/dist/public-api.d.mts +634 -0
- package/dist/public-api.d.ts +634 -0
- package/dist/public-api.js +2161 -0
- package/dist/public-api.mjs +2129 -0
- package/package.json +12 -3
- package/src/Builder-option.ts +67 -0
- package/src/Builder-page.spec.ts +313 -0
- package/src/Builder-page.ts +249 -0
- package/src/Builder-question.spec.ts +68 -0
- package/src/Builder-question.ts +101 -0
- package/src/Builder-schema.spec.ts +302 -0
- package/src/Builder-schema.ts +250 -0
- package/src/Builder-text.spec.ts +24 -0
- package/src/Builder-text.ts +57 -0
- package/src/BuilderMainImageDto.ts +7 -0
- package/src/BuilderMainText.ts +81 -0
- package/src/BuilderMainVideoDto.ts +10 -0
- package/src/BuilderObject.ts +69 -0
- package/src/BuilderTag.ts +97 -0
- package/src/media-files.ts +28 -0
- package/src/public-api.ts +10 -6
- package/src/rulebuilder/Builder-condition-group.spec.ts +47 -0
- package/src/rulebuilder/Builder-condition-group.ts +109 -0
- package/src/rulebuilder/Builder-condition.spec.ts +169 -0
- package/src/rulebuilder/Builder-condition.ts +186 -0
- package/src/rulebuilder/Builder-operator.spec.ts +9 -0
- package/src/rulebuilder/Builder-operator.ts +31 -0
- package/src/rulebuilder/Builder-rule.spec.ts +207 -0
- package/src/rulebuilder/Builder-rule.ts +165 -0
- package/src/rulebuilder/RuleAction.ts +20 -0
- package/src/rulebuilder/RuleBuilder-test-utils.ts +254 -0
- package/src/rulebuilder/RuleInput.ts +44 -0
- package/src/rulebuilder/RuleVariable.ts +39 -0
- package/src/rulebuilder/SingleSelectItem.ts +135 -0
- package/src/rulebuilder/index.ts +22 -0
- package/src/rulebuilder/jump-to-action-manager.ts +33 -0
- package/src/rulebuilder/multi-select-item.ts +70 -0
- package/src/rulebuilder/page-action-manager.ts +20 -0
- package/src/rulebuilder/tag-action-manager.spec.ts +44 -0
- package/src/rulebuilder/tag-action-manager.ts +18 -0
- package/src/theme/AbstractThemeCompiler.ts +7 -0
- package/src/theme/IDefaultTheme.ts +178 -0
- package/src/theme/css-theme.ts +7 -0
- package/src/theme/default-theme-compiler.ts +395 -0
- package/src/theme/icon-urls.ts +29 -0
- package/src/theme/standard-props.ts +113 -0
- package/src/theme/theme-utils.ts +110 -0
- package/src/theme/theme1.spec.ts +52 -0
- package/tsconfig.json +0 -2
|
@@ -0,0 +1,207 @@
|
|
|
1
|
+
import { BuilderRule, type BuilderRuleDto } from "./Builder-rule";
|
|
2
|
+
import { RuleBuilderTestUtils as U } from "./RuleBuilder-test-utils";
|
|
3
|
+
import { RuleInput } from "./RuleInput";
|
|
4
|
+
import type { BuilderConditionGroupDto } from "./Builder-condition-group";
|
|
5
|
+
|
|
6
|
+
const { createBuilderVariables_A_H } = U;
|
|
7
|
+
let questionVariables = createBuilderVariables_A_H();
|
|
8
|
+
const createDto = (): {
|
|
9
|
+
ruleInput: RuleInput;
|
|
10
|
+
builderRuleDto: BuilderRuleDto;
|
|
11
|
+
} => {
|
|
12
|
+
const v1 = U.createRuleVariable("v1", 2);
|
|
13
|
+
const v2 = U.createRuleVariable("v2", 2);
|
|
14
|
+
const v3 = U.createRuleVariable("v3", 2);
|
|
15
|
+
const v4 = U.createRuleVariable("v4", 2);
|
|
16
|
+
const vg1 = U.createRuleVariable("vg1", 2);
|
|
17
|
+
const vg2 = U.createRuleVariable("vg2", 2);
|
|
18
|
+
const vg3 = U.createRuleVariable("vg3", 2);
|
|
19
|
+
const vg4 = U.createRuleVariable("vg4", 2);
|
|
20
|
+
const variableList = [v1, v2, v3, v4, vg1, vg2, vg3, vg4];
|
|
21
|
+
const tagAction1 = U.excludeByTagAction("tag1");
|
|
22
|
+
const tagAction2 = U.excludeByTagAction("tag2");
|
|
23
|
+
const tagAction3 = U.excludeByTagAction("tag3");
|
|
24
|
+
const tagAction4 = U.excludeByTagAction("tag4");
|
|
25
|
+
const pageAction1 = U.excludeByPageIdAction(v1.varId);
|
|
26
|
+
const pageAction2 = U.excludeByPageIdAction(v2.varId);
|
|
27
|
+
const pageAction3 = U.excludeByPageIdAction(v3.varId);
|
|
28
|
+
const pageAction4 = U.excludeByPageIdAction(v4.varId);
|
|
29
|
+
|
|
30
|
+
// const pageAction =
|
|
31
|
+
// const excludeByTagList = [];
|
|
32
|
+
const ruleInput = new RuleInput(
|
|
33
|
+
variableList,
|
|
34
|
+
[],
|
|
35
|
+
[pageAction1, pageAction2, pageAction3, pageAction4],
|
|
36
|
+
[tagAction1, tagAction2, tagAction3, tagAction4],
|
|
37
|
+
[]
|
|
38
|
+
);
|
|
39
|
+
const c1 = U.createConditionDto(v1);
|
|
40
|
+
const c2 = U.createConditionDto(v2);
|
|
41
|
+
const c3 = U.createConditionDto(v3);
|
|
42
|
+
const c4 = U.createConditionDto(v4);
|
|
43
|
+
const cg1 = U.createConditionDto(vg1);
|
|
44
|
+
const cg2 = U.createConditionDto(vg2);
|
|
45
|
+
const cg3 = U.createConditionDto(vg3);
|
|
46
|
+
const cg4 = U.createConditionDto(vg4);
|
|
47
|
+
const group3: BuilderConditionGroupDto = {
|
|
48
|
+
kind: "condition-group",
|
|
49
|
+
name: "group3",
|
|
50
|
+
type: "all",
|
|
51
|
+
conditions: [cg1, cg2, cg3, cg4],
|
|
52
|
+
};
|
|
53
|
+
|
|
54
|
+
const builderRuleDto1: BuilderRuleDto = {
|
|
55
|
+
type: "any",
|
|
56
|
+
jumpToPage: false,
|
|
57
|
+
excludePages: [v1.varId, v3.varId],
|
|
58
|
+
excludeTags: [tagAction1.tag, tagAction2.tag],
|
|
59
|
+
name: "kitchen-sink",
|
|
60
|
+
conditions: [c1, c2, group3, c3, c4],
|
|
61
|
+
};
|
|
62
|
+
|
|
63
|
+
return { ruleInput, builderRuleDto: builderRuleDto1 };
|
|
64
|
+
};
|
|
65
|
+
let dto: BuilderRuleDto = {
|
|
66
|
+
name: "test-rule",
|
|
67
|
+
conditions: [],
|
|
68
|
+
type: "all",
|
|
69
|
+
excludePages: [],
|
|
70
|
+
excludeTags: [],
|
|
71
|
+
jumpToPage: false,
|
|
72
|
+
};
|
|
73
|
+
|
|
74
|
+
const excludeByTagActionList = U.excludeByTagActionList();
|
|
75
|
+
const pageActions = questionVariables.map((q) => U.excludeByPageIdAction(q.varId, q.pageNumber));
|
|
76
|
+
let ruleInput = new RuleInput(questionVariables, [], [...pageActions], excludeByTagActionList, []);
|
|
77
|
+
|
|
78
|
+
let rule: BuilderRule = BuilderRule.fromDto(dto, ruleInput);
|
|
79
|
+
|
|
80
|
+
beforeEach(() => {
|
|
81
|
+
rule = BuilderRule.fromDto(dto, ruleInput);
|
|
82
|
+
});
|
|
83
|
+
|
|
84
|
+
describe("Builder Rule", () => {
|
|
85
|
+
test("Can create rule", () => {
|
|
86
|
+
expect(rule).toBeInstanceOf(BuilderRule);
|
|
87
|
+
});
|
|
88
|
+
test("Can add condition", () => {
|
|
89
|
+
rule.addCondition();
|
|
90
|
+
expect(rule.conditions.length).toBe(1);
|
|
91
|
+
});
|
|
92
|
+
test("Can delete condition", () => {
|
|
93
|
+
const r1 = rule.addCondition();
|
|
94
|
+
const r2 = rule.addCondition();
|
|
95
|
+
const r3 = rule.addCondition();
|
|
96
|
+
const r4 = rule.addCondition();
|
|
97
|
+
const r5 = rule.addCondition();
|
|
98
|
+
expect(rule.conditionCount).toBe(5);
|
|
99
|
+
const result = rule.deleteCondition(r3);
|
|
100
|
+
expect(result).toBeTruthy();
|
|
101
|
+
expect(rule.conditionCount).toBe(4);
|
|
102
|
+
expect(rule.conditions[0]).toBe(r1);
|
|
103
|
+
expect(rule.conditions[1]).toBe(r2);
|
|
104
|
+
expect(rule.conditions[2]).toBe(r4);
|
|
105
|
+
expect(rule.conditions[3]).toBe(r5);
|
|
106
|
+
expect(rule.deleteCondition(r3)).toBeFalsy();
|
|
107
|
+
// expect(rule.conditions[0]).toBe(r1);
|
|
108
|
+
});
|
|
109
|
+
test("Can delete condition-group", () => {
|
|
110
|
+
const r1 = rule.addCondition();
|
|
111
|
+
const r2 = rule.addConditionGroup();
|
|
112
|
+
const r3 = rule.addConditionGroup();
|
|
113
|
+
const r4 = rule.addCondition();
|
|
114
|
+
const r5 = rule.addConditionGroup();
|
|
115
|
+
expect(rule.conditionCount).toBe(5);
|
|
116
|
+
const result = rule.deleteCondition(r2);
|
|
117
|
+
expect(result).toBeTruthy();
|
|
118
|
+
expect(rule.conditionCount).toBe(4);
|
|
119
|
+
expect(rule.conditions[0]).toBe(r1);
|
|
120
|
+
expect(rule.conditions[1]).toBe(r3);
|
|
121
|
+
expect(rule.conditions[2]).toBe(r4);
|
|
122
|
+
expect(rule.conditions[3]).toBe(r5);
|
|
123
|
+
expect(rule.deleteCondition(r2)).toBeFalsy();
|
|
124
|
+
expect(rule.deleteCondition(r1)).toBeTruthy();
|
|
125
|
+
expect(rule.deleteCondition(r5)).toBeTruthy();
|
|
126
|
+
expect(rule.conditionCount).toBe(2);
|
|
127
|
+
});
|
|
128
|
+
|
|
129
|
+
test("Conditions have no operators available before variable is set.", () => {
|
|
130
|
+
const c1 = rule.addCondition();
|
|
131
|
+
expect(c1.operatorsSelectItems.length).toBe(0);
|
|
132
|
+
|
|
133
|
+
const a = c1.variableSelectItemsInUniverse[0]?.data ?? false;
|
|
134
|
+
c1.variable = a;
|
|
135
|
+
expect(c1.operatorsSelectItems.length).toBe(2);
|
|
136
|
+
});
|
|
137
|
+
|
|
138
|
+
test("Conditions and actions in dto will exist: ", () => {
|
|
139
|
+
const v1 = ruleInput.questionVars[0];
|
|
140
|
+
const v2 = ruleInput.questionVars[1];
|
|
141
|
+
const tag1 = ruleInput.excludeByTagActions[0];
|
|
142
|
+
const pageAction1 = ruleInput.excludeByPageIdActions[0];
|
|
143
|
+
|
|
144
|
+
const dtoWithOneCondition: BuilderRuleDto = {
|
|
145
|
+
...dto,
|
|
146
|
+
excludePages: [pageAction1.pageId],
|
|
147
|
+
excludeTags: [tag1.tag],
|
|
148
|
+
jumpToPage: v1.varId,
|
|
149
|
+
conditions: [
|
|
150
|
+
{
|
|
151
|
+
kind: "condition",
|
|
152
|
+
name: "condition 1",
|
|
153
|
+
variableId: v1.varId,
|
|
154
|
+
operator: "equal",
|
|
155
|
+
value: v1.options[0].value,
|
|
156
|
+
},
|
|
157
|
+
{
|
|
158
|
+
kind: "condition-group",
|
|
159
|
+
type: "all",
|
|
160
|
+
name: "condtion-grup-from-testing.",
|
|
161
|
+
conditions: [
|
|
162
|
+
{
|
|
163
|
+
name: "nested-condition",
|
|
164
|
+
kind: "condition",
|
|
165
|
+
value: v2.options[0].value,
|
|
166
|
+
operator: "equal",
|
|
167
|
+
variableId: v2.varId,
|
|
168
|
+
},
|
|
169
|
+
],
|
|
170
|
+
},
|
|
171
|
+
],
|
|
172
|
+
};
|
|
173
|
+
|
|
174
|
+
const rule = BuilderRule.fromDto(dtoWithOneCondition, ruleInput);
|
|
175
|
+
// console.log(rule);
|
|
176
|
+
expect(rule.conditions.length).toBe(2);
|
|
177
|
+
const excludeTags = rule.toJson().excludeTags;
|
|
178
|
+
expect(excludeTags.length).toBe(1);
|
|
179
|
+
expect(rule.jumpToActionManager).toBeTruthy();
|
|
180
|
+
});
|
|
181
|
+
|
|
182
|
+
test("fromJSON -> toJSON -> are equal.", () => {
|
|
183
|
+
const data = createDto();
|
|
184
|
+
|
|
185
|
+
const localRule = BuilderRule.fromDto(data.builderRuleDto, data.ruleInput);
|
|
186
|
+
|
|
187
|
+
const json = localRule.toJson();
|
|
188
|
+
expect(data.builderRuleDto).toStrictEqual(json);
|
|
189
|
+
});
|
|
190
|
+
|
|
191
|
+
test("invalid tags will be removed.", () => {
|
|
192
|
+
const ruleInput = new RuleInput([], [], [], U.excludeByTagActionList(), []);
|
|
193
|
+
const dto: BuilderRuleDto = {
|
|
194
|
+
conditions: [],
|
|
195
|
+
excludePages: [],
|
|
196
|
+
excludeTags: ["tag3", "tag1"],
|
|
197
|
+
jumpToPage: false,
|
|
198
|
+
name: "Rule-name-in-test",
|
|
199
|
+
type: "all",
|
|
200
|
+
};
|
|
201
|
+
|
|
202
|
+
const localRule = BuilderRule.fromDto(dto, ruleInput);
|
|
203
|
+
|
|
204
|
+
expect(ruleInput.excludeByTagActions.length).toStrictEqual(10);
|
|
205
|
+
expect(ruleInput.excludeByTagActions.length).toStrictEqual(10);
|
|
206
|
+
});
|
|
207
|
+
});
|
|
@@ -0,0 +1,165 @@
|
|
|
1
|
+
import {
|
|
2
|
+
BuilderCondition,
|
|
3
|
+
type BuilderConditionDto
|
|
4
|
+
} from './Builder-condition';
|
|
5
|
+
import {
|
|
6
|
+
BuilderConditionGroup,
|
|
7
|
+
type BuilderConditionGroupDto,
|
|
8
|
+
type ConditionGroupType
|
|
9
|
+
} from './Builder-condition-group';
|
|
10
|
+
import type { RuleInput } from './RuleInput';
|
|
11
|
+
import { BuilderObject } from '../BuilderObject';
|
|
12
|
+
import { TagActionManager } from './tag-action-manager';
|
|
13
|
+
import { PageActionManager } from './page-action-manager';
|
|
14
|
+
import { JumpToActionManager } from './jump-to-action-manager';
|
|
15
|
+
|
|
16
|
+
export interface BuilderRuleDto {
|
|
17
|
+
readonly type: ConditionGroupType;
|
|
18
|
+
readonly name: string;
|
|
19
|
+
readonly conditions: ReadonlyArray<
|
|
20
|
+
BuilderConditionDto | BuilderConditionGroupDto
|
|
21
|
+
>;
|
|
22
|
+
readonly excludeTags: ReadonlyArray<string>;
|
|
23
|
+
readonly excludePages: ReadonlyArray<string>;
|
|
24
|
+
readonly jumpToPage: string | false;
|
|
25
|
+
}
|
|
26
|
+
export class BuilderRule extends BuilderObject<'builder-rule', BuilderRuleDto> {
|
|
27
|
+
readonly objectType: 'builder-rule' = 'builder-rule';
|
|
28
|
+
private _type: ConditionGroupType = 'all';
|
|
29
|
+
public name = 'Rule name';
|
|
30
|
+
// public countNumber = 1;
|
|
31
|
+
private readonly _conditions: Array<
|
|
32
|
+
BuilderCondition | BuilderConditionGroup
|
|
33
|
+
> = [];
|
|
34
|
+
|
|
35
|
+
private _tagActionManager: TagActionManager;
|
|
36
|
+
private _pageActionManager: PageActionManager;
|
|
37
|
+
readonly jumpToActionManager: JumpToActionManager;
|
|
38
|
+
public static readonly fromDto = (
|
|
39
|
+
dto: BuilderRuleDto,
|
|
40
|
+
input: RuleInput
|
|
41
|
+
): BuilderRule => {
|
|
42
|
+
return new BuilderRule(dto, input);
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
protected constructor(
|
|
46
|
+
private readonly dto: BuilderRuleDto,
|
|
47
|
+
private readonly _ruleInput: RuleInput
|
|
48
|
+
) {
|
|
49
|
+
super(dto);
|
|
50
|
+
const conditionInput = this._ruleInput.getConditionInput();
|
|
51
|
+
this.name = dto.name ?? '';
|
|
52
|
+
this._type = dto.type ?? 'any';
|
|
53
|
+
this._conditions = dto.conditions.reduce<
|
|
54
|
+
Array<BuilderCondition | BuilderConditionGroup>
|
|
55
|
+
>((acc, curr) => {
|
|
56
|
+
if (curr.kind === 'condition') {
|
|
57
|
+
const condition = BuilderCondition.fromDto(curr, conditionInput);
|
|
58
|
+
acc.push(condition);
|
|
59
|
+
}
|
|
60
|
+
if (curr.kind === 'condition-group') {
|
|
61
|
+
const conditionGroup = BuilderConditionGroup.fromDto(
|
|
62
|
+
curr,
|
|
63
|
+
conditionInput
|
|
64
|
+
);
|
|
65
|
+
acc.push(conditionGroup);
|
|
66
|
+
}
|
|
67
|
+
return acc;
|
|
68
|
+
}, []);
|
|
69
|
+
// TODO CHECK WITH CURRENT OPTIONS.
|
|
70
|
+
this._pageActionManager = new PageActionManager(
|
|
71
|
+
_ruleInput.excludeByPageIdActions,
|
|
72
|
+
dto.excludePages
|
|
73
|
+
);
|
|
74
|
+
// this.excludeByPageIdDtoList.push(...dto.excludePages);
|
|
75
|
+
this._tagActionManager = new TagActionManager(
|
|
76
|
+
_ruleInput.excludeByTagActions,
|
|
77
|
+
dto.excludeTags
|
|
78
|
+
);
|
|
79
|
+
|
|
80
|
+
this.jumpToActionManager = new JumpToActionManager(
|
|
81
|
+
_ruleInput.jumpToPageActions,
|
|
82
|
+
dto.jumpToPage
|
|
83
|
+
);
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
get conditions(): ReadonlyArray<BuilderConditionGroup | BuilderCondition> {
|
|
87
|
+
return this._conditions;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
getTagActions() {
|
|
91
|
+
return this._tagActionManager.selectItems;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
getValidPageActions() {
|
|
95
|
+
return this._pageActionManager.selectItems;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
get conditionCount() {
|
|
99
|
+
return this._conditions.length;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
set type(type: ConditionGroupType) {
|
|
103
|
+
if (BuilderConditionGroup.isConditionGroupType(type)) {
|
|
104
|
+
this._type = type;
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
get type() {
|
|
109
|
+
return this._type;
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
deleteCondition(
|
|
113
|
+
condition: BuilderCondition | BuilderConditionGroup
|
|
114
|
+
): boolean {
|
|
115
|
+
const index = this._conditions.indexOf(condition);
|
|
116
|
+
if (index < 0) {
|
|
117
|
+
return false;
|
|
118
|
+
}
|
|
119
|
+
this._conditions.splice(index, 1);
|
|
120
|
+
return true;
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
addCondition(): BuilderCondition {
|
|
124
|
+
const condition = BuilderCondition.create(
|
|
125
|
+
this._ruleInput.getConditionInput()
|
|
126
|
+
);
|
|
127
|
+
this._conditions.push(condition);
|
|
128
|
+
return condition;
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
addConditionGroup(): BuilderConditionGroup {
|
|
132
|
+
const dto: BuilderConditionGroupDto = {
|
|
133
|
+
kind: 'condition-group',
|
|
134
|
+
name: '',
|
|
135
|
+
type: 'all',
|
|
136
|
+
conditions: []
|
|
137
|
+
};
|
|
138
|
+
const newGroup = BuilderConditionGroup.fromDto(
|
|
139
|
+
dto,
|
|
140
|
+
this._ruleInput.questionVars
|
|
141
|
+
);
|
|
142
|
+
this._conditions.push(newGroup);
|
|
143
|
+
return newGroup;
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
clone(): BuilderRuleDto {
|
|
147
|
+
return this.toJson();
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
toJson(): BuilderRuleDto {
|
|
151
|
+
const conditions = this._conditions.map(c => c.toJson());
|
|
152
|
+
const excludePages = this._pageActionManager.getCurrentSelection();
|
|
153
|
+
const excludeTags = this._tagActionManager.getCurrentSelection();
|
|
154
|
+
const jumpToPage = this.jumpToActionManager.getSelectedPageId();
|
|
155
|
+
const dto: BuilderRuleDto = {
|
|
156
|
+
type: this._type,
|
|
157
|
+
name: this.name,
|
|
158
|
+
conditions,
|
|
159
|
+
excludePages,
|
|
160
|
+
jumpToPage,
|
|
161
|
+
excludeTags
|
|
162
|
+
};
|
|
163
|
+
return dto;
|
|
164
|
+
}
|
|
165
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
export interface ExcludeByPageAction {
|
|
2
|
+
readonly kind: 'exclude-by-pageId';
|
|
3
|
+
readonly pageId: string;
|
|
4
|
+
readonly mainText: string;
|
|
5
|
+
readonly pageNumber: number;
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
export interface JumpToPageAction {
|
|
9
|
+
readonly kind: 'jump-to-page';
|
|
10
|
+
readonly pageId: string;
|
|
11
|
+
readonly mainText: string;
|
|
12
|
+
readonly pageNumber: number;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export interface ExcludeByTagAction {
|
|
16
|
+
readonly kind: 'exclude-by-tag';
|
|
17
|
+
readonly tag: string;
|
|
18
|
+
readonly description: string;
|
|
19
|
+
readonly pageCount: number;
|
|
20
|
+
}
|
|
@@ -0,0 +1,254 @@
|
|
|
1
|
+
import { BuilderOption } from "../Builder-option";
|
|
2
|
+
import { type BuilderVariable, QuestionVariable } from "./RuleVariable";
|
|
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";
|
|
7
|
+
import type { ExcludeByPageAction, ExcludeByTagAction } from "./RuleAction";
|
|
8
|
+
import { ExcludeByPageIdSelectItem, ExcludeByTagSelectItem } from "./multi-select-item";
|
|
9
|
+
|
|
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
|
+
];
|
|
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;
|
|
26
|
+
};
|
|
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;
|
|
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
|
+
|
|
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
|
+
|
|
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
|
+
};
|
|
78
|
+
};
|
|
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
|
+
};
|
|
87
|
+
};
|
|
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 [];
|
|
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
|
+
|
|
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
|
+
|
|
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
|
+
|
|
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
|
+
|
|
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
|
+
|
|
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
|
+
|
|
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
|
+
|
|
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
|
+
|
|
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
|
+
}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import type { QuestionVariable, CustomVariable, BuilderVariable } from "./RuleVariable";
|
|
2
|
+
import type { ExcludeByPageAction, ExcludeByTagAction, JumpToPageAction } from "./RuleAction";
|
|
3
|
+
import { JumpToPageSelectItem } from "./SingleSelectItem";
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* TODO Crate filters for "cardinality" or "order" of a variable;
|
|
7
|
+
* Return legal lists of variables.
|
|
8
|
+
*/
|
|
9
|
+
export class RuleInput {
|
|
10
|
+
constructor(
|
|
11
|
+
private readonly _questionVariables: ReadonlyArray<QuestionVariable>,
|
|
12
|
+
private readonly _customVariables: ReadonlyArray<CustomVariable>,
|
|
13
|
+
private readonly _pageIdActions: ReadonlyArray<ExcludeByPageAction>,
|
|
14
|
+
private readonly _tagActions: ReadonlyArray<ExcludeByTagAction>,
|
|
15
|
+
private readonly _jumpActions: ReadonlyArray<JumpToPageAction>
|
|
16
|
+
) {}
|
|
17
|
+
|
|
18
|
+
get questionVars(): ReadonlyArray<QuestionVariable> {
|
|
19
|
+
return this._questionVariables;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
getConditionInput(): ReadonlyArray<BuilderVariable> {
|
|
23
|
+
return [...this.questionVars, ...this.customVars];
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
getJumpToPageOptions(): ReadonlyArray<JumpToPageSelectItem> {
|
|
27
|
+
return this._jumpActions.map(JumpToPageSelectItem.create);
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
get customVars(): ReadonlyArray<CustomVariable> {
|
|
31
|
+
return this._customVariables;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
get excludeByPageIdActions() {
|
|
35
|
+
return this._pageIdActions;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
get excludeByTagActions() {
|
|
39
|
+
return this._tagActions;
|
|
40
|
+
}
|
|
41
|
+
get jumpToPageActions() {
|
|
42
|
+
return this._jumpActions;
|
|
43
|
+
}
|
|
44
|
+
}
|