@media-quest/engine 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.
- package/dist/public-api.d.mts +35 -5
- package/dist/public-api.d.ts +35 -5
- package/dist/public-api.js +45 -3
- package/dist/public-api.mjs +41 -2
- package/package.json +2 -2
- package/src/commands/DCommand.ts +35 -34
- package/src/dto/SchemaDto.ts +45 -45
- package/src/engine/DPage.ts +44 -39
- package/src/player/dplayer.spec.ts +70 -69
- package/src/player/history-que.spec.ts +20 -19
- package/src/player/next-que.spec.ts +84 -83
- package/src/public-api.ts +1 -0
- package/src/rules/__test__/rule-engine.spec.ts +317 -316
- package/src/utils/ID.spec.ts +39 -0
- package/src/utils/ID.ts +71 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@media-quest/engine",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.8",
|
|
4
4
|
"description": "Rendering engine for media-quest schemas.",
|
|
5
5
|
"main": "dist/public-api.js",
|
|
6
6
|
"module": "dist/public-api.mjs",
|
|
@@ -10,6 +10,6 @@
|
|
|
10
10
|
"clean": "rimraf dist",
|
|
11
11
|
"build": "npm run clean && tsup src/public-api.ts --sourcemap inline --format cjs,esm --dts",
|
|
12
12
|
"prepublishOnly": "npm run build",
|
|
13
|
-
"tsc:check": "tsc --watch --noEmit"
|
|
13
|
+
"tsc:check:engine": "tsc --watch --noEmit"
|
|
14
14
|
}
|
|
15
15
|
}
|
package/src/commands/DCommand.ts
CHANGED
|
@@ -2,6 +2,7 @@ import { DStyle } from "../Delement/DStyle";
|
|
|
2
2
|
import { AnimationDto } from "../dto/AnimationDto";
|
|
3
3
|
import { Fact } from "../rules/fact";
|
|
4
4
|
import { DState } from "../state/Dstate";
|
|
5
|
+
import { PageID } from "../utils/ID";
|
|
5
6
|
|
|
6
7
|
type CommandTarget = "VIDEO" | "AUDIO" | "ELEMENT" | "PAGE_QUE" | "ENGINE" | "STATE";
|
|
7
8
|
type CommandKind = `${Uppercase<CommandTarget>}_${Uppercase<string>}_COMMAND`;
|
|
@@ -10,53 +11,53 @@ export type StateCommand = CommandDto<"STATE_MUTATE_COMMAND", "STATE", { mutatio
|
|
|
10
11
|
// export type StateCommand = CommandDto<"STATE_MUTATE_COMMAND", "STATE", { mutation: DState.StateMutation }>;
|
|
11
12
|
|
|
12
13
|
export type NavigationCommand =
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
14
|
+
| CommandDto<"PAGE_QUE_NEXT_PAGE_COMMAND", "PAGE_QUE", {}>
|
|
15
|
+
| CommandDto<"PAGE_QUE_GO_TO_SEQUENCE_COMMAND", "PAGE_QUE", { sequenceId: string }>
|
|
16
|
+
| CommandDto<"PAGE_QUE_GO_TO_PAGE_COMMAND", "PAGE_QUE", { pageId: string }>;
|
|
16
17
|
|
|
17
18
|
export type EngineCommand = CommandDto<
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
19
|
+
"ENGINE_LEAVE_PAGE_COMMAND",
|
|
20
|
+
"ENGINE",
|
|
21
|
+
{
|
|
22
|
+
readonly pageId: string;
|
|
23
|
+
readonly factsCollected: ReadonlyArray<Fact>;
|
|
24
|
+
}
|
|
24
25
|
>;
|
|
25
26
|
|
|
26
27
|
interface CommandDto<K extends CommandKind, T extends CommandTarget, P> {
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
28
|
+
readonly kind: K;
|
|
29
|
+
readonly target: T;
|
|
30
|
+
readonly targetId: T | Omit<string, T>;
|
|
31
|
+
readonly payload: P;
|
|
31
32
|
}
|
|
32
33
|
|
|
33
34
|
export type VideoCommand =
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
35
|
+
| CommandDto<"VIDEO_PLAY_COMMAND", "VIDEO", { volume?: number }>
|
|
36
|
+
| CommandDto<"VIDEO_SET_VOLUME_COMMAND", "VIDEO", { volume: number }>
|
|
37
|
+
| CommandDto<"VIDEO_JUMP_TO_COMMAND", "VIDEO", { volume?: number; ms: number }>
|
|
38
|
+
| CommandDto<"VIDEO_PAUSE_COMMAND", "VIDEO", {}>;
|
|
38
39
|
|
|
39
40
|
export type AudioCommand =
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
41
|
+
| CommandDto<"AUDIO_PAUSE_COMMAND", "AUDIO", {}>
|
|
42
|
+
| CommandDto<"AUDIO_PLAY_COMMAND", "AUDIO", { volume?: number; startAt?: number }>
|
|
43
|
+
| CommandDto<"AUDIO_SET_VOLUME_COMMAND", "AUDIO", { volume: number }>;
|
|
43
44
|
|
|
44
45
|
export type ElementCommand =
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
46
|
+
| CommandDto<"ELEMENT_ANIMATE_COMMAND", "ELEMENT", AnimationDto>
|
|
47
|
+
| CommandDto<"ELEMENT_DISABLE_CLICK_COMMAND", "ELEMENT", {}>
|
|
48
|
+
| CommandDto<"ELEMENT_ENABLE_CLICK_COMMAND", "ELEMENT", {}>
|
|
49
|
+
| CommandDto<"ELEMENT_STYLE_COMMAND", "ELEMENT", { changes: Partial<DStyle>; clickIsAllowed?: boolean }>;
|
|
49
50
|
|
|
50
51
|
export type PageQueCommand =
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
52
|
+
| CommandDto<"PAGE_QUE_EXCLUDE_BY_TAG_COMMAND", "PAGE_QUE", { tagIds: string[] }>
|
|
53
|
+
| CommandDto<"PAGE_QUE_EXCLUDE_BY_PAGE_ID_COMMAND", "PAGE_QUE", { pageIds: Array<PageID> }>
|
|
54
|
+
| CommandDto<"PAGE_QUE_JUMP_TO_PAGE_COMMAND", "PAGE_QUE", { readonly pageId: string }>;
|
|
54
55
|
|
|
55
56
|
export type DCommand =
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
57
|
+
| StateCommand
|
|
58
|
+
| NavigationCommand
|
|
59
|
+
| VideoCommand
|
|
60
|
+
| AudioCommand
|
|
61
|
+
| ElementCommand
|
|
62
|
+
| EngineCommand
|
|
63
|
+
| PageQueCommand;
|
package/src/dto/SchemaDto.ts
CHANGED
|
@@ -4,62 +4,62 @@ import { Rule } from "../rules/rule";
|
|
|
4
4
|
import { Fact } from "../rules/fact";
|
|
5
5
|
import { PageQueCommand } from "../commands/DCommand";
|
|
6
6
|
import { DState } from "../state/Dstate";
|
|
7
|
+
import { PageID, SchemaID } from "../utils/ID";
|
|
7
8
|
|
|
8
9
|
export type PageQueRules = Rule<PageQueCommand, never>;
|
|
9
10
|
export interface PageDto {
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
11
|
+
readonly id: PageID;
|
|
12
|
+
readonly elements: Array<DElementDto>;
|
|
13
|
+
readonly tags?: string[];
|
|
14
|
+
readonly mainVideoId?: string;
|
|
15
|
+
readonly backgroundColor?: string;
|
|
16
|
+
readonly video?: Array<DVideoDto>;
|
|
17
|
+
readonly audio?: Array<DAudioDto>;
|
|
18
|
+
readonly autoPlaySequence?: DAutoPlaySequence;
|
|
18
19
|
}
|
|
19
20
|
|
|
20
21
|
export interface PageSequenceDto {
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
22
|
+
readonly id: string;
|
|
23
|
+
readonly rules: Array<PageQueRules>;
|
|
24
|
+
readonly pages: Array<PageDto>;
|
|
24
25
|
}
|
|
25
26
|
|
|
26
27
|
export interface SchemaDto {
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
readonly predefinedFacts?: ReadonlyArray<Fact>;
|
|
28
|
+
readonly id: SchemaID;
|
|
29
|
+
readonly baseHeight: number;
|
|
30
|
+
readonly baseWidth: number;
|
|
31
|
+
readonly backgroundColor: string;
|
|
32
|
+
readonly pages: PageDto[];
|
|
33
|
+
readonly rules: Array<PageQueRules>;
|
|
34
|
+
readonly stateProps?: ReadonlyArray<DState.Prop>;
|
|
35
|
+
readonly stateQueries?: ReadonlyArray<DState.StateQuery>;
|
|
36
|
+
readonly stateFromEvent: ReadonlyArray<DState.fromEventHandler>;
|
|
37
|
+
readonly pageSequences?: Array<PageSequenceDto>;
|
|
38
|
+
readonly predefinedFacts?: ReadonlyArray<Fact>;
|
|
39
39
|
}
|
|
40
40
|
|
|
41
41
|
export namespace SchemaDto {
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
42
|
+
export const getResources = (
|
|
43
|
+
schema: SchemaDto,
|
|
44
|
+
): {
|
|
45
|
+
videoList: ReadonlyArray<DVideoDto>;
|
|
46
|
+
audioList: ReadonlyArray<DAudioDto>;
|
|
47
|
+
imageList: ReadonlyArray<DImgDto>;
|
|
48
|
+
} => {
|
|
49
|
+
const { pages } = schema;
|
|
50
|
+
const videoList = pages.reduce<Array<DVideoDto>>((acc, curr) => {
|
|
51
|
+
if (Array.isArray(curr.video)) {
|
|
52
|
+
acc.push(...curr.video);
|
|
53
|
+
}
|
|
54
|
+
return acc;
|
|
55
|
+
}, []);
|
|
56
|
+
const audioList: Array<DAudioDto> = pages.reduce<Array<DAudioDto>>((acc, curr) => {
|
|
57
|
+
if (Array.isArray(curr.audio)) {
|
|
58
|
+
acc.push(...curr.audio);
|
|
59
|
+
}
|
|
60
|
+
return acc;
|
|
61
|
+
}, []);
|
|
62
62
|
|
|
63
|
-
|
|
64
|
-
|
|
63
|
+
return { videoList, audioList, imageList: [] };
|
|
64
|
+
};
|
|
65
65
|
}
|
package/src/engine/DPage.ts
CHANGED
|
@@ -7,49 +7,54 @@ import { DTimestamp } from "../common/DTimestamp";
|
|
|
7
7
|
import { ScaleService } from "./scale";
|
|
8
8
|
|
|
9
9
|
export class DPage {
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
10
|
+
private readonly TAG = "[ DPage ]: ";
|
|
11
|
+
private elements: DElement<HTMLElement>[] = [];
|
|
12
|
+
private readonly eventBus;
|
|
13
|
+
private readonly commandBus;
|
|
14
|
+
private readonly scale: ScaleService;
|
|
15
|
+
// Todo GLOBAL EVENT_BUSS AND PAGE EVENTS:
|
|
16
16
|
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
17
|
+
constructor(
|
|
18
|
+
private readonly dto: PageDto,
|
|
19
|
+
eventBus: EventBus,
|
|
20
|
+
commandBus: DCommandBus,
|
|
21
|
+
scale: ScaleService,
|
|
22
|
+
) {
|
|
23
|
+
this.eventBus = eventBus;
|
|
24
|
+
this.commandBus = commandBus;
|
|
25
|
+
this.scale = scale;
|
|
26
|
+
this.elements = dto.elements.map((dto) => createDElement(dto, this.commandBus, this.eventBus, this.scale));
|
|
27
|
+
}
|
|
23
28
|
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
29
|
+
appendYourself(parent: HTMLElement) {
|
|
30
|
+
// console.log(this.TAG + " APPENDING TO PARENT");
|
|
31
|
+
this.elements.forEach((el) => {
|
|
32
|
+
el.appendYourself(parent);
|
|
33
|
+
// parent.appendChild(el.el);
|
|
34
|
+
});
|
|
30
35
|
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
36
|
+
// if (!preloadMode) {
|
|
37
|
+
this.eventBus.emit({
|
|
38
|
+
kind: "PAGE_ENTER_EVENT",
|
|
39
|
+
timestamp: DTimestamp.now(),
|
|
40
|
+
producer: "DPage",
|
|
41
|
+
producerId: this.id,
|
|
42
|
+
data: { pageId: this.id },
|
|
43
|
+
});
|
|
44
|
+
// }
|
|
45
|
+
}
|
|
41
46
|
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
+
destroy() {
|
|
48
|
+
this.elements.forEach((el) => {
|
|
49
|
+
el.destroy();
|
|
50
|
+
});
|
|
51
|
+
}
|
|
47
52
|
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
53
|
+
log(): void {
|
|
54
|
+
// console.log(this.TAG + 'scale - ' + this.scale);
|
|
55
|
+
}
|
|
51
56
|
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
57
|
+
get id() {
|
|
58
|
+
return this.dto.id;
|
|
59
|
+
}
|
|
55
60
|
}
|
|
@@ -4,9 +4,10 @@ import { Rule } from "../rules/rule";
|
|
|
4
4
|
import { PageHistory } from "./history-que";
|
|
5
5
|
import { DTimestamp } from "../common/DTimestamp";
|
|
6
6
|
import { PageQueCommand } from "../commands/DCommand";
|
|
7
|
+
import { PageID } from "../utils/ID";
|
|
7
8
|
|
|
8
9
|
const page = (id: number): PageDto => {
|
|
9
|
-
|
|
10
|
+
return { id: PageID.create(), elements: [] };
|
|
10
11
|
};
|
|
11
12
|
const p1 = page(1);
|
|
12
13
|
const p2 = page(2);
|
|
@@ -16,93 +17,93 @@ const p5 = page(5);
|
|
|
16
17
|
const p6 = page(6);
|
|
17
18
|
const all = [p1, p2, p3, p4, p5, p6];
|
|
18
19
|
const Seq1 = {
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
20
|
+
p10: page(10),
|
|
21
|
+
p11: page(11),
|
|
22
|
+
p12: page(12),
|
|
22
23
|
};
|
|
23
24
|
|
|
24
25
|
const seq1: PageSequenceDto = {
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
26
|
+
id: "s1",
|
|
27
|
+
pages: [Seq1.p10, Seq1.p11, Seq1.p12],
|
|
28
|
+
rules: [],
|
|
28
29
|
};
|
|
29
30
|
const data = (
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
31
|
+
pages: PageDto[],
|
|
32
|
+
pageSequences: PageSequenceDto[] = [],
|
|
33
|
+
rules: Rule<PageQueCommand, never>[] = [],
|
|
33
34
|
): DPlayerData => ({ pages, pageSequences, rules });
|
|
34
35
|
// const seq = (pages: PageDto[], rules: Rule[]) => {};
|
|
35
36
|
beforeEach(() => {
|
|
36
|
-
|
|
37
|
+
// data = { pages: [], rules: [], pageSequences: [] };
|
|
37
38
|
});
|
|
38
39
|
|
|
39
40
|
describe("DPlayer", () => {
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
41
|
+
it("should create an instance", () => {
|
|
42
|
+
const player = new DPlayer(data([p1, p1]));
|
|
43
|
+
expect(player).toBeTruthy();
|
|
44
|
+
});
|
|
44
45
|
|
|
45
|
-
|
|
46
|
-
|
|
46
|
+
it("can app pages, and get next", () => {
|
|
47
|
+
const player = new DPlayer(data([p1, p2]));
|
|
47
48
|
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
49
|
+
expect(player.getNextPage()).toBe(p1);
|
|
50
|
+
expect(player.getNextPage()).toBe(p2);
|
|
51
|
+
expect(player.getNextPage()).toBe(false);
|
|
52
|
+
});
|
|
52
53
|
|
|
53
|
-
|
|
54
|
-
|
|
54
|
+
it("Can insert a sequence", () => {
|
|
55
|
+
const player = new DPlayer(data(all, [seq1]));
|
|
55
56
|
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
});
|
|
66
|
-
expect(player.getNextPage()).toBe(Seq1.p10);
|
|
67
|
-
expect(player.getNextPage()).toBe(Seq1.p11);
|
|
68
|
-
expect(player.getNextPage()).toBe(Seq1.p12);
|
|
69
|
-
expect(player.getNextPage()).toBe(p3);
|
|
57
|
+
expect(player.getNextPage()).toBe(p1);
|
|
58
|
+
expect(player.getNextPage()).toBe(p2);
|
|
59
|
+
player.handleNavigationCommand({
|
|
60
|
+
kind: "PAGE_QUE_GO_TO_SEQUENCE_COMMAND",
|
|
61
|
+
target: "PAGE_QUE",
|
|
62
|
+
targetId: "PAGE_QUE",
|
|
63
|
+
payload: {
|
|
64
|
+
sequenceId: seq1.id,
|
|
65
|
+
},
|
|
70
66
|
});
|
|
67
|
+
expect(player.getNextPage()).toBe(Seq1.p10);
|
|
68
|
+
expect(player.getNextPage()).toBe(Seq1.p11);
|
|
69
|
+
expect(player.getNextPage()).toBe(Seq1.p12);
|
|
70
|
+
expect(player.getNextPage()).toBe(p3);
|
|
71
|
+
});
|
|
71
72
|
|
|
72
|
-
|
|
73
|
-
|
|
73
|
+
it("Can jump forward to a pageId", () => {
|
|
74
|
+
const player = new DPlayer(data(all));
|
|
74
75
|
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
});
|
|
82
|
-
expect(player.getNextPage()).toBe(p4);
|
|
76
|
+
expect(player.getNextPage()).toBe(p1);
|
|
77
|
+
player.handleNavigationCommand({
|
|
78
|
+
kind: "PAGE_QUE_GO_TO_PAGE_COMMAND",
|
|
79
|
+
target: "PAGE_QUE",
|
|
80
|
+
targetId: "PAGE_QUE",
|
|
81
|
+
payload: { pageId: p4.id },
|
|
83
82
|
});
|
|
83
|
+
expect(player.getNextPage()).toBe(p4);
|
|
84
|
+
});
|
|
84
85
|
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
86
|
+
it("Save history", () => {
|
|
87
|
+
const player = new DPlayer(data(all));
|
|
88
|
+
const curr = player.getNextPage() as PageDto;
|
|
88
89
|
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
90
|
+
const history: PageHistory = {
|
|
91
|
+
pageId: curr.id,
|
|
92
|
+
answeredQuestions: [
|
|
93
|
+
{
|
|
94
|
+
timestamp: DTimestamp.now(),
|
|
95
|
+
fact: {
|
|
96
|
+
referenceId: "as",
|
|
97
|
+
referenceLabel: "as-label",
|
|
98
|
+
kind: "numeric-fact",
|
|
99
|
+
label: "litt",
|
|
100
|
+
value: 2,
|
|
101
|
+
},
|
|
102
|
+
},
|
|
103
|
+
],
|
|
104
|
+
};
|
|
105
|
+
player.saveHistory(history);
|
|
106
|
+
expect(player.getNextPage()).toBe(p2);
|
|
107
|
+
expect(player.getResults().length).toBe(1);
|
|
108
|
+
});
|
|
108
109
|
});
|
|
@@ -1,24 +1,25 @@
|
|
|
1
1
|
import { AnsweredQuestion, HistoryQue, PageHistory } from "./history-que";
|
|
2
2
|
import { DTimestamp } from "../common/DTimestamp";
|
|
3
3
|
import { PageDto } from "../dto/SchemaDto";
|
|
4
|
+
import { PageID } from "../utils/ID";
|
|
4
5
|
|
|
5
6
|
const p = (id: number): PageDto => {
|
|
6
|
-
|
|
7
|
+
return { id: PageID.create(), elements: [] };
|
|
7
8
|
};
|
|
8
9
|
|
|
9
10
|
const answer = (id: number, value: number): AnsweredQuestion => ({
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
11
|
+
timestamp: DTimestamp.now(),
|
|
12
|
+
fact: {
|
|
13
|
+
referenceId: "" + id,
|
|
14
|
+
referenceLabel: "label-for-" + id,
|
|
15
|
+
value,
|
|
16
|
+
label: "value-label " + value,
|
|
17
|
+
kind: "numeric-fact",
|
|
18
|
+
},
|
|
18
19
|
});
|
|
19
20
|
const h = (page: PageDto, answeredQuestions: AnsweredQuestion[]): PageHistory => ({
|
|
20
|
-
|
|
21
|
-
|
|
21
|
+
pageId: page.id,
|
|
22
|
+
answeredQuestions,
|
|
22
23
|
});
|
|
23
24
|
const p1 = p(1);
|
|
24
25
|
const p2 = p(2);
|
|
@@ -30,16 +31,16 @@ const all = [p1, p2, p3, p4, p5, p6];
|
|
|
30
31
|
|
|
31
32
|
let history = new HistoryQue();
|
|
32
33
|
beforeEach(() => {
|
|
33
|
-
|
|
34
|
+
history = new HistoryQue();
|
|
34
35
|
});
|
|
35
36
|
|
|
36
37
|
describe("HistoryQue", () => {
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
38
|
+
it("should create an instance", () => {
|
|
39
|
+
expect(history).toBeTruthy();
|
|
40
|
+
});
|
|
40
41
|
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
42
|
+
it("Can add history, and get facts back", () => {
|
|
43
|
+
history.addToHistory(h(p1, [answer(1, 2)]));
|
|
44
|
+
expect(history.getFacts().length).toBe(1);
|
|
45
|
+
});
|
|
45
46
|
});
|