@vnejs/plugins.views.scenario.qte 0.2.2 → 0.2.4
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/index.js +4 -3
- package/dist/modules/controller.accept.d.ts +10 -0
- package/dist/modules/controller.accept.js +9 -0
- package/dist/modules/controller.d.ts +4 -7
- package/dist/modules/controller.js +6 -19
- package/dist/modules/view.d.ts +4 -5
- package/dist/modules/view.js +4 -5
- package/package.json +5 -1
- package/src/index.ts +4 -3
- package/src/modules/controller.accept.ts +15 -0
- package/src/modules/controller.ts +6 -19
- package/src/modules/view.ts +6 -5
- package/src/tests/accept.test.ts +52 -0
- package/src/tests/controller.test.ts +23 -23
- package/src/tests/setup.ts +1 -0
package/dist/index.js
CHANGED
|
@@ -2,6 +2,7 @@ import "@vnejs/contracts.scenario.qte";
|
|
|
2
2
|
import "@vnejs/contracts.views.scenario.qte";
|
|
3
3
|
import { regPlugin } from "@vnejs/shared";
|
|
4
4
|
import { PARAMS, PLUGIN_NAME, SUBSCRIBE_EVENTS } from "@vnejs/contracts.views.scenario.qte";
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
|
|
5
|
+
import { QteViewController } from "./modules/controller.js";
|
|
6
|
+
import { QteViewControllerAccept } from "./modules/controller.accept.js";
|
|
7
|
+
import { QteViewView } from "./modules/view.js";
|
|
8
|
+
regPlugin(PLUGIN_NAME, { events: SUBSCRIBE_EVENTS, params: PARAMS }, [QteViewController, QteViewControllerAccept, QteViewView]);
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { ModuleControllerAccept } from "@vnejs/module.controller.accept";
|
|
2
|
+
import type { QtePluginConstants, QtePluginEvents, QtePluginParams, QtePluginSettings } from "../types.js";
|
|
3
|
+
export declare class QteViewControllerAccept extends ModuleControllerAccept<QtePluginEvents, QtePluginConstants, QtePluginSettings, QtePluginParams> {
|
|
4
|
+
name: string;
|
|
5
|
+
EVENT_SHOW: "vne:qte_view:show";
|
|
6
|
+
EVENT_HIDE: "vne:qte_view:hide";
|
|
7
|
+
EVENT_ACCEPT: "vne:qte_view:action";
|
|
8
|
+
CONTROLS_ZINDEX: number;
|
|
9
|
+
onAccept: () => undefined;
|
|
10
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { ModuleControllerAccept } from "@vnejs/module.controller.accept";
|
|
2
|
+
export class QteViewControllerAccept extends ModuleControllerAccept {
|
|
3
|
+
name = "qte_view.controller.accept";
|
|
4
|
+
EVENT_SHOW = this.EVENTS.QTE_VIEW.SHOW;
|
|
5
|
+
EVENT_HIDE = this.EVENTS.QTE_VIEW.HIDE;
|
|
6
|
+
EVENT_ACCEPT = this.EVENTS.QTE_VIEW.ACTION;
|
|
7
|
+
CONTROLS_ZINDEX = this.PARAMS.QTE_VIEW.ZINDEX;
|
|
8
|
+
onAccept = () => undefined;
|
|
9
|
+
}
|
|
@@ -2,14 +2,11 @@ import { ModuleController } from "@vnejs/module.components";
|
|
|
2
2
|
import type { ViewActionPayload } from "@vnejs/module.components";
|
|
3
3
|
import type { QtePluginConstants, QtePluginEvents, QtePluginParams, QtePluginSettings } from "../types.js";
|
|
4
4
|
import type { QtePluginControllerState, QteVisibilityPayload } from "../utils/qte.js";
|
|
5
|
-
export declare class
|
|
5
|
+
export declare class QteViewController extends ModuleController<QtePluginEvents, QtePluginConstants, QtePluginSettings, QtePluginParams, QtePluginControllerState> {
|
|
6
6
|
name: string;
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
abstract_interact: () => undefined;
|
|
11
|
-
};
|
|
12
|
-
controlsIndex: number;
|
|
7
|
+
EVENT_UPDATE_VIEW: "vne:qte_view:update";
|
|
8
|
+
CONTROLS: {};
|
|
9
|
+
CONTROLS_INDEX: number;
|
|
13
10
|
activeStartedAt: number | null;
|
|
14
11
|
isResolved: boolean;
|
|
15
12
|
resultTimeout: ReturnType<typeof setTimeout> | null;
|
|
@@ -1,13 +1,10 @@
|
|
|
1
1
|
import { ModuleController } from "@vnejs/module.components";
|
|
2
2
|
import { getFailAtProgress, getProgressFromElapsed, isProgressInsideZone } from "../utils/qte.js";
|
|
3
|
-
export class
|
|
3
|
+
export class QteViewController extends ModuleController {
|
|
4
4
|
name = "qte_view.controller";
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
[this.CONST.CONTROLS.BUTTONS.INTERACT]: () => void this.onAction(),
|
|
9
|
-
};
|
|
10
|
-
controlsIndex = this.PARAMS.QTE_VIEW.ZINDEX;
|
|
5
|
+
EVENT_UPDATE_VIEW = this.EVENTS.QTE_VIEW.UPDATE;
|
|
6
|
+
CONTROLS = {};
|
|
7
|
+
CONTROLS_INDEX = this.PARAMS.QTE_VIEW.ZINDEX;
|
|
11
8
|
activeStartedAt = null;
|
|
12
9
|
isResolved = false;
|
|
13
10
|
resultTimeout = null;
|
|
@@ -81,10 +78,7 @@ export class QteController extends ModuleController {
|
|
|
81
78
|
return;
|
|
82
79
|
this.isResolved = true;
|
|
83
80
|
this.clearFailTimeout();
|
|
84
|
-
this.updateStateAndViewFast({
|
|
85
|
-
phase: "resolved",
|
|
86
|
-
result: success ? "success" : "fail",
|
|
87
|
-
});
|
|
81
|
+
this.updateStateAndViewFast({ phase: "resolved", result: success ? "success" : "fail" });
|
|
88
82
|
this.resultTimeout = setTimeout(() => {
|
|
89
83
|
this.updateStateAndViewFast({ phase: "outro" });
|
|
90
84
|
void this.emit(this.EVENTS.QTE.RESULT, { success });
|
|
@@ -105,12 +99,5 @@ export class QteController extends ModuleController {
|
|
|
105
99
|
this.resultTimeout = null;
|
|
106
100
|
this.activeStartedAt = null;
|
|
107
101
|
};
|
|
108
|
-
getDefaultState = () => ({
|
|
109
|
-
isShow: false,
|
|
110
|
-
isForce: false,
|
|
111
|
-
id: "",
|
|
112
|
-
item: null,
|
|
113
|
-
phase: "idle",
|
|
114
|
-
result: "idle",
|
|
115
|
-
});
|
|
102
|
+
getDefaultState = () => ({ isShow: false, isForce: false, id: "", item: null, phase: "idle", result: "idle" });
|
|
116
103
|
}
|
package/dist/modules/view.d.ts
CHANGED
|
@@ -1,11 +1,10 @@
|
|
|
1
1
|
import { ModuleView } from "@vnejs/module.components";
|
|
2
2
|
import type { QtePluginConstants, QtePluginEvents, QtePluginParams, QtePluginSettings } from "../types.js";
|
|
3
3
|
import type { QtePluginControllerState } from "../utils/qte.js";
|
|
4
|
-
export declare class
|
|
4
|
+
export declare class QteViewView extends ModuleView<QtePluginEvents, QtePluginConstants, QtePluginSettings, QtePluginParams, QtePluginControllerState> {
|
|
5
5
|
name: string;
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
6
|
+
EVENT_UPDATE_VIEW: "vne:qte_view:update";
|
|
7
|
+
LOC_LABEL: string;
|
|
8
|
+
TRANSITION: number;
|
|
9
9
|
renderFunc: import("@vnejs/module.components").ViewRenderFunc<QtePluginControllerState>;
|
|
10
|
-
updateHandler: (state?: QtePluginControllerState | undefined) => Promise<void>;
|
|
11
10
|
}
|
package/dist/modules/view.js
CHANGED
|
@@ -1,10 +1,9 @@
|
|
|
1
1
|
import { ModuleView } from "@vnejs/module.components";
|
|
2
2
|
import { render } from "../view/index.js";
|
|
3
|
-
export class
|
|
3
|
+
export class QteViewView extends ModuleView {
|
|
4
4
|
name = "qte_view.view";
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
5
|
+
EVENT_UPDATE_VIEW = this.EVENTS.QTE_VIEW.UPDATE;
|
|
6
|
+
LOC_LABEL = this.PARAMS.QTE_VIEW.LOC_LABEL;
|
|
7
|
+
TRANSITION = this.PARAMS.QTE_VIEW.TRANSITION;
|
|
8
8
|
renderFunc = render;
|
|
9
|
-
updateHandler = this.onUpdateStoreComponent;
|
|
10
9
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vnejs/plugins.views.scenario.qte",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.4",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -36,6 +36,8 @@
|
|
|
36
36
|
"peerDependencies": {
|
|
37
37
|
"@vnejs/contracts.controls": "~0.2.0",
|
|
38
38
|
"@vnejs/module.components": "~0.2.0",
|
|
39
|
+
"@vnejs/module.core": "~0.2.0",
|
|
40
|
+
"@vnejs/module.controller.accept": "~0.2.0",
|
|
39
41
|
"@vnejs/shared": "~0.2.0",
|
|
40
42
|
"@vnejs/uis.react": "~0.2.0",
|
|
41
43
|
"@vnejs/uis.utils": "~0.2.0"
|
|
@@ -48,6 +50,8 @@
|
|
|
48
50
|
"@vnejs/contracts.scenario.qte": "~0.2.0",
|
|
49
51
|
"@vnejs/contracts.views.scenario.qte": "~0.2.0",
|
|
50
52
|
"@vnejs/module.components": "~0.2.0",
|
|
53
|
+
"@vnejs/module.core": "~0.2.0",
|
|
54
|
+
"@vnejs/module.controller.accept": "~0.2.0",
|
|
51
55
|
"@vnejs/shared": "~0.2.0",
|
|
52
56
|
"@vnejs/sources-set": "~0.2.0",
|
|
53
57
|
"@vnejs/uis.react": "~0.2.0",
|
package/src/index.ts
CHANGED
|
@@ -4,7 +4,8 @@ import "@vnejs/contracts.views.scenario.qte";
|
|
|
4
4
|
import { regPlugin } from "@vnejs/shared";
|
|
5
5
|
import { PARAMS, PLUGIN_NAME, SUBSCRIBE_EVENTS } from "@vnejs/contracts.views.scenario.qte";
|
|
6
6
|
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
7
|
+
import { QteViewController } from "./modules/controller.js";
|
|
8
|
+
import { QteViewControllerAccept } from "./modules/controller.accept.js";
|
|
9
|
+
import { QteViewView } from "./modules/view.js";
|
|
9
10
|
|
|
10
|
-
regPlugin(PLUGIN_NAME, { events: SUBSCRIBE_EVENTS, params: PARAMS }, [
|
|
11
|
+
regPlugin(PLUGIN_NAME, { events: SUBSCRIBE_EVENTS, params: PARAMS }, [QteViewController, QteViewControllerAccept, QteViewView]);
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { ModuleControllerAccept } from "@vnejs/module.controller.accept";
|
|
2
|
+
|
|
3
|
+
import type { QtePluginConstants, QtePluginEvents, QtePluginParams, QtePluginSettings } from "../types.js";
|
|
4
|
+
|
|
5
|
+
export class QteViewControllerAccept extends ModuleControllerAccept<QtePluginEvents, QtePluginConstants, QtePluginSettings, QtePluginParams> {
|
|
6
|
+
name = "qte_view.controller.accept";
|
|
7
|
+
|
|
8
|
+
EVENT_SHOW = this.EVENTS.QTE_VIEW.SHOW;
|
|
9
|
+
EVENT_HIDE = this.EVENTS.QTE_VIEW.HIDE;
|
|
10
|
+
EVENT_ACCEPT = this.EVENTS.QTE_VIEW.ACTION;
|
|
11
|
+
|
|
12
|
+
CONTROLS_ZINDEX = this.PARAMS.QTE_VIEW.ZINDEX;
|
|
13
|
+
|
|
14
|
+
onAccept = () => undefined;
|
|
15
|
+
}
|
|
@@ -6,16 +6,13 @@ import type { QtePluginConstants, QtePluginEvents, QtePluginParams, QtePluginSet
|
|
|
6
6
|
import type { QtePluginControllerState, QteVisibilityPayload } from "../utils/qte.js";
|
|
7
7
|
import { getFailAtProgress, getProgressFromElapsed, isProgressInsideZone } from "../utils/qte.js";
|
|
8
8
|
|
|
9
|
-
export class
|
|
9
|
+
export class QteViewController extends ModuleController<QtePluginEvents, QtePluginConstants, QtePluginSettings, QtePluginParams, QtePluginControllerState> {
|
|
10
10
|
name = "qte_view.controller";
|
|
11
11
|
|
|
12
|
-
|
|
12
|
+
EVENT_UPDATE_VIEW = this.EVENTS.QTE_VIEW.UPDATE;
|
|
13
13
|
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
[this.CONST.CONTROLS.BUTTONS.INTERACT]: () => void this.onAction(),
|
|
17
|
-
};
|
|
18
|
-
controlsIndex = this.PARAMS.QTE_VIEW.ZINDEX;
|
|
14
|
+
CONTROLS = {};
|
|
15
|
+
CONTROLS_INDEX = this.PARAMS.QTE_VIEW.ZINDEX;
|
|
19
16
|
|
|
20
17
|
activeStartedAt: number | null = null;
|
|
21
18
|
isResolved = false;
|
|
@@ -104,10 +101,7 @@ export class QteController extends ModuleController<QtePluginEvents, QtePluginCo
|
|
|
104
101
|
|
|
105
102
|
this.isResolved = true;
|
|
106
103
|
this.clearFailTimeout();
|
|
107
|
-
this.updateStateAndViewFast({
|
|
108
|
-
phase: "resolved",
|
|
109
|
-
result: success ? "success" : "fail",
|
|
110
|
-
});
|
|
104
|
+
this.updateStateAndViewFast({ phase: "resolved", result: success ? "success" : "fail" });
|
|
111
105
|
|
|
112
106
|
this.resultTimeout = setTimeout(() => {
|
|
113
107
|
this.updateStateAndViewFast({ phase: "outro" });
|
|
@@ -129,12 +123,5 @@ export class QteController extends ModuleController<QtePluginEvents, QtePluginCo
|
|
|
129
123
|
this.activeStartedAt = null;
|
|
130
124
|
};
|
|
131
125
|
|
|
132
|
-
getDefaultState = (): QtePluginControllerState => ({
|
|
133
|
-
isShow: false,
|
|
134
|
-
isForce: false,
|
|
135
|
-
id: "",
|
|
136
|
-
item: null,
|
|
137
|
-
phase: "idle",
|
|
138
|
-
result: "idle",
|
|
139
|
-
});
|
|
126
|
+
getDefaultState = (): QtePluginControllerState => ({ isShow: false, isForce: false, id: "", item: null, phase: "idle", result: "idle" });
|
|
140
127
|
}
|
package/src/modules/view.ts
CHANGED
|
@@ -4,13 +4,14 @@ import { render } from "../view/index.js";
|
|
|
4
4
|
import type { QtePluginConstants, QtePluginEvents, QtePluginParams, QtePluginSettings } from "../types.js";
|
|
5
5
|
import type { QtePluginControllerState } from "../utils/qte.js";
|
|
6
6
|
|
|
7
|
-
export class
|
|
7
|
+
export class QteViewView extends ModuleView<QtePluginEvents, QtePluginConstants, QtePluginSettings, QtePluginParams, QtePluginControllerState> {
|
|
8
8
|
name = "qte_view.view";
|
|
9
9
|
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
10
|
+
EVENT_UPDATE_VIEW = this.EVENTS.QTE_VIEW.UPDATE;
|
|
11
|
+
|
|
12
|
+
LOC_LABEL = this.PARAMS.QTE_VIEW.LOC_LABEL;
|
|
13
|
+
|
|
14
|
+
TRANSITION = this.PARAMS.QTE_VIEW.TRANSITION;
|
|
13
15
|
|
|
14
16
|
renderFunc = render;
|
|
15
|
-
updateHandler = this.onUpdateStoreComponent;
|
|
16
17
|
}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { beforeEach, describe, expect, it } from "vitest";
|
|
2
|
+
|
|
3
|
+
import { spyEvent } from "@vnejs/test-utils";
|
|
4
|
+
|
|
5
|
+
import { QteViewControllerAccept } from "../modules/controller.accept.js";
|
|
6
|
+
import { CONTROLS_EVENTS, createQteViewTestModule, registerQteViewPluginVne, SUBSCRIBE_EVENTS } from "./setup.js";
|
|
7
|
+
|
|
8
|
+
describe("QteViewControllerAccept", () => {
|
|
9
|
+
beforeEach(() => {
|
|
10
|
+
registerQteViewPluginVne();
|
|
11
|
+
});
|
|
12
|
+
|
|
13
|
+
it("SHOW pushes ACCEPT and INTERACT controls", async () => {
|
|
14
|
+
const { module, observer } = createQteViewTestModule(QteViewControllerAccept);
|
|
15
|
+
const accept = module as QteViewControllerAccept;
|
|
16
|
+
const push = spyEvent(observer, CONTROLS_EVENTS.PUSH);
|
|
17
|
+
|
|
18
|
+
await observer.emit(SUBSCRIBE_EVENTS.SHOW);
|
|
19
|
+
|
|
20
|
+
expect(push).toHaveBeenCalledExactlyOnceWith(
|
|
21
|
+
expect.objectContaining({
|
|
22
|
+
key: "qte_view.controller.accept",
|
|
23
|
+
checkNext: true,
|
|
24
|
+
index: accept.PARAMS.QTE_VIEW.ZINDEX + 1,
|
|
25
|
+
}),
|
|
26
|
+
);
|
|
27
|
+
expect(push.mock.calls[0][0].controls).toHaveProperty(accept.CONST.CONTROLS.BUTTONS.ACCEPT);
|
|
28
|
+
expect(push.mock.calls[0][0].controls).toHaveProperty(accept.CONST.CONTROLS.BUTTONS.INTERACT);
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
it("HIDE pops ACCEPT controls", async () => {
|
|
32
|
+
const { observer } = createQteViewTestModule(QteViewControllerAccept);
|
|
33
|
+
const pop = spyEvent(observer, CONTROLS_EVENTS.POP);
|
|
34
|
+
|
|
35
|
+
await observer.emit(SUBSCRIBE_EVENTS.HIDE);
|
|
36
|
+
|
|
37
|
+
expect(pop).toHaveBeenCalledExactlyOnceWith({ key: "qte_view.controller.accept" });
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
it("ACCEPT and INTERACT emit QTE_VIEW.ACTION", async () => {
|
|
41
|
+
const { module, observer } = createQteViewTestModule(QteViewControllerAccept);
|
|
42
|
+
const accept = module as QteViewControllerAccept;
|
|
43
|
+
const action = spyEvent(observer, SUBSCRIBE_EVENTS.ACTION);
|
|
44
|
+
|
|
45
|
+
accept.CONTROLS[accept.CONST.CONTROLS.BUTTONS.ACCEPT]();
|
|
46
|
+
accept.CONTROLS[accept.CONST.CONTROLS.BUTTONS.INTERACT]();
|
|
47
|
+
await Promise.resolve();
|
|
48
|
+
await Promise.resolve();
|
|
49
|
+
|
|
50
|
+
expect(action).toHaveBeenCalledTimes(2);
|
|
51
|
+
});
|
|
52
|
+
});
|
|
@@ -2,17 +2,17 @@ import { beforeEach, describe, expect, it, vi } from "vitest";
|
|
|
2
2
|
|
|
3
3
|
import { spyEvent } from "@vnejs/test-utils";
|
|
4
4
|
|
|
5
|
-
import {
|
|
5
|
+
import { QteViewController } from "../modules/controller.js";
|
|
6
6
|
import { createQteViewTestModule, registerQteViewPluginVne, QTE_EVENTS, SUBSCRIBE_EVENTS } from "./setup.js";
|
|
7
7
|
|
|
8
|
-
describe("
|
|
8
|
+
describe("QteViewController", () => {
|
|
9
9
|
beforeEach(() => {
|
|
10
10
|
registerQteViewPluginVne();
|
|
11
11
|
vi.useFakeTimers({ toFake: ["setTimeout", "clearTimeout", "performance"] });
|
|
12
12
|
});
|
|
13
13
|
|
|
14
14
|
it("OPENED bridge emits SHOW with payload", async () => {
|
|
15
|
-
const { observer } = createQteViewTestModule(
|
|
15
|
+
const { observer } = createQteViewTestModule(QteViewController);
|
|
16
16
|
const show = spyEvent(observer, SUBSCRIBE_EVENTS.SHOW);
|
|
17
17
|
const payload = { id: "door_lock", item: { start: 70, size: 20, duration: 1500 } };
|
|
18
18
|
|
|
@@ -22,66 +22,66 @@ describe("QteController", () => {
|
|
|
22
22
|
});
|
|
23
23
|
|
|
24
24
|
it("SHOW starts in initial, then intro, then active", async () => {
|
|
25
|
-
const { module, observer } = createQteViewTestModule(
|
|
25
|
+
const { module, observer } = createQteViewTestModule(QteViewController);
|
|
26
26
|
const item = { start: 70, size: 20, duration: 1500 };
|
|
27
|
-
const { INITIAL, TRANSITION } = (module as
|
|
27
|
+
const { INITIAL, TRANSITION } = (module as QteViewController).PARAMS.QTE_VIEW;
|
|
28
28
|
|
|
29
29
|
await observer.emit(SUBSCRIBE_EVENTS.SHOW, { id: "door_lock", item });
|
|
30
30
|
|
|
31
|
-
expect((module as
|
|
32
|
-
expect((module as
|
|
33
|
-
expect((module as
|
|
31
|
+
expect((module as QteViewController).state.id).toBe("door_lock");
|
|
32
|
+
expect((module as QteViewController).state.item).toEqual(item);
|
|
33
|
+
expect((module as QteViewController).state.phase).toBe("initial");
|
|
34
34
|
|
|
35
35
|
await vi.advanceTimersByTimeAsync(INITIAL);
|
|
36
|
-
expect((module as
|
|
36
|
+
expect((module as QteViewController).state.phase).toBe("intro");
|
|
37
37
|
|
|
38
38
|
await vi.advanceTimersByTimeAsync(TRANSITION - INITIAL);
|
|
39
|
-
expect((module as
|
|
40
|
-
expect((module as
|
|
39
|
+
expect((module as QteViewController).state.phase).toBe("active");
|
|
40
|
+
expect((module as QteViewController).activeStartedAt).not.toBeNull();
|
|
41
41
|
});
|
|
42
42
|
|
|
43
43
|
it("ACTION resolves success inside zone by elapsed time", async () => {
|
|
44
|
-
const { module, observer } = createQteViewTestModule(
|
|
44
|
+
const { module, observer } = createQteViewTestModule(QteViewController);
|
|
45
45
|
const result = spyEvent(observer, QTE_EVENTS.RESULT);
|
|
46
46
|
const item = { start: 40, size: 20, duration: 1000 };
|
|
47
47
|
|
|
48
48
|
await observer.emit(SUBSCRIBE_EVENTS.SHOW, { id: "door_lock", item });
|
|
49
|
-
await vi.advanceTimersByTimeAsync((module as
|
|
49
|
+
await vi.advanceTimersByTimeAsync((module as QteViewController).PARAMS.QTE_VIEW.TRANSITION);
|
|
50
50
|
await vi.advanceTimersByTimeAsync(500);
|
|
51
51
|
|
|
52
52
|
await observer.emit(SUBSCRIBE_EVENTS.ACTION);
|
|
53
53
|
|
|
54
|
-
expect((module as
|
|
54
|
+
expect((module as QteViewController).state.result).toBe("success");
|
|
55
55
|
|
|
56
|
-
await vi.advanceTimersByTimeAsync((module as
|
|
56
|
+
await vi.advanceTimersByTimeAsync((module as QteViewController).PARAMS.QTE_VIEW.RESULT_DELAY);
|
|
57
57
|
|
|
58
58
|
expect(result).toHaveBeenCalledExactlyOnceWith({ success: true });
|
|
59
59
|
});
|
|
60
60
|
|
|
61
61
|
it("ACTION resolves fail outside zone", async () => {
|
|
62
|
-
const { module, observer } = createQteViewTestModule(
|
|
62
|
+
const { module, observer } = createQteViewTestModule(QteViewController);
|
|
63
63
|
const item = { start: 70, size: 20, duration: 1000 };
|
|
64
64
|
|
|
65
65
|
await observer.emit(SUBSCRIBE_EVENTS.SHOW, { id: "door_lock", item });
|
|
66
|
-
await vi.advanceTimersByTimeAsync((module as
|
|
66
|
+
await vi.advanceTimersByTimeAsync((module as QteViewController).PARAMS.QTE_VIEW.TRANSITION);
|
|
67
67
|
await vi.advanceTimersByTimeAsync(100);
|
|
68
68
|
|
|
69
|
-
|
|
69
|
+
await observer.emit(SUBSCRIBE_EVENTS.ACTION);
|
|
70
70
|
|
|
71
|
-
expect((module as
|
|
71
|
+
expect((module as QteViewController).state.result).toBe("fail");
|
|
72
72
|
});
|
|
73
73
|
|
|
74
74
|
it("auto-fails when pointer leaves the zone", async () => {
|
|
75
|
-
const { module, observer } = createQteViewTestModule(
|
|
75
|
+
const { module, observer } = createQteViewTestModule(QteViewController);
|
|
76
76
|
const result = spyEvent(observer, QTE_EVENTS.RESULT);
|
|
77
77
|
const item = { start: 50, size: 10, duration: 1000 };
|
|
78
78
|
|
|
79
79
|
await observer.emit(SUBSCRIBE_EVENTS.SHOW, { id: "door_lock", item });
|
|
80
|
-
await vi.advanceTimersByTimeAsync((module as
|
|
80
|
+
await vi.advanceTimersByTimeAsync((module as QteViewController).PARAMS.QTE_VIEW.TRANSITION);
|
|
81
81
|
await vi.advanceTimersByTimeAsync(600);
|
|
82
|
-
await vi.advanceTimersByTimeAsync((module as
|
|
82
|
+
await vi.advanceTimersByTimeAsync((module as QteViewController).PARAMS.QTE_VIEW.RESULT_DELAY);
|
|
83
83
|
|
|
84
|
-
expect((module as
|
|
84
|
+
expect((module as QteViewController).state.result).toBe("fail");
|
|
85
85
|
expect(result).toHaveBeenCalledExactlyOnceWith({ success: false });
|
|
86
86
|
});
|
|
87
87
|
});
|
package/src/tests/setup.ts
CHANGED
|
@@ -27,6 +27,7 @@ export const createQteViewTestModule = <T extends Parameters<typeof baseCreateTe
|
|
|
27
27
|
stubSilentEvent(result.observer, QTE_VIEW_EVENTS.HIDE);
|
|
28
28
|
stubSilentEvent(result.observer, QTE_VIEW_EVENTS.SHOW_BEFORE);
|
|
29
29
|
stubSilentEvent(result.observer, QTE_VIEW_EVENTS.UPDATE);
|
|
30
|
+
stubSilentEvent(result.observer, QTE_VIEW_EVENTS.ACTION);
|
|
30
31
|
stubSilentEvent(result.observer, CONTROLS_EVENTS.PUSH);
|
|
31
32
|
stubSilentEvent(result.observer, CONTROLS_EVENTS.POP);
|
|
32
33
|
|