@vnejs/compatibility.scenario.choose-with-scenario.history 0.2.2 → 0.2.3
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.d.ts +1 -1
- package/dist/index.js +3 -1
- package/package.json +1 -1
- package/src/index.ts +3 -1
- package/src/tests/choose.history.test.ts +8 -12
package/dist/index.d.ts
CHANGED
|
@@ -4,6 +4,6 @@ import { ModuleCore } from "@vnejs/module.core";
|
|
|
4
4
|
import type { PluginConstants, PluginEvents, PluginParams, PluginSettings } from "./types.js";
|
|
5
5
|
export declare class CompatibilityScenarioChooseWithScenarioHistory extends ModuleCore<PluginEvents, PluginConstants, PluginSettings, PluginParams> {
|
|
6
6
|
name: string;
|
|
7
|
-
|
|
7
|
+
subscribe: () => void;
|
|
8
8
|
onChooseOptionBefore: () => undefined;
|
|
9
9
|
}
|
package/dist/index.js
CHANGED
|
@@ -5,7 +5,9 @@ import { regModule } from "@vnejs/shared";
|
|
|
5
5
|
const HISTORY_CHOICE_LOC_KEY = "choice";
|
|
6
6
|
export class CompatibilityScenarioChooseWithScenarioHistory extends ModuleCore {
|
|
7
7
|
name = "compatibility.scenario.choose-with-scenario.history";
|
|
8
|
-
|
|
8
|
+
subscribe = () => {
|
|
9
|
+
this.on(this.EVENTS.CHOOSE.OPTION_BEFORE, this.onChooseOptionBefore);
|
|
10
|
+
};
|
|
9
11
|
onChooseOptionBefore = () => void this.emit(this.EVENTS.HISTORY.ADD, { locKey: HISTORY_CHOICE_LOC_KEY });
|
|
10
12
|
}
|
|
11
13
|
regModule(CompatibilityScenarioChooseWithScenarioHistory);
|
package/package.json
CHANGED
package/src/index.ts
CHANGED
|
@@ -11,7 +11,9 @@ const HISTORY_CHOICE_LOC_KEY = "choice";
|
|
|
11
11
|
export class CompatibilityScenarioChooseWithScenarioHistory extends ModuleCore<PluginEvents, PluginConstants, PluginSettings, PluginParams> {
|
|
12
12
|
name = "compatibility.scenario.choose-with-scenario.history";
|
|
13
13
|
|
|
14
|
-
|
|
14
|
+
subscribe = () => {
|
|
15
|
+
this.on(this.EVENTS.CHOOSE.OPTION_BEFORE, this.onChooseOptionBefore);
|
|
16
|
+
};
|
|
15
17
|
|
|
16
18
|
onChooseOptionBefore = () => void this.emit(this.EVENTS.HISTORY.ADD, { locKey: HISTORY_CHOICE_LOC_KEY });
|
|
17
19
|
}
|
|
@@ -8,25 +8,21 @@ import { CHOOSE_EVENTS, createCompatibilityTestModule, HISTORY_EVENTS, registerC
|
|
|
8
8
|
describe("CompatibilityScenarioChooseWithScenarioHistory", () => {
|
|
9
9
|
beforeEach(() => registerCompatibilityVne());
|
|
10
10
|
|
|
11
|
-
it("
|
|
11
|
+
it("subscribe registers CHOOSE.OPTION_BEFORE handler", () => {
|
|
12
12
|
const { module, observer } = createCompatibilityTestModule(CompatibilityScenarioChooseWithScenarioHistory, { subscribe: false });
|
|
13
|
-
const reg = spyEvent(observer, CHOOSE_EVENTS.OPTION_BEFORE_REG);
|
|
14
13
|
|
|
15
|
-
|
|
14
|
+
(module as CompatibilityScenarioChooseWithScenarioHistory).subscribe();
|
|
16
15
|
|
|
17
|
-
expect(
|
|
18
|
-
|
|
16
|
+
expect(observer.subscribers[CHOOSE_EVENTS.OPTION_BEFORE]?.flatMap((group) => group.subscribers)).toEqual(
|
|
17
|
+
expect.arrayContaining([expect.objectContaining({ func: (module as CompatibilityScenarioChooseWithScenarioHistory).onChooseOptionBefore })]),
|
|
18
|
+
);
|
|
19
19
|
});
|
|
20
20
|
|
|
21
|
-
it("
|
|
22
|
-
const {
|
|
23
|
-
const reg = spyEvent(observer, CHOOSE_EVENTS.OPTION_BEFORE_REG);
|
|
21
|
+
it("CHOOSE.OPTION_BEFORE emits HISTORY.ADD with locKey choice", async () => {
|
|
22
|
+
const { observer } = createCompatibilityTestModule(CompatibilityScenarioChooseWithScenarioHistory);
|
|
24
23
|
const add = spyEvent(observer, HISTORY_EVENTS.ADD);
|
|
25
24
|
|
|
26
|
-
await (
|
|
27
|
-
|
|
28
|
-
const handler = reg.mock.calls[0]?.[0]?.handler as () => unknown;
|
|
29
|
-
await handler();
|
|
25
|
+
await observer.emit(CHOOSE_EVENTS.OPTION_BEFORE);
|
|
30
26
|
|
|
31
27
|
expect(add).toHaveBeenCalledOnce();
|
|
32
28
|
expect(add.mock.calls[0]?.[0]).toMatchObject({ locKey: "choice" });
|