@vnejs/plugins.views.scenario.interface 0.1.33 → 0.1.35
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/package.json +16 -3
- package/src/tests/controller.test.ts +41 -0
- package/src/tests/interface.test.ts +68 -0
- package/src/tests/setup.ts +54 -0
- package/tsconfig.json +9 -2
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vnejs/plugins.views.scenario.interface",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.35",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -18,7 +18,7 @@
|
|
|
18
18
|
"tsconfig.json"
|
|
19
19
|
],
|
|
20
20
|
"scripts": {
|
|
21
|
-
"test": "
|
|
21
|
+
"test": "npx @vnejs/monorepo test",
|
|
22
22
|
"build": "npx @vnejs/monorepo package",
|
|
23
23
|
"publish:major:plugin": "npm run publish:major",
|
|
24
24
|
"publish:minor:plugin": "npm run publish:minor",
|
|
@@ -44,6 +44,19 @@
|
|
|
44
44
|
"@vnejs/uis.utils": "~0.1.0"
|
|
45
45
|
},
|
|
46
46
|
"devDependencies": {
|
|
47
|
-
"@vnejs/configs.ts-common": "~0.1.0"
|
|
47
|
+
"@vnejs/configs.ts-common": "~0.1.0",
|
|
48
|
+
"@vnejs/configs.vitest": "~0.1.0",
|
|
49
|
+
"@vnejs/test-utils": "~0.1.0",
|
|
50
|
+
"@vnejs/contracts.text": "~0.1.0",
|
|
51
|
+
"@vnejs/sources-set": "~0.1.0",
|
|
52
|
+
"@vnejs/helpers": "~0.1.0",
|
|
53
|
+
"@vnejs/module.core": "~0.1.0",
|
|
54
|
+
"@vnejs/module.components": "~0.1.0",
|
|
55
|
+
"@vnejs/contracts.text.meet": "~0.1.0",
|
|
56
|
+
"@vnejs/contracts.text.wall": "~0.1.0",
|
|
57
|
+
"@vnejs/shared": "~0.1.0",
|
|
58
|
+
"@vnejs/uis.react": "~0.1.0",
|
|
59
|
+
"@vnejs/uis.utils": "~0.1.0",
|
|
60
|
+
"@vnejs/contracts.views.scenario.interface": "~0.1.0"
|
|
48
61
|
}
|
|
49
62
|
}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { beforeEach, describe, expect, it } from "vitest";
|
|
2
|
+
|
|
3
|
+
import { spyEvent } from "@vnejs/test-utils";
|
|
4
|
+
|
|
5
|
+
import { InterfaceController } from "../modules/controller.js";
|
|
6
|
+
import { createInterfaceTestModule, PARAMS, registerInterfacePluginVne, SUBSCRIBE_EVENTS } from "./setup.js";
|
|
7
|
+
|
|
8
|
+
describe("InterfaceController", () => {
|
|
9
|
+
beforeEach(() => {
|
|
10
|
+
registerInterfacePluginVne();
|
|
11
|
+
});
|
|
12
|
+
|
|
13
|
+
it("init emits default view", () => {
|
|
14
|
+
const { module, observer } = createInterfaceTestModule(InterfaceController, { subscribe: false });
|
|
15
|
+
const view = spyEvent(observer, SUBSCRIBE_EVENTS.VIEW);
|
|
16
|
+
|
|
17
|
+
(module as InterfaceController).init();
|
|
18
|
+
|
|
19
|
+
expect(view).toHaveBeenCalledExactlyOnceWith({ view: PARAMS.DEFAULT_VIEW, isForce: true });
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
it("onShowChanged emits VIEW_SHOW when interface becomes visible", async () => {
|
|
23
|
+
const { module, observer } = createInterfaceTestModule(InterfaceController, {
|
|
24
|
+
state: { interface: { view: "line", isShow: true, isVisible: false } },
|
|
25
|
+
});
|
|
26
|
+
const viewShow = spyEvent(observer, SUBSCRIBE_EVENTS.VIEW_SHOW);
|
|
27
|
+
|
|
28
|
+
await observer.emit(SUBSCRIBE_EVENTS.SHOW_CHANGED, {});
|
|
29
|
+
|
|
30
|
+
expect(viewShow).toHaveBeenCalledOnce();
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
it("onTextChanged updates controller tokens", async () => {
|
|
34
|
+
const { module, observer } = createInterfaceTestModule(InterfaceController);
|
|
35
|
+
|
|
36
|
+
await observer.emit(SUBSCRIBE_EVENTS.TEXT_CHANGED, { tokens: ["Hello"], uid: "1", tokensVisible: 1 });
|
|
37
|
+
|
|
38
|
+
expect((module as InterfaceController).state.tokens).toEqual(["Hello"]);
|
|
39
|
+
expect((module as InterfaceController).state.uid).toBe("1");
|
|
40
|
+
});
|
|
41
|
+
});
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import { beforeEach, describe, expect, it } from "vitest";
|
|
2
|
+
|
|
3
|
+
import { spyEvent } from "@vnejs/test-utils";
|
|
4
|
+
|
|
5
|
+
import { Interface } from "../modules/interface.js";
|
|
6
|
+
import { createInterfaceTestModule, PARAMS, registerInterfacePluginVne, SCENARIO_EVENTS, SUBSCRIBE_EVENTS, TEXT_EVENTS } from "./setup.js";
|
|
7
|
+
|
|
8
|
+
describe("Interface", () => {
|
|
9
|
+
beforeEach(() => {
|
|
10
|
+
registerInterfacePluginVne();
|
|
11
|
+
});
|
|
12
|
+
|
|
13
|
+
it("init registers scenario line exec and text emit before handlers", async () => {
|
|
14
|
+
const { module, observer } = createInterfaceTestModule(Interface, { subscribe: false });
|
|
15
|
+
const lineExecReg = spyEvent(observer, SCENARIO_EVENTS.LINE_EXEC_REG);
|
|
16
|
+
const textEmitBeforeReg = spyEvent(observer, TEXT_EVENTS.EMIT_BEFORE_REG);
|
|
17
|
+
|
|
18
|
+
await (module as Interface).init();
|
|
19
|
+
|
|
20
|
+
expect(lineExecReg).toHaveBeenCalledOnce();
|
|
21
|
+
expect(textEmitBeforeReg).toHaveBeenCalledOnce();
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
it("onLineExec show sets isShow", async () => {
|
|
25
|
+
const { module } = createInterfaceTestModule(Interface);
|
|
26
|
+
|
|
27
|
+
await (module as Interface).onLineExec({ line: "show" });
|
|
28
|
+
|
|
29
|
+
expect((module as Interface).state.isShow).toBe(true);
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
it("onLineExec hide clears isShow", async () => {
|
|
33
|
+
const { module } = createInterfaceTestModule(Interface);
|
|
34
|
+
|
|
35
|
+
(module as Interface).state.isShow = true;
|
|
36
|
+
await (module as Interface).onLineExec({ line: "hide" });
|
|
37
|
+
|
|
38
|
+
expect((module as Interface).state.isShow).toBe(false);
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
it("onLineExec view changes view", async () => {
|
|
42
|
+
const { module } = createInterfaceTestModule(Interface);
|
|
43
|
+
const viewChanged = spyEvent(module.observer!, SUBSCRIBE_EVENTS.VIEW_CHANGED);
|
|
44
|
+
|
|
45
|
+
await (module as Interface).onLineExec({ line: "view wall" });
|
|
46
|
+
|
|
47
|
+
expect((module as Interface).state.view).toBe("wall");
|
|
48
|
+
expect(viewChanged).toHaveBeenCalledOnce();
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
it("onInteract emits VISIBLE when interface is hidden", async () => {
|
|
52
|
+
const { module, observer } = createInterfaceTestModule(Interface);
|
|
53
|
+
const visible = spyEvent(observer, SUBSCRIBE_EVENTS.VISIBLE);
|
|
54
|
+
|
|
55
|
+
await observer.emit(SUBSCRIBE_EVENTS.INTERACT);
|
|
56
|
+
|
|
57
|
+
expect(visible).toHaveBeenCalledOnce();
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
it("onStateClear resets to default view", async () => {
|
|
61
|
+
const { module } = createInterfaceTestModule(Interface);
|
|
62
|
+
|
|
63
|
+
(module as Interface).state = { view: "wall", isShow: true, isVisible: true };
|
|
64
|
+
await (module as Interface).onStateClear();
|
|
65
|
+
|
|
66
|
+
expect((module as Interface).state).toEqual({ view: PARAMS.DEFAULT_VIEW, isShow: false, isVisible: false });
|
|
67
|
+
});
|
|
68
|
+
});
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { CONSTANTS as CONTROLS_CONST, PLUGIN_NAME as CONTROLS, SUBSCRIBE_EVENTS as CONTROLS_EVENTS } from "@vnejs/contracts.controls";
|
|
2
|
+
import { SUBSCRIBE_EVENTS as SCENARIO_EVENTS } from "@vnejs/contracts.core.scenario";
|
|
3
|
+
import { SUBSCRIBE_EVENTS as TEXT_EVENTS, PLUGIN_NAME as TEXT } from "@vnejs/contracts.text";
|
|
4
|
+
import { PARAMS, PLUGIN_NAME, SUBSCRIBE_EVENTS } from "@vnejs/contracts.views.scenario.interface";
|
|
5
|
+
import { SourcesSet } from "@vnejs/sources-set";
|
|
6
|
+
import {
|
|
7
|
+
createTestModule as baseCreateTestModule,
|
|
8
|
+
registerCoreVne,
|
|
9
|
+
registerVnePlugin,
|
|
10
|
+
stubEvent,
|
|
11
|
+
stubSilentEvent,
|
|
12
|
+
} from "@vnejs/test-utils";
|
|
13
|
+
|
|
14
|
+
export const registerInterfacePluginVne = () => {
|
|
15
|
+
registerCoreVne();
|
|
16
|
+
registerVnePlugin(CONTROLS, { constants: CONTROLS_CONST, events: CONTROLS_EVENTS });
|
|
17
|
+
registerVnePlugin(TEXT, { events: TEXT_EVENTS });
|
|
18
|
+
registerVnePlugin(PLUGIN_NAME, { events: SUBSCRIBE_EVENTS, params: PARAMS });
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
export const createInterfaceTestModule = <T extends Parameters<typeof baseCreateTestModule>[0]>(
|
|
22
|
+
ModuleClass: T,
|
|
23
|
+
options: Parameters<typeof baseCreateTestModule>[1] = {},
|
|
24
|
+
) => {
|
|
25
|
+
const result = baseCreateTestModule(ModuleClass, {
|
|
26
|
+
state: {
|
|
27
|
+
interface: { view: PARAMS.DEFAULT_VIEW, isShow: false, isVisible: false },
|
|
28
|
+
text: { tokens: [], uid: "", texts: [], speaker: "" },
|
|
29
|
+
scenario: { label: "start" },
|
|
30
|
+
...(options.state ?? {}),
|
|
31
|
+
},
|
|
32
|
+
shared: {
|
|
33
|
+
viewForceAnimationSources: new SourcesSet(),
|
|
34
|
+
interfaceTextShowAllTokensOnChange: true,
|
|
35
|
+
...(options.shared ?? {}),
|
|
36
|
+
},
|
|
37
|
+
...options,
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
stubEvent(result.observer, TEXT_EVENTS.REPLACE, ({ text }) => text);
|
|
41
|
+
stubSilentEvent(result.observer, SUBSCRIBE_EVENTS.VIEW_UPDATE);
|
|
42
|
+
stubSilentEvent(result.observer, SUBSCRIBE_EVENTS.VIEW_SHOW);
|
|
43
|
+
stubSilentEvent(result.observer, SUBSCRIBE_EVENTS.VIEW_HIDE);
|
|
44
|
+
stubSilentEvent(result.observer, SUBSCRIBE_EVENTS.SHOW_CHANGED);
|
|
45
|
+
stubSilentEvent(result.observer, SUBSCRIBE_EVENTS.VISIBLE_CHANGED);
|
|
46
|
+
stubSilentEvent(result.observer, SUBSCRIBE_EVENTS.VISIBLE);
|
|
47
|
+
stubSilentEvent(result.observer, SUBSCRIBE_EVENTS.STATE_CHANGED);
|
|
48
|
+
stubSilentEvent(result.observer, CONTROLS_EVENTS.PUSH);
|
|
49
|
+
stubSilentEvent(result.observer, CONTROLS_EVENTS.POP);
|
|
50
|
+
|
|
51
|
+
return result;
|
|
52
|
+
};
|
|
53
|
+
|
|
54
|
+
export { SUBSCRIBE_EVENTS, PARAMS, PLUGIN_NAME, SCENARIO_EVENTS, TEXT_EVENTS, CONTROLS_EVENTS };
|
package/tsconfig.json
CHANGED
|
@@ -5,6 +5,13 @@
|
|
|
5
5
|
"outDir": "dist",
|
|
6
6
|
"jsx": "react-jsx"
|
|
7
7
|
},
|
|
8
|
-
"include": [
|
|
9
|
-
|
|
8
|
+
"include": [
|
|
9
|
+
"src/**/*.ts",
|
|
10
|
+
"src/**/*.tsx"
|
|
11
|
+
],
|
|
12
|
+
"exclude": [
|
|
13
|
+
"dist",
|
|
14
|
+
"node_modules",
|
|
15
|
+
"src/tests"
|
|
16
|
+
]
|
|
10
17
|
}
|