@media-quest/engine 0.0.39 → 0.0.41
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.ts +8 -21
- package/dist/public-api.js +53 -32
- package/dist/public-api.js.map +1 -1
- package/package.json +26 -26
- package/src/Delement/DButton.ts +25 -25
- package/src/Delement/DElement.dto.ts +6 -6
- package/src/Delement/DElement.ts +198 -190
- package/src/Delement/DImg.ts +48 -48
- package/src/Delement/DStyle.ts +382 -391
- package/src/Delement/DText.ts +23 -23
- package/src/Delement/Ddiv.ts +44 -44
- package/src/Delement/button-click-action.ts +42 -42
- package/src/Delement/css.spec.ts +40 -40
- package/src/Delement/css.ts +70 -56
- package/src/Delement/element-factory.ts +49 -49
- package/src/engine/SchemaEngine.ts +159 -160
- package/src/engine/SchemaResult.ts +10 -12
- package/src/engine/dplayer.spec.ts +91 -92
- package/src/engine/dplayer.ts +104 -106
- package/src/engine/history-que.spec.ts +67 -69
- package/src/engine/history-que.ts +17 -21
- package/src/engine/next-que.spec.ts +121 -122
- package/src/engine/next-que.ts +101 -101
- package/src/events/mq-events.ts +63 -76
- package/src/page/Page.ts +197 -180
- package/src/page/page-result.ts +11 -12
- package/src/page/task-manager.ts +263 -263
- package/src/page/task-state.ts +65 -65
- package/src/public-api.ts +25 -26
- package/src/utils/DUtil.ts +2 -3
- package/tsconfig.json +19 -19
package/src/engine/dplayer.ts
CHANGED
|
@@ -1,106 +1,104 @@
|
|
|
1
|
-
import { HistoryQue } from "./history-que";
|
|
2
|
-
import { RuleEngine } from "../rules/rule-engine";
|
|
3
|
-
import { NextQue } from "./next-que";
|
|
4
|
-
import { SchemaDto } from "./SchemaDto";
|
|
5
|
-
import { RuleActionPageQue } from "./page-que-ruleengine-action";
|
|
6
|
-
import { PageDto } from "../page/Page";
|
|
7
|
-
import { PageResult } from "../page/page-result";
|
|
8
|
-
import { Fact } from "../rules/fact";
|
|
9
|
-
import { MqEvent } from "../events/mq-events";
|
|
10
|
-
|
|
11
|
-
export type DPlayerData = Pick<SchemaDto, "pages" | "pageSequences" | "rules" | "predefinedFacts">;
|
|
12
|
-
export class DPlayer {
|
|
13
|
-
private readonly eventLog: Array<MqEvent> = [];
|
|
14
|
-
private history = new HistoryQue();
|
|
15
|
-
private ruleEngine = new RuleEngine<RuleActionPageQue, never>();
|
|
16
|
-
private nextQue = new NextQue();
|
|
17
|
-
private data: DPlayerData;
|
|
18
|
-
private readonly predefinedFacts: ReadonlyArray<Fact>;
|
|
19
|
-
|
|
20
|
-
constructor(data: DPlayerData) {
|
|
21
|
-
this.data = data;
|
|
22
|
-
const pages = data.pages ?? [];
|
|
23
|
-
this.predefinedFacts = data.predefinedFacts ? [...data.predefinedFacts] : [];
|
|
24
|
-
this.nextQue.resetQue(pages);
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
saveEvent(event: MqEvent) {
|
|
28
|
-
this.eventLog.push(event);
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
saveHistory(
|
|
32
|
-
// console.log("SAVE HISTORY", pageHistory);
|
|
33
|
-
this.history.addToHistory(
|
|
34
|
-
this.eventLog.push(...
|
|
35
|
-
// Evaluate rules
|
|
36
|
-
const userGeneratedFact = this.history.getFacts();
|
|
37
|
-
const predefinedFacts = this.predefinedFacts;
|
|
38
|
-
const facts = [...userGeneratedFact, ...predefinedFacts];
|
|
39
|
-
const result = this.ruleEngine.solveAll(this.data.rules, facts);
|
|
40
|
-
|
|
41
|
-
const matchingRules = result.matching;
|
|
42
|
-
const actions = matchingRules.map((r) => r.actionList).flat(1);
|
|
43
|
-
// Execute actions
|
|
44
|
-
actions.forEach((a) => {
|
|
45
|
-
// console.log(a.payload);
|
|
46
|
-
switch (a.kind) {
|
|
47
|
-
case "jumpToPage":
|
|
48
|
-
this.nextQue.jumpToPageById(a.pageId);
|
|
49
|
-
break;
|
|
50
|
-
case "excludeByPageId":
|
|
51
|
-
this.nextQue.removeByPageId(a.pageIds);
|
|
52
|
-
break;
|
|
53
|
-
case "excludeByTag":
|
|
54
|
-
this.nextQue.removeByTag(a.tagIds);
|
|
55
|
-
break;
|
|
56
|
-
default:
|
|
57
|
-
console.log("UNKNOWN ACTION", a);
|
|
58
|
-
const check: never = a;
|
|
59
|
-
}
|
|
60
|
-
});
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
getResults() {
|
|
64
|
-
const pagesLeft = this.nextQue.size;
|
|
65
|
-
const answerFacts = this.history.getFacts();
|
|
66
|
-
const predefinedFacts = this.predefinedFacts;
|
|
67
|
-
const eventLog = [...this.eventLog];
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
}
|
|
106
|
-
}
|
|
1
|
+
import { HistoryQue } from "./history-que";
|
|
2
|
+
import { RuleEngine } from "../rules/rule-engine";
|
|
3
|
+
import { NextQue } from "./next-que";
|
|
4
|
+
import { SchemaDto } from "./SchemaDto";
|
|
5
|
+
import { RuleActionPageQue } from "./page-que-ruleengine-action";
|
|
6
|
+
import { PageDto } from "../page/Page";
|
|
7
|
+
import { PageResult } from "../page/page-result";
|
|
8
|
+
import { Fact } from "../rules/fact";
|
|
9
|
+
import { MqEvent } from "../events/mq-events";
|
|
10
|
+
|
|
11
|
+
export type DPlayerData = Pick<SchemaDto, "pages" | "pageSequences" | "rules" | "predefinedFacts">;
|
|
12
|
+
export class DPlayer {
|
|
13
|
+
private readonly eventLog: Array<MqEvent> = [];
|
|
14
|
+
private history = new HistoryQue();
|
|
15
|
+
private ruleEngine = new RuleEngine<RuleActionPageQue, never>();
|
|
16
|
+
private nextQue = new NextQue();
|
|
17
|
+
private data: DPlayerData;
|
|
18
|
+
private readonly predefinedFacts: ReadonlyArray<Fact>;
|
|
19
|
+
|
|
20
|
+
constructor(data: DPlayerData) {
|
|
21
|
+
this.data = data;
|
|
22
|
+
const pages = data.pages ?? [];
|
|
23
|
+
this.predefinedFacts = data.predefinedFacts ? [...data.predefinedFacts] : [];
|
|
24
|
+
this.nextQue.resetQue(pages);
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
saveEvent(event: MqEvent) {
|
|
28
|
+
this.eventLog.push(event);
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
saveHistory(pageHistory: PageResult) {
|
|
32
|
+
// console.log("SAVE HISTORY", pageHistory);
|
|
33
|
+
this.history.addToHistory(pageHistory);
|
|
34
|
+
this.eventLog.push(...pageHistory.eventLog);
|
|
35
|
+
// Evaluate rules
|
|
36
|
+
const userGeneratedFact = this.history.getFacts();
|
|
37
|
+
const predefinedFacts = this.predefinedFacts;
|
|
38
|
+
const facts = [...userGeneratedFact, ...predefinedFacts];
|
|
39
|
+
const result = this.ruleEngine.solveAll(this.data.rules, facts);
|
|
40
|
+
|
|
41
|
+
const matchingRules = result.matching;
|
|
42
|
+
const actions = matchingRules.map((r) => r.actionList).flat(1);
|
|
43
|
+
// Execute actions
|
|
44
|
+
actions.forEach((a) => {
|
|
45
|
+
// console.log(a.payload);
|
|
46
|
+
switch (a.kind) {
|
|
47
|
+
case "jumpToPage":
|
|
48
|
+
this.nextQue.jumpToPageById(a.pageId);
|
|
49
|
+
break;
|
|
50
|
+
case "excludeByPageId":
|
|
51
|
+
this.nextQue.removeByPageId(a.pageIds);
|
|
52
|
+
break;
|
|
53
|
+
case "excludeByTag":
|
|
54
|
+
this.nextQue.removeByTag(a.tagIds);
|
|
55
|
+
break;
|
|
56
|
+
default:
|
|
57
|
+
console.log("UNKNOWN ACTION", a);
|
|
58
|
+
const check: never = a;
|
|
59
|
+
}
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
getResults() {
|
|
64
|
+
const pagesLeft = this.nextQue.size;
|
|
65
|
+
const answerFacts = this.history.getFacts();
|
|
66
|
+
const predefinedFacts = this.predefinedFacts;
|
|
67
|
+
const eventLog = [...this.eventLog];
|
|
68
|
+
// console.log(answerFacts);
|
|
69
|
+
return { answerFacts, predefinedFacts, eventLog, pagesLeft };
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
insertSequence(sequenceId: string) {
|
|
73
|
+
this.insertSequenceById(sequenceId);
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
getNextPage(): PageDto | false {
|
|
77
|
+
const next = this.nextQue.pop();
|
|
78
|
+
return next ?? false;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
private insertSequenceById(id: string) {
|
|
82
|
+
const seq = this.data.pageSequences?.find((s) => s.id === id);
|
|
83
|
+
if (seq) {
|
|
84
|
+
this.nextQue.insertAsNextByForce([...seq.pages]);
|
|
85
|
+
} else {
|
|
86
|
+
// HOW TO HANDLE INVALID ID_REFS?? LOGGER??
|
|
87
|
+
// LOG INVALID COMMAND.
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
/**
|
|
92
|
+
* Total number of pages left in que
|
|
93
|
+
*/
|
|
94
|
+
get pagesLeft(): number {
|
|
95
|
+
return this.nextQue.pageCount;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
/**
|
|
99
|
+
* Total number of pages in test
|
|
100
|
+
*/
|
|
101
|
+
get totalPageCount(): number {
|
|
102
|
+
return this.data.pages.length;
|
|
103
|
+
}
|
|
104
|
+
}
|
|
@@ -1,69 +1,67 @@
|
|
|
1
|
-
import { HistoryQue } from "./history-que";
|
|
2
|
-
import { DTimestamp } from "../common/DTimestamp";
|
|
3
|
-
import { PageDto } from "../page/Page";
|
|
4
|
-
import { PageResult } from "../page/page-result";
|
|
5
|
-
import { DUtil } from "../utils/DUtil";
|
|
6
|
-
|
|
7
|
-
const p = (id: number): PageDto => {
|
|
8
|
-
return {
|
|
9
|
-
id: DUtil.randomObjectId(),
|
|
10
|
-
prefix: "prefix" + id,
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
const
|
|
21
|
-
const
|
|
22
|
-
const
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
//
|
|
44
|
-
//
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
const
|
|
48
|
-
const
|
|
49
|
-
const
|
|
50
|
-
const
|
|
51
|
-
const
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
});
|
|
69
|
-
});
|
|
1
|
+
import { HistoryQue } from "./history-que";
|
|
2
|
+
import { DTimestamp } from "../common/DTimestamp";
|
|
3
|
+
import { PageDto } from "../page/Page";
|
|
4
|
+
import { PageResult } from "../page/page-result";
|
|
5
|
+
import { DUtil } from "../utils/DUtil";
|
|
6
|
+
|
|
7
|
+
const p = (id: number): PageDto => {
|
|
8
|
+
return {
|
|
9
|
+
id: DUtil.randomObjectId(),
|
|
10
|
+
prefix: "prefix" + id,
|
|
11
|
+
elements: [],
|
|
12
|
+
initialTasks: [],
|
|
13
|
+
// staticElements: [],
|
|
14
|
+
background: "",
|
|
15
|
+
tags: [],
|
|
16
|
+
};
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
const pageResult = (id: number, value: number): PageResult => {
|
|
20
|
+
const pageEntered = DTimestamp.now();
|
|
21
|
+
const pageExited = DTimestamp.addMills(pageEntered, 1000);
|
|
22
|
+
const pageTime = DTimestamp.diff(pageEntered, pageExited);
|
|
23
|
+
|
|
24
|
+
const result: PageResult = {
|
|
25
|
+
pageId: "_dummyId" + id,
|
|
26
|
+
pagePrefix: "prefix" + id,
|
|
27
|
+
eventLog: [],
|
|
28
|
+
pageTime,
|
|
29
|
+
collectedFacts: [
|
|
30
|
+
{
|
|
31
|
+
referenceId: "" + id,
|
|
32
|
+
referenceLabel: "label-for-" + id,
|
|
33
|
+
value,
|
|
34
|
+
label: "value-label " + value,
|
|
35
|
+
kind: "numeric-fact",
|
|
36
|
+
},
|
|
37
|
+
],
|
|
38
|
+
};
|
|
39
|
+
return result;
|
|
40
|
+
};
|
|
41
|
+
// const h = (page: PageDto, answeredQuestions: AnsweredQuestion[]): PageResult => ({
|
|
42
|
+
// pageId: page.id,
|
|
43
|
+
// answeredQuestions,
|
|
44
|
+
// });
|
|
45
|
+
const p1 = p(1);
|
|
46
|
+
const p2 = p(2);
|
|
47
|
+
const p3 = p(3);
|
|
48
|
+
const p4 = p(4);
|
|
49
|
+
const p5 = p(5);
|
|
50
|
+
const p6 = p(6);
|
|
51
|
+
const all = [p1, p2, p3, p4, p5, p6];
|
|
52
|
+
|
|
53
|
+
let history = new HistoryQue();
|
|
54
|
+
beforeEach(() => {
|
|
55
|
+
history = new HistoryQue();
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
describe("HistoryQue", () => {
|
|
59
|
+
it("should create an instance", () => {
|
|
60
|
+
expect(history).toBeTruthy();
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
it("Can add history, and get facts back", () => {
|
|
64
|
+
history.addToHistory(pageResult(1, 2));
|
|
65
|
+
expect(history.getFacts().length).toBe(1);
|
|
66
|
+
});
|
|
67
|
+
});
|
|
@@ -1,21 +1,17 @@
|
|
|
1
|
-
import { Fact } from "../rules/fact";
|
|
2
|
-
import { PageResult } from "../page/page-result";
|
|
3
|
-
|
|
4
|
-
export class HistoryQue {
|
|
5
|
-
private history: PageResult[] = [];
|
|
6
|
-
|
|
7
|
-
getFacts(): Array<Fact> {
|
|
8
|
-
const answers = this.history.map((h) => h.collectedFacts).flat(1);
|
|
9
|
-
// const facts = answers.map((a) => a.fact);
|
|
10
|
-
// TODO FIND LATEST FACT (answer) if have multiple.
|
|
11
|
-
return answers;
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
addToHistory(result: PageResult) {
|
|
19
|
-
this.history.push(result);
|
|
20
|
-
}
|
|
21
|
-
}
|
|
1
|
+
import { Fact } from "../rules/fact";
|
|
2
|
+
import { PageResult } from "../page/page-result";
|
|
3
|
+
|
|
4
|
+
export class HistoryQue {
|
|
5
|
+
private history: PageResult[] = [];
|
|
6
|
+
|
|
7
|
+
getFacts(): Array<Fact> {
|
|
8
|
+
const answers = this.history.map((h) => h.collectedFacts).flat(1);
|
|
9
|
+
// const facts = answers.map((a) => a.fact);
|
|
10
|
+
// TODO FIND LATEST FACT (answer) if have multiple.
|
|
11
|
+
return answers;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
addToHistory(result: PageResult) {
|
|
15
|
+
this.history.push(result);
|
|
16
|
+
}
|
|
17
|
+
}
|
|
@@ -1,122 +1,121 @@
|
|
|
1
|
-
import { NextQue } from "./next-que";
|
|
2
|
-
import { PageDto } from "../page/Page";
|
|
3
|
-
import { DUtil } from "../utils/DUtil";
|
|
4
|
-
|
|
5
|
-
const tag1 = "tag1";
|
|
6
|
-
const tag2 = "tag2";
|
|
7
|
-
const tag3 = "tag3";
|
|
8
|
-
|
|
9
|
-
let que = new NextQue();
|
|
10
|
-
const createPage = (tags: string[]): PageDto => {
|
|
11
|
-
const dto: PageDto = {
|
|
12
|
-
id: DUtil.randomObjectId(),
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
const
|
|
25
|
-
const
|
|
26
|
-
const
|
|
27
|
-
const
|
|
28
|
-
const
|
|
29
|
-
const
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
que.
|
|
39
|
-
expect(que.pop()).toBe(
|
|
40
|
-
expect(que.
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
que.
|
|
46
|
-
|
|
47
|
-
que.
|
|
48
|
-
expect(que.
|
|
49
|
-
|
|
50
|
-
que.
|
|
51
|
-
expect(que.
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
que.
|
|
57
|
-
que.
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
que.
|
|
63
|
-
que.
|
|
64
|
-
expect(que.
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
que.
|
|
70
|
-
que.
|
|
71
|
-
|
|
72
|
-
que.
|
|
73
|
-
expect(que.
|
|
74
|
-
|
|
75
|
-
que.
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
que
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
que
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
que
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
que
|
|
96
|
-
que.pop();
|
|
97
|
-
que.pop();
|
|
98
|
-
que.
|
|
99
|
-
|
|
100
|
-
que.
|
|
101
|
-
expect(que.
|
|
102
|
-
expect(que.
|
|
103
|
-
expect(que.pop()).toBe(
|
|
104
|
-
expect(que.pop()).toBe(
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
que
|
|
110
|
-
que.
|
|
111
|
-
que.
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
que.
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
que.
|
|
118
|
-
|
|
119
|
-
que.
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
});
|
|
1
|
+
import { NextQue } from "./next-que";
|
|
2
|
+
import { PageDto } from "../page/Page";
|
|
3
|
+
import { DUtil } from "../utils/DUtil";
|
|
4
|
+
|
|
5
|
+
const tag1 = "tag1";
|
|
6
|
+
const tag2 = "tag2";
|
|
7
|
+
const tag3 = "tag3";
|
|
8
|
+
|
|
9
|
+
let que = new NextQue();
|
|
10
|
+
const createPage = (tags: string[]): PageDto => {
|
|
11
|
+
const dto: PageDto = {
|
|
12
|
+
id: DUtil.randomObjectId(),
|
|
13
|
+
prefix: "prefix",
|
|
14
|
+
elements: [],
|
|
15
|
+
background: "white",
|
|
16
|
+
// components: [],
|
|
17
|
+
initialTasks: [],
|
|
18
|
+
tags,
|
|
19
|
+
};
|
|
20
|
+
return dto;
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
const p1 = createPage([tag1]);
|
|
24
|
+
const p2 = createPage([]);
|
|
25
|
+
const p3 = createPage([tag2]);
|
|
26
|
+
const p4 = createPage([]);
|
|
27
|
+
const p5 = createPage([tag3, tag2]);
|
|
28
|
+
const p6 = createPage([tag3]);
|
|
29
|
+
const all = [p1, p2, p3, p4, p5, p6];
|
|
30
|
+
|
|
31
|
+
beforeEach(() => {
|
|
32
|
+
que = new NextQue();
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
describe("NextQue testing", () => {
|
|
36
|
+
it("Can pop", () => {
|
|
37
|
+
que.resetQue(all);
|
|
38
|
+
expect(que.pop()).toBe(p1);
|
|
39
|
+
expect(que.pop()).toBe(p2);
|
|
40
|
+
expect(que.size).toBe(all.length - 2);
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
it("Can remove by tag", () => {
|
|
44
|
+
que.resetQue(all);
|
|
45
|
+
expect(que.size).toBe(6);
|
|
46
|
+
que.removeByTag(tag3);
|
|
47
|
+
expect(que.size).toBe(4);
|
|
48
|
+
expect(que.peek()).toBe(p1);
|
|
49
|
+
que.pop();
|
|
50
|
+
expect(que.peek()).toBe(p2);
|
|
51
|
+
expect(que.size).toBe(3);
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
it("Can remove by tags[]", () => {
|
|
55
|
+
que.resetQue(all);
|
|
56
|
+
que.removeByTag([tag3, tag2, tag1]);
|
|
57
|
+
expect(que.size).toBe(2);
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
it("Can remove by pageIds[]", () => {
|
|
61
|
+
que.resetQue(all);
|
|
62
|
+
que.removeByPageId([p1.id, p2.id, p3.id]);
|
|
63
|
+
expect(que.pop()).toBe(p4);
|
|
64
|
+
expect(que.size).toBe(2);
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
it("Can remove by pageId", () => {
|
|
68
|
+
que.resetQue(all);
|
|
69
|
+
que.removeByPageId(p1.id);
|
|
70
|
+
expect(que.peek()).toBe(p2);
|
|
71
|
+
que.pop();
|
|
72
|
+
expect(que.peek()).toBe(p3);
|
|
73
|
+
expect(que.size).toBe(4);
|
|
74
|
+
que.removeByPageId(p3.id);
|
|
75
|
+
expect(que.size).toBe(3);
|
|
76
|
+
});
|
|
77
|
+
|
|
78
|
+
it("Can set pages in constuctor", () => {
|
|
79
|
+
que = new NextQue(all);
|
|
80
|
+
expect(que.size).toBe(all.length);
|
|
81
|
+
});
|
|
82
|
+
|
|
83
|
+
it("Can set pages in constuctor", () => {
|
|
84
|
+
que = new NextQue(all);
|
|
85
|
+
expect(que.size).toBe(all.length);
|
|
86
|
+
});
|
|
87
|
+
|
|
88
|
+
it("Can reset que to start over.", () => {
|
|
89
|
+
que = new NextQue(all);
|
|
90
|
+
expect(que.size).toBe(all.length);
|
|
91
|
+
});
|
|
92
|
+
|
|
93
|
+
it("Can insert new pages in the middle of the test.", () => {
|
|
94
|
+
que = new NextQue(all);
|
|
95
|
+
que.pop();
|
|
96
|
+
que.pop();
|
|
97
|
+
que.pop();
|
|
98
|
+
expect(que.peek()).toBe(p4);
|
|
99
|
+
que.insertAsNextByForce([p1, p2]);
|
|
100
|
+
expect(que.peek()).toBe(p1);
|
|
101
|
+
expect(que.size).toBe(5);
|
|
102
|
+
expect(que.pop()).toBe(p1);
|
|
103
|
+
expect(que.pop()).toBe(p2);
|
|
104
|
+
expect(que.pop()).toBe(p4);
|
|
105
|
+
});
|
|
106
|
+
|
|
107
|
+
it("Can jump to page by id", () => {
|
|
108
|
+
que = new NextQue(all);
|
|
109
|
+
que.pop();
|
|
110
|
+
que.jumpToPageById(p5.id);
|
|
111
|
+
// expect(que.size).toBe(5);
|
|
112
|
+
expect(que.peek()).toBe(p5);
|
|
113
|
+
que.jumpToPageById("noncence");
|
|
114
|
+
expect(que.peek()).toBe(p5);
|
|
115
|
+
// CAn not jump back
|
|
116
|
+
que.jumpToPageById(p2.id);
|
|
117
|
+
expect(que.peek()).toBe(p5);
|
|
118
|
+
que.jumpToPageById(p6.id);
|
|
119
|
+
expect(que.peek()).toBe(p6);
|
|
120
|
+
});
|
|
121
|
+
});
|