@vnejs/plugins.views.achievement 0.1.18 → 0.1.19

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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vnejs/plugins.views.achievement",
3
- "version": "0.1.18",
3
+ "version": "0.1.19",
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": "echo \"Error: no test specified\" && exit 1",
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",
@@ -41,6 +41,16 @@
41
41
  "@vnejs/uis.utils": "~0.1.0"
42
42
  },
43
43
  "devDependencies": {
44
- "@vnejs/configs.ts-common": "~0.1.0"
44
+ "@vnejs/configs.ts-common": "~0.1.0",
45
+ "@vnejs/configs.vitest": "~0.1.0",
46
+ "@vnejs/test-utils": "~0.1.0",
47
+ "@vnejs/contracts.canvas.layer": "~0.1.0",
48
+ "@vnejs/contracts.views.achievement": "~0.1.0",
49
+ "@vnejs/helpers": "~0.1.0",
50
+ "@vnejs/module.core": "~0.1.0",
51
+ "@vnejs/module.components": "~0.1.0",
52
+ "@vnejs/shared": "~0.1.0",
53
+ "@vnejs/uis.react": "~0.1.0",
54
+ "@vnejs/uis.utils": "~0.1.0"
45
55
  }
46
56
  }
@@ -0,0 +1,45 @@
1
+ import { beforeEach, describe, expect, it } from "vitest";
2
+
3
+ import { spyEvent } from "@vnejs/test-utils";
4
+
5
+ import { Achievement } from "../modules/achievement.js";
6
+ import { createAchievementTestModule, registerAchievementPluginVne, STORAGE_EVENTS, SUBSCRIBE_EVENTS } from "./setup.js";
7
+
8
+ describe("Achievement", () => {
9
+ beforeEach(() => {
10
+ registerAchievementPluginVne();
11
+ });
12
+
13
+ it("UNLOCK stores value and emits UNLOCKED and APPEND for new achievement", async () => {
14
+ const { observer } = createAchievementTestModule(Achievement);
15
+ const unlocked = spyEvent(observer, SUBSCRIBE_EVENTS.UNLOCKED);
16
+ const append = spyEvent(observer, SUBSCRIBE_EVENTS.APPEND);
17
+ const storageSet = spyEvent(observer, STORAGE_EVENTS.SET);
18
+
19
+ await observer.emit(SUBSCRIBE_EVENTS.UNLOCK, { id: "kekw" });
20
+
21
+ expect(unlocked).toHaveBeenCalledExactlyOnceWith({ id: "kekw" });
22
+ expect(storageSet).toHaveBeenCalledOnce();
23
+ expect(append).toHaveBeenCalledExactlyOnceWith({ id: "kekw" });
24
+ });
25
+
26
+ it("UNLOCK skips APPEND when already unlocked and isSkipIfPossible", async () => {
27
+ const { observer, storage } = createAchievementTestModule(Achievement);
28
+ const append = spyEvent(observer, SUBSCRIBE_EVENTS.APPEND);
29
+
30
+ storage.set("kekw", 1);
31
+
32
+ await observer.emit(SUBSCRIBE_EVENTS.UNLOCK, { id: "kekw", isSkipIfPossible: true });
33
+
34
+ expect(append).not.toHaveBeenCalled();
35
+ });
36
+
37
+ it("CLEAR removes all storage for module", async () => {
38
+ const { observer } = createAchievementTestModule(Achievement);
39
+ const rmAll = spyEvent(observer, STORAGE_EVENTS.RM_ALL);
40
+
41
+ await observer.emit(SUBSCRIBE_EVENTS.CLEAR);
42
+
43
+ expect(rmAll).toHaveBeenCalledExactlyOnceWith({ module: "achievement" });
44
+ });
45
+ });
@@ -0,0 +1,55 @@
1
+ import { CONSTANTS as SCENARIO_CONST } from "@vnejs/contracts.core.scenario";
2
+ import { beforeEach, describe, expect, it, vi } from "vitest";
3
+
4
+ import { spyEvent } from "@vnejs/test-utils";
5
+
6
+ import { AchievementExec } from "../modules/exec.js";
7
+ import { createAchievementTestModule, registerAchievementPluginVne, SUBSCRIBE_EVENTS } from "./setup.js";
8
+
9
+ describe("AchievementExec", () => {
10
+ beforeEach(() => {
11
+ registerAchievementPluginVne();
12
+ });
13
+
14
+ it("line exec unlock emits UNLOCK", async () => {
15
+ const { module, observer } = createAchievementTestModule(AchievementExec, { subscribe: false });
16
+ const unlock = spyEvent(observer, SUBSCRIBE_EVENTS.UNLOCK);
17
+
18
+ await (module as AchievementExec).init();
19
+ await (module as AchievementExec).onLineExec({ line: 'unlock kekw', keywords: [] });
20
+
21
+ expect(unlock).toHaveBeenCalledExactlyOnceWith({ id: "kekw", isSkipIfPossible: false });
22
+ });
23
+
24
+ it("line exec with skip_if_possible keyword passes isSkipIfPossible", async () => {
25
+ const { module, observer } = createAchievementTestModule(AchievementExec, { subscribe: false });
26
+ const unlock = spyEvent(observer, SUBSCRIBE_EVENTS.UNLOCK);
27
+
28
+ await (module as AchievementExec).onLineExec({
29
+ line: 'unlock kekw',
30
+ keywords: [SCENARIO_CONST.LINE_KEYWORDS.SKIP_IF_POSSIBLE],
31
+ });
32
+
33
+ expect(unlock).toHaveBeenCalledExactlyOnceWith({ id: "kekw", isSkipIfPossible: true });
34
+ });
35
+
36
+ it("line load unlock emits LOAD", async () => {
37
+ const { module, observer } = createAchievementTestModule(AchievementExec, { subscribe: false });
38
+ const load = spyEvent(observer, SUBSCRIBE_EVENTS.LOAD);
39
+
40
+ await (module as AchievementExec).onLineLoad({ line: 'unlock kekw' });
41
+
42
+ expect(load).toHaveBeenCalledOnce();
43
+ });
44
+
45
+ it("line exec calls emitNext", async () => {
46
+ const { module, observer } = createAchievementTestModule(AchievementExec, { subscribe: false });
47
+ const next = vi.fn();
48
+
49
+ observer.subscribe("vne:scenario:next", next);
50
+
51
+ await (module as AchievementExec).onLineExec({ line: 'unlock kekw' });
52
+
53
+ expect(next).toHaveBeenCalledOnce();
54
+ });
55
+ });
@@ -0,0 +1,23 @@
1
+ import { beforeEach, describe, expect, it } from "vitest";
2
+
3
+ import { spyEvent } from "@vnejs/test-utils";
4
+ import { SUBSCRIBE_EVENTS as LOGS_EVENTS } from "@vnejs/contracts.core.logs";
5
+
6
+ import { AchievementLogs } from "../modules/logs.js";
7
+ import { createAchievementTestModule, registerAchievementPluginVne, SUBSCRIBE_EVENTS } from "./setup.js";
8
+
9
+ describe("AchievementLogs", () => {
10
+ beforeEach(() => {
11
+ registerAchievementPluginVne();
12
+ });
13
+
14
+ it("UNLOCKED emits log with unlocked action", async () => {
15
+ const { observer } = createAchievementTestModule(AchievementLogs);
16
+ const log = spyEvent(observer, LOGS_EVENTS.EMIT);
17
+
18
+ await observer.emit(SUBSCRIBE_EVENTS.UNLOCKED, { id: "kekw" });
19
+
20
+ expect(log).toHaveBeenCalledOnce();
21
+ expect(log.mock.calls[0][0]).toMatchObject({ module: "achievement.logs", value: { action: "unlocked", id: "kekw" } });
22
+ });
23
+ });
@@ -0,0 +1,50 @@
1
+ import { CONSTANTS as LAYER_CONST, PLUGIN_NAME as LAYER, SETTINGS_KEYS as LAYER_SETTINGS } from "@vnejs/contracts.canvas.layer";
2
+ import { SUBSCRIBE_EVENTS as MEDIA_EVENTS } from "@vnejs/contracts.core.media";
3
+ import { SUBSCRIBE_EVENTS as STORAGE_EVENTS } from "@vnejs/contracts.core.storage";
4
+ import { CONSTANTS, PARAMS, PLUGIN_NAME, SUBSCRIBE_EVENTS } from "@vnejs/contracts.views.achievement";
5
+ import {
6
+ createTestModule as baseCreateTestModule,
7
+ registerCoreVne,
8
+ registerVnePlugin,
9
+ stubEvent,
10
+ stubSilentEvent,
11
+ } from "@vnejs/test-utils";
12
+
13
+ export const registerAchievementPluginVne = () => {
14
+ registerCoreVne();
15
+ registerVnePlugin(LAYER, { constants: LAYER_CONST, settings: LAYER_SETTINGS });
16
+ registerVnePlugin(PLUGIN_NAME, { constants: CONSTANTS, events: SUBSCRIBE_EVENTS, params: PARAMS });
17
+ };
18
+
19
+ export const createAchievementTestModule = <T extends Parameters<typeof baseCreateTestModule>[0]>(
20
+ ModuleClass: T,
21
+ options: Parameters<typeof baseCreateTestModule>[1] = {},
22
+ ) => {
23
+ const storage = new Map<string, unknown>();
24
+
25
+ const result = baseCreateTestModule(ModuleClass, {
26
+ state: {
27
+ "achievement.controller": { array: [], isShow: false },
28
+ ...(options.state ?? {}),
29
+ },
30
+ shared: {
31
+ settings: { [LAYER_SETTINGS.QUALITY]: LAYER_CONST.QUALITIES.FHD },
32
+ ...(options.shared ?? {}),
33
+ },
34
+ ...options,
35
+ });
36
+
37
+ stubEvent(result.observer, STORAGE_EVENTS.GET, ({ key }: { key?: string } = {}) => storage.get(key ?? ""));
38
+ stubSilentEvent(result.observer, STORAGE_EVENTS.SET, ({ key, value }: { key?: string; value?: unknown } = {}) => {
39
+ storage.set(key ?? "", value);
40
+ });
41
+ stubSilentEvent(result.observer, STORAGE_EVENTS.RM_ALL, () => storage.clear());
42
+ stubEvent(result.observer, MEDIA_EVENTS.LOAD, () => ({ src: "icon.png" }));
43
+ stubSilentEvent(result.observer, SUBSCRIBE_EVENTS.APPEND);
44
+ stubSilentEvent(result.observer, SUBSCRIBE_EVENTS.UPDATE);
45
+ stubSilentEvent(result.observer, SUBSCRIBE_EVENTS.LOAD);
46
+
47
+ return { ...result, storage };
48
+ };
49
+
50
+ export { SUBSCRIBE_EVENTS, PARAMS, PLUGIN_NAME, STORAGE_EVENTS };
package/tsconfig.json CHANGED
@@ -6,5 +6,5 @@
6
6
  "jsx": "react-jsx"
7
7
  },
8
8
  "include": ["src/**/*.ts", "src/**/*.tsx"],
9
- "exclude": ["dist", "node_modules"]
9
+ "exclude": ["dist", "node_modules", "src/tests"]
10
10
  }