@vnejs/plugins.controllers.screens.gallery 0.0.0-stage → 0.2.26
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 -0
- package/dist/index.js +31 -0
- package/dist/modules/controller.accept.d.ts +12 -0
- package/dist/modules/controller.accept.js +26 -0
- package/dist/modules/controller.audio.d.ts +11 -0
- package/dist/modules/controller.audio.js +10 -0
- package/dist/modules/controller.bg.d.ts +14 -0
- package/dist/modules/controller.bg.js +12 -0
- package/dist/modules/controller.d.ts +15 -0
- package/dist/modules/controller.grid.d.ts +20 -0
- package/dist/modules/controller.grid.js +25 -0
- package/dist/modules/controller.js +16 -0
- package/dist/modules/controller.pages.d.ts +12 -0
- package/dist/modules/controller.pages.items.d.ts +27 -0
- package/dist/modules/controller.pages.items.js +29 -0
- package/dist/modules/controller.pages.js +17 -0
- package/dist/modules/controller.preload.d.ts +28 -0
- package/dist/modules/controller.preload.js +29 -0
- package/dist/modules/controller.tabs.d.ts +33 -0
- package/dist/modules/controller.tabs.js +29 -0
- package/dist/modules/gallery.d.ts +10 -0
- package/dist/modules/gallery.js +14 -0
- package/dist/modules/hide.controls.d.ts +8 -0
- package/dist/modules/hide.controls.js +7 -0
- package/dist/modules/hide.state.d.ts +6 -0
- package/dist/modules/hide.state.js +5 -0
- package/dist/modules/view.d.ts +10 -0
- package/dist/modules/view.js +9 -0
- package/dist/types.d.ts +29 -0
- package/dist/types.js +1 -0
- package/dist/utils/gallery.d.ts +21 -0
- package/dist/utils/gallery.js +2 -0
- package/dist/view/components/GalleryClose.d.ts +2 -0
- package/dist/view/components/GalleryClose.js +3 -0
- package/dist/view/components/GalleryControls.d.ts +7 -0
- package/dist/view/components/GalleryControls.js +10 -0
- package/dist/view/components/GalleryItems.d.ts +7 -0
- package/dist/view/components/GalleryItems.js +22 -0
- package/dist/view/components/GalleryPages.d.ts +7 -0
- package/dist/view/components/GalleryPages.js +6 -0
- package/dist/view/components/index.d.ts +4 -0
- package/dist/view/components/index.js +4 -0
- package/dist/view/index.d.ts +3 -0
- package/dist/view/index.js +9 -0
- package/package.json +75 -4
- package/src/index.ts +35 -0
- package/src/modules/controller.accept.ts +41 -0
- package/src/modules/controller.audio.ts +16 -0
- package/src/modules/controller.bg.ts +25 -0
- package/src/modules/controller.grid.ts +41 -0
- package/src/modules/controller.pages.items.ts +47 -0
- package/src/modules/controller.pages.ts +28 -0
- package/src/modules/controller.preload.ts +48 -0
- package/src/modules/controller.tabs.ts +49 -0
- package/src/modules/controller.ts +28 -0
- package/src/modules/gallery.ts +25 -0
- package/src/modules/hide.controls.ts +17 -0
- package/src/modules/hide.state.ts +9 -0
- package/src/modules/view.ts +17 -0
- package/src/tests/accept.test.ts +98 -0
- package/src/tests/audio.test.ts +86 -0
- package/src/tests/controller.bg.test.ts +84 -0
- package/src/tests/gallery.test.ts +49 -0
- package/src/tests/grid.test.ts +189 -0
- package/src/tests/hide.controls.test.ts +55 -0
- package/src/tests/hide.state.test.ts +27 -0
- package/src/tests/pages.items.test.ts +48 -0
- package/src/tests/pages.test.ts +98 -0
- package/src/tests/preload.test.ts +75 -0
- package/src/tests/setup.ts +67 -0
- package/src/tests/tabs.test.ts +101 -0
- package/src/types.ts +42 -0
- package/src/utils/gallery.ts +26 -0
- package/src/view/components/GalleryClose.tsx +12 -0
- package/src/view/components/GalleryControls.tsx +26 -0
- package/src/view/components/GalleryItems.tsx +51 -0
- package/src/view/components/GalleryPages.tsx +24 -0
- package/src/view/components/index.ts +4 -0
- package/src/view/index.tsx +67 -0
- package/tsconfig.json +10 -0
- package/README.md +0 -3
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
import { beforeEach, describe, expect, it } from "vitest";
|
|
2
|
+
|
|
3
|
+
import { spyEvent } from "@vnejs/test-utils";
|
|
4
|
+
|
|
5
|
+
import { GalleryControllerAccept } from "../modules/controller.accept.js";
|
|
6
|
+
|
|
7
|
+
import { CONTROLS_EVENTS, createGalleryTestModule, registerGalleryPluginVne, SUBSCRIBE_EVENTS } from "./setup.js";
|
|
8
|
+
|
|
9
|
+
describe("GalleryControllerAccept", () => {
|
|
10
|
+
beforeEach(() => {
|
|
11
|
+
registerGalleryPluginVne();
|
|
12
|
+
});
|
|
13
|
+
|
|
14
|
+
const select = async (
|
|
15
|
+
observer: ReturnType<typeof createGalleryTestModule>["observer"],
|
|
16
|
+
gridItems: Array<Record<string, unknown>>,
|
|
17
|
+
gridRow: number | null = 0,
|
|
18
|
+
gridColumn: number | null = 0,
|
|
19
|
+
) => {
|
|
20
|
+
await observer.emit(SUBSCRIBE_EVENTS.UPDATE_STATE, { gridItems, gridRow, gridColumn });
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
it("SHOW pushes ACCEPT and INTERACT controls", async () => {
|
|
24
|
+
const { module, observer } = createGalleryTestModule(GalleryControllerAccept);
|
|
25
|
+
const accept = module as GalleryControllerAccept;
|
|
26
|
+
const push = spyEvent(observer, CONTROLS_EVENTS.PUSH);
|
|
27
|
+
|
|
28
|
+
await observer.emit(SUBSCRIBE_EVENTS.SHOW);
|
|
29
|
+
|
|
30
|
+
expect(push).toHaveBeenCalledExactlyOnceWith(
|
|
31
|
+
expect.objectContaining({
|
|
32
|
+
key: "gallery.controller.accept",
|
|
33
|
+
checkNext: true,
|
|
34
|
+
index: accept.PARAMS.GALLERY.ZINDEX + 1,
|
|
35
|
+
}),
|
|
36
|
+
);
|
|
37
|
+
expect(push.mock.calls[0][0].controls).toHaveProperty(accept.CONST.CONTROLS.BUTTONS.ACCEPT);
|
|
38
|
+
expect(push.mock.calls[0][0].controls).toHaveProperty(accept.CONST.CONTROLS.BUTTONS.INTERACT);
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
it("HIDE pops ACCEPT controls", async () => {
|
|
42
|
+
const { observer } = createGalleryTestModule(GalleryControllerAccept);
|
|
43
|
+
const pop = spyEvent(observer, CONTROLS_EVENTS.POP);
|
|
44
|
+
|
|
45
|
+
await observer.emit(SUBSCRIBE_EVENTS.SHOW);
|
|
46
|
+
await observer.emit(SUBSCRIBE_EVENTS.HIDE);
|
|
47
|
+
|
|
48
|
+
expect(pop).toHaveBeenCalledExactlyOnceWith({ key: "gallery.controller.accept" });
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
it("ACCEPT emits CHOOSE for an opened slot", async () => {
|
|
52
|
+
const { observer } = createGalleryTestModule(GalleryControllerAccept);
|
|
53
|
+
const choose = spyEvent(observer, SUBSCRIBE_EVENTS.CHOOSE);
|
|
54
|
+
const opened = { isOpened: true, fullName: "cg1", mediaType: "gallery", variants: [{ isOpened: true, name: "cg1" }] };
|
|
55
|
+
|
|
56
|
+
await select(observer, [opened]);
|
|
57
|
+
await observer.emit(SUBSCRIBE_EVENTS.ACCEPT);
|
|
58
|
+
|
|
59
|
+
expect(choose).toHaveBeenCalledExactlyOnceWith({
|
|
60
|
+
index: 0,
|
|
61
|
+
fullName: "cg1",
|
|
62
|
+
mediaType: "gallery",
|
|
63
|
+
layerChildType: undefined,
|
|
64
|
+
isOpened: true,
|
|
65
|
+
variants: opened.variants,
|
|
66
|
+
});
|
|
67
|
+
});
|
|
68
|
+
|
|
69
|
+
it("ACCEPT does not emit CHOOSE for a locked slot", async () => {
|
|
70
|
+
const { observer } = createGalleryTestModule(GalleryControllerAccept);
|
|
71
|
+
const choose = spyEvent(observer, SUBSCRIBE_EVENTS.CHOOSE);
|
|
72
|
+
|
|
73
|
+
await select(observer, [{ isOpened: false, fullName: "cg1", mediaType: "gallery" }]);
|
|
74
|
+
await observer.emit(SUBSCRIBE_EVENTS.ACCEPT);
|
|
75
|
+
|
|
76
|
+
expect(choose).not.toHaveBeenCalled();
|
|
77
|
+
});
|
|
78
|
+
|
|
79
|
+
it("ACCEPT does not emit CHOOSE for a stub slot", async () => {
|
|
80
|
+
const { observer } = createGalleryTestModule(GalleryControllerAccept);
|
|
81
|
+
const choose = spyEvent(observer, SUBSCRIBE_EVENTS.CHOOSE);
|
|
82
|
+
|
|
83
|
+
await select(observer, [{ isStub: true }]);
|
|
84
|
+
await observer.emit(SUBSCRIBE_EVENTS.ACCEPT);
|
|
85
|
+
|
|
86
|
+
expect(choose).not.toHaveBeenCalled();
|
|
87
|
+
});
|
|
88
|
+
|
|
89
|
+
it("ACCEPT does not emit CHOOSE without a selection", async () => {
|
|
90
|
+
const { observer } = createGalleryTestModule(GalleryControllerAccept);
|
|
91
|
+
const choose = spyEvent(observer, SUBSCRIBE_EVENTS.CHOOSE);
|
|
92
|
+
|
|
93
|
+
await select(observer, [{ isOpened: true, fullName: "cg1" }], null, null);
|
|
94
|
+
await observer.emit(SUBSCRIBE_EVENTS.ACCEPT);
|
|
95
|
+
|
|
96
|
+
expect(choose).not.toHaveBeenCalled();
|
|
97
|
+
});
|
|
98
|
+
});
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
import { beforeEach, describe, expect, it } from "vitest";
|
|
2
|
+
|
|
3
|
+
import { spyEvent } from "@vnejs/test-utils";
|
|
4
|
+
|
|
5
|
+
import { SUBSCRIBE_EVENTS as AUDIO_EVENTS } from "@vnejs/contracts.audio";
|
|
6
|
+
import { SETTINGS_KEYS as MUSIC_SETTINGS } from "@vnejs/contracts.audio.music";
|
|
7
|
+
|
|
8
|
+
import { GalleryControllerAudio } from "../modules/controller.audio.js";
|
|
9
|
+
|
|
10
|
+
import { createGalleryTestModule, registerGalleryPluginVne, SUBSCRIBE_EVENTS } from "./setup.js";
|
|
11
|
+
|
|
12
|
+
describe("GalleryControllerAudio", () => {
|
|
13
|
+
beforeEach(() => {
|
|
14
|
+
registerGalleryPluginVne();
|
|
15
|
+
});
|
|
16
|
+
|
|
17
|
+
it("does not subscribe when AUDIO_NAME is empty", () => {
|
|
18
|
+
const { module } = createGalleryTestModule(GalleryControllerAudio, { subscribe: false });
|
|
19
|
+
|
|
20
|
+
(module as GalleryControllerAudio).init();
|
|
21
|
+
(module as GalleryControllerAudio).subscribe();
|
|
22
|
+
|
|
23
|
+
expect((module as GalleryControllerAudio).AUDIO_NAME).toBe("");
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
it("SHOW pauses global audio and plays gallery audio when configured", async () => {
|
|
27
|
+
const { module, observer } = createGalleryTestModule(GalleryControllerAudio, { subscribe: false });
|
|
28
|
+
|
|
29
|
+
(module as GalleryControllerAudio).AUDIO_NAME = "gallery-theme";
|
|
30
|
+
(module as GalleryControllerAudio).init();
|
|
31
|
+
(module as GalleryControllerAudio).subscribe();
|
|
32
|
+
|
|
33
|
+
const pause = spyEvent(observer, AUDIO_EVENTS.GLOBAL_PAUSE);
|
|
34
|
+
const play = spyEvent(observer, AUDIO_EVENTS.PLAY);
|
|
35
|
+
|
|
36
|
+
await observer.emit(SUBSCRIBE_EVENTS.SHOW);
|
|
37
|
+
|
|
38
|
+
expect(pause).toHaveBeenCalledOnce();
|
|
39
|
+
expect(play).toHaveBeenCalledOnce();
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
it("SHOW plays overlay audio at MUSIC.VOLUME from settings", async () => {
|
|
43
|
+
const { module, observer } = createGalleryTestModule(GalleryControllerAudio, { subscribe: false });
|
|
44
|
+
|
|
45
|
+
(module as GalleryControllerAudio).AUDIO_NAME = "gallery-theme";
|
|
46
|
+
(module as GalleryControllerAudio).shared.settings[MUSIC_SETTINGS.VOLUME] = 10;
|
|
47
|
+
(module as GalleryControllerAudio).init();
|
|
48
|
+
(module as GalleryControllerAudio).subscribe();
|
|
49
|
+
|
|
50
|
+
const play = spyEvent(observer, AUDIO_EVENTS.PLAY);
|
|
51
|
+
|
|
52
|
+
await observer.emit(SUBSCRIBE_EVENTS.SHOW);
|
|
53
|
+
|
|
54
|
+
expect(play).toHaveBeenCalledExactlyOnceWith(expect.objectContaining({ layer: "view", name: "gallery-theme", volume: 10 }));
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
it("HIDE stops gallery audio and resumes global audio when configured", async () => {
|
|
58
|
+
const { module, observer } = createGalleryTestModule(GalleryControllerAudio, { subscribe: false });
|
|
59
|
+
|
|
60
|
+
(module as GalleryControllerAudio).AUDIO_NAME = "gallery-theme";
|
|
61
|
+
(module as GalleryControllerAudio).init();
|
|
62
|
+
(module as GalleryControllerAudio).subscribe();
|
|
63
|
+
|
|
64
|
+
const stop = spyEvent(observer, AUDIO_EVENTS.STOP);
|
|
65
|
+
const resume = spyEvent(observer, AUDIO_EVENTS.GLOBAL_RESUME);
|
|
66
|
+
|
|
67
|
+
await observer.emit(SUBSCRIBE_EVENTS.HIDE);
|
|
68
|
+
|
|
69
|
+
expect(stop).toHaveBeenCalledOnce();
|
|
70
|
+
expect(resume).toHaveBeenCalledOnce();
|
|
71
|
+
});
|
|
72
|
+
|
|
73
|
+
it("PRELOAD loads gallery audio media when configured", async () => {
|
|
74
|
+
const { module, observer } = createGalleryTestModule(GalleryControllerAudio, { subscribe: false });
|
|
75
|
+
|
|
76
|
+
(module as GalleryControllerAudio).AUDIO_NAME = "gallery-theme";
|
|
77
|
+
(module as GalleryControllerAudio).init();
|
|
78
|
+
(module as GalleryControllerAudio).subscribe();
|
|
79
|
+
|
|
80
|
+
const mediaLoad = spyEvent(observer, AUDIO_EVENTS.MEDIA_LOAD);
|
|
81
|
+
|
|
82
|
+
await observer.emit(SUBSCRIBE_EVENTS.PRELOAD);
|
|
83
|
+
|
|
84
|
+
expect(mediaLoad).toHaveBeenCalledOnce();
|
|
85
|
+
});
|
|
86
|
+
});
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
import { beforeEach, describe, expect, it } from "vitest";
|
|
2
|
+
|
|
3
|
+
import { spyEvent, stubEvent } from "@vnejs/test-utils";
|
|
4
|
+
|
|
5
|
+
import { SUBSCRIBE_EVENTS as MEDIA_EVENTS } from "@vnejs/contracts.core.media";
|
|
6
|
+
import { SUBSCRIBE_EVENTS as MEMORY_EVENTS } from "@vnejs/contracts.core.memory";
|
|
7
|
+
|
|
8
|
+
import { GalleryControllerBg } from "../modules/controller.bg.js";
|
|
9
|
+
|
|
10
|
+
import { createGalleryTestModule, PARAMS, registerGalleryPluginVne, SUBSCRIBE_EVENTS } from "./setup.js";
|
|
11
|
+
|
|
12
|
+
describe("GalleryControllerBg", () => {
|
|
13
|
+
beforeEach(() => {
|
|
14
|
+
registerGalleryPluginVne();
|
|
15
|
+
});
|
|
16
|
+
|
|
17
|
+
it("SHOW loads bg and emits UPDATE_STATE with bgSrc", async () => {
|
|
18
|
+
const { observer } = createGalleryTestModule(GalleryControllerBg);
|
|
19
|
+
stubEvent(observer, MEDIA_EVENTS.LOAD, () => ({ src: "bg.png" }));
|
|
20
|
+
const mediaLoad = spyEvent(observer, MEDIA_EVENTS.LOAD);
|
|
21
|
+
const stateUpdate = spyEvent(observer, SUBSCRIBE_EVENTS.UPDATE_STATE);
|
|
22
|
+
const updateFast = spyEvent(observer, SUBSCRIBE_EVENTS.UPDATE_FAST);
|
|
23
|
+
|
|
24
|
+
await observer.emit(SUBSCRIBE_EVENTS.SHOW);
|
|
25
|
+
|
|
26
|
+
expect(mediaLoad).toHaveBeenCalledOnce();
|
|
27
|
+
expect(mediaLoad.mock.calls[0][0]).toMatchObject({
|
|
28
|
+
name: `bg/${PARAMS.BACKGROUND}`,
|
|
29
|
+
mediaType: "view",
|
|
30
|
+
});
|
|
31
|
+
expect(stateUpdate).toHaveBeenCalledWith({ bgSrc: "bg.png" });
|
|
32
|
+
expect(updateFast).not.toHaveBeenCalled();
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
it("PRELOAD loads bg media without UPDATE_STATE", async () => {
|
|
36
|
+
const { observer } = createGalleryTestModule(GalleryControllerBg);
|
|
37
|
+
stubEvent(observer, MEDIA_EVENTS.LOAD, () => ({ src: "bg.png" }));
|
|
38
|
+
const mediaLoad = spyEvent(observer, MEDIA_EVENTS.LOAD);
|
|
39
|
+
const stateUpdate = spyEvent(observer, SUBSCRIBE_EVENTS.UPDATE_STATE);
|
|
40
|
+
|
|
41
|
+
await observer.emit(SUBSCRIBE_EVENTS.PRELOAD);
|
|
42
|
+
|
|
43
|
+
expect(mediaLoad).toHaveBeenCalledOnce();
|
|
44
|
+
expect(mediaLoad.mock.calls[0][0]).toMatchObject({
|
|
45
|
+
name: `bg/${PARAMS.BACKGROUND}`,
|
|
46
|
+
mediaType: "view",
|
|
47
|
+
});
|
|
48
|
+
expect(stateUpdate).not.toHaveBeenCalled();
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
it("MEMORY.CLEARED is a no-op when not shown", async () => {
|
|
52
|
+
const { observer } = createGalleryTestModule(GalleryControllerBg);
|
|
53
|
+
stubEvent(observer, MEDIA_EVENTS.LOAD, () => ({ src: "bg.png" }));
|
|
54
|
+
const mediaLoad = spyEvent(observer, MEDIA_EVENTS.LOAD);
|
|
55
|
+
const stateUpdate = spyEvent(observer, SUBSCRIBE_EVENTS.UPDATE_STATE);
|
|
56
|
+
const updateFast = spyEvent(observer, SUBSCRIBE_EVENTS.UPDATE_FAST);
|
|
57
|
+
|
|
58
|
+
await observer.emit(MEMORY_EVENTS.CLEARED);
|
|
59
|
+
|
|
60
|
+
expect(mediaLoad).not.toHaveBeenCalled();
|
|
61
|
+
expect(stateUpdate).not.toHaveBeenCalled();
|
|
62
|
+
expect(updateFast).not.toHaveBeenCalled();
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
it("MEMORY.CLEARED updates bgSrc and UPDATE_FAST when shown", async () => {
|
|
66
|
+
const { observer } = createGalleryTestModule(GalleryControllerBg);
|
|
67
|
+
stubEvent(observer, MEDIA_EVENTS.LOAD, () => ({ src: "bg.png" }));
|
|
68
|
+
const mediaLoad = spyEvent(observer, MEDIA_EVENTS.LOAD);
|
|
69
|
+
const stateUpdate = spyEvent(observer, SUBSCRIBE_EVENTS.UPDATE_STATE);
|
|
70
|
+
const updateFast = spyEvent(observer, SUBSCRIBE_EVENTS.UPDATE_FAST);
|
|
71
|
+
|
|
72
|
+
await observer.emit(SUBSCRIBE_EVENTS.SHOW);
|
|
73
|
+
await observer.emit(SUBSCRIBE_EVENTS.UPDATE_STATE, { isShow: true });
|
|
74
|
+
mediaLoad.mockClear();
|
|
75
|
+
stateUpdate.mockClear();
|
|
76
|
+
updateFast.mockClear();
|
|
77
|
+
|
|
78
|
+
await observer.emit(MEMORY_EVENTS.CLEARED);
|
|
79
|
+
|
|
80
|
+
expect(mediaLoad).toHaveBeenCalledOnce();
|
|
81
|
+
expect(stateUpdate).toHaveBeenCalledWith({ bgSrc: "bg.png" });
|
|
82
|
+
expect(updateFast).toHaveBeenCalledOnce();
|
|
83
|
+
});
|
|
84
|
+
});
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { beforeEach, describe, expect, it } from "vitest";
|
|
2
|
+
|
|
3
|
+
import { spyEvent } from "@vnejs/test-utils";
|
|
4
|
+
|
|
5
|
+
import { Gallery } from "../modules/gallery.js";
|
|
6
|
+
|
|
7
|
+
import { createGalleryTestModule, registerGalleryPluginVne, STORAGE_EVENTS, SUBSCRIBE_EVENTS } from "./setup.js";
|
|
8
|
+
|
|
9
|
+
describe("Gallery", () => {
|
|
10
|
+
beforeEach(() => {
|
|
11
|
+
registerGalleryPluginVne();
|
|
12
|
+
});
|
|
13
|
+
|
|
14
|
+
it("OPEN sets storage value", async () => {
|
|
15
|
+
const { observer } = createGalleryTestModule(Gallery);
|
|
16
|
+
const storageSet = spyEvent(observer, STORAGE_EVENTS.SET);
|
|
17
|
+
|
|
18
|
+
await observer.emit(SUBSCRIBE_EVENTS.OPEN, { key: "scene1" });
|
|
19
|
+
|
|
20
|
+
expect(storageSet).toHaveBeenCalledExactlyOnceWith({ module: "gallery", key: "scene1", value: 1 });
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
it("CHECK returns true when storage value matches", async () => {
|
|
24
|
+
const { observer, storage } = createGalleryTestModule(Gallery);
|
|
25
|
+
|
|
26
|
+
storage.set("scene1", 1);
|
|
27
|
+
|
|
28
|
+
const [result] = await observer.emit(SUBSCRIBE_EVENTS.CHECK, { key: "scene1" });
|
|
29
|
+
|
|
30
|
+
expect(result).toBe(true);
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
it("CHECK returns false when storage value missing", async () => {
|
|
34
|
+
const { observer } = createGalleryTestModule(Gallery);
|
|
35
|
+
|
|
36
|
+
const [result] = await observer.emit(SUBSCRIBE_EVENTS.CHECK, { key: "scene1" });
|
|
37
|
+
|
|
38
|
+
expect(result).toBe(false);
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
it("CLEAR removes all storage", async () => {
|
|
42
|
+
const { observer } = createGalleryTestModule(Gallery);
|
|
43
|
+
const rmAll = spyEvent(observer, STORAGE_EVENTS.RM_ALL);
|
|
44
|
+
|
|
45
|
+
await observer.emit(SUBSCRIBE_EVENTS.CLEAR);
|
|
46
|
+
|
|
47
|
+
expect(rmAll).toHaveBeenCalledExactlyOnceWith({ module: "gallery" });
|
|
48
|
+
});
|
|
49
|
+
});
|
|
@@ -0,0 +1,189 @@
|
|
|
1
|
+
import { beforeEach, describe, expect, it } from "vitest";
|
|
2
|
+
|
|
3
|
+
import { spyEvent } from "@vnejs/test-utils";
|
|
4
|
+
|
|
5
|
+
import { GalleryControllerGrid } from "../modules/controller.grid.js";
|
|
6
|
+
|
|
7
|
+
import { CONTROLS_EVENTS, createGalleryTestModule, PARAMS, registerGalleryPluginVne, SUBSCRIBE_EVENTS } from "./setup.js";
|
|
8
|
+
|
|
9
|
+
describe("GalleryControllerGrid", () => {
|
|
10
|
+
beforeEach(() => {
|
|
11
|
+
registerGalleryPluginVne();
|
|
12
|
+
});
|
|
13
|
+
|
|
14
|
+
const seedGrid = async (
|
|
15
|
+
observer: ReturnType<typeof createGalleryTestModule>["observer"],
|
|
16
|
+
gridIndex = 0,
|
|
17
|
+
gridsCount = 2,
|
|
18
|
+
itemsCount = PARAMS.ROWS * PARAMS.COLUMNS,
|
|
19
|
+
) => {
|
|
20
|
+
await observer.emit(SUBSCRIBE_EVENTS.UPDATE_STATE, {
|
|
21
|
+
gridIndex,
|
|
22
|
+
gridsCount,
|
|
23
|
+
gridItems: Array.from({ length: itemsCount }, (_, index) => ({ isOpened: true, fullName: `cg${index}` })),
|
|
24
|
+
});
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
it("SHOW pushes arrow controls above the controller layer", async () => {
|
|
28
|
+
const { module, observer } = createGalleryTestModule(GalleryControllerGrid);
|
|
29
|
+
const grid = module as GalleryControllerGrid;
|
|
30
|
+
const push = spyEvent(observer, CONTROLS_EVENTS.PUSH);
|
|
31
|
+
|
|
32
|
+
await observer.emit(SUBSCRIBE_EVENTS.SHOW);
|
|
33
|
+
|
|
34
|
+
expect(grid.gridRow).toBeNull();
|
|
35
|
+
expect(grid.gridColumn).toBeNull();
|
|
36
|
+
expect(push).toHaveBeenCalledExactlyOnceWith(
|
|
37
|
+
expect.objectContaining({
|
|
38
|
+
key: "gallery.controller.grid",
|
|
39
|
+
checkNext: true,
|
|
40
|
+
index: grid.PARAMS.GALLERY.ZINDEX + 1,
|
|
41
|
+
}),
|
|
42
|
+
);
|
|
43
|
+
expect(push.mock.calls[0][0].controls).toHaveProperty(grid.CONST.CONTROLS.BUTTONS.ARROW_UP);
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
it("HIDE cleanup unsets gridRow and gridColumn", async () => {
|
|
47
|
+
const { module, observer } = createGalleryTestModule(GalleryControllerGrid);
|
|
48
|
+
const grid = module as GalleryControllerGrid;
|
|
49
|
+
|
|
50
|
+
await seedGrid(observer);
|
|
51
|
+
grid.incRow();
|
|
52
|
+
|
|
53
|
+
const stateUpdate = spyEvent(observer, SUBSCRIBE_EVENTS.UPDATE_STATE);
|
|
54
|
+
const updateFast = spyEvent(observer, SUBSCRIBE_EVENTS.UPDATE_FAST);
|
|
55
|
+
|
|
56
|
+
await observer.emit(SUBSCRIBE_EVENTS.HIDE);
|
|
57
|
+
|
|
58
|
+
expect(grid.gridRow).toBeNull();
|
|
59
|
+
expect(grid.gridColumn).toBeNull();
|
|
60
|
+
expect(grid.state.gridRow).toBeUndefined();
|
|
61
|
+
expect(grid.state.gridColumn).toBeUndefined();
|
|
62
|
+
expect(stateUpdate).toHaveBeenCalledWith({ gridRow: undefined, gridColumn: undefined });
|
|
63
|
+
expect(updateFast).toHaveBeenCalledOnce();
|
|
64
|
+
});
|
|
65
|
+
|
|
66
|
+
it("GRID_CLEAR resets position to null and emits UPDATE_STATE", async () => {
|
|
67
|
+
const { module, observer } = createGalleryTestModule(GalleryControllerGrid);
|
|
68
|
+
const grid = module as GalleryControllerGrid;
|
|
69
|
+
await seedGrid(observer);
|
|
70
|
+
|
|
71
|
+
grid.incRow();
|
|
72
|
+
grid.incColumn();
|
|
73
|
+
|
|
74
|
+
const stateUpdate = spyEvent(observer, SUBSCRIBE_EVENTS.UPDATE_STATE);
|
|
75
|
+
|
|
76
|
+
await observer.emit(SUBSCRIBE_EVENTS.GRID_CLEAR);
|
|
77
|
+
|
|
78
|
+
expect(grid.gridRow).toBeNull();
|
|
79
|
+
expect(grid.gridColumn).toBeNull();
|
|
80
|
+
expect(stateUpdate).toHaveBeenCalledExactlyOnceWith({ gridRow: null, gridColumn: null });
|
|
81
|
+
});
|
|
82
|
+
|
|
83
|
+
it("first ARROW selects 0,0 and emits UPDATE_STATE plus UPDATE_FAST", async () => {
|
|
84
|
+
const { module, observer } = createGalleryTestModule(GalleryControllerGrid);
|
|
85
|
+
const grid = module as GalleryControllerGrid;
|
|
86
|
+
await seedGrid(observer);
|
|
87
|
+
|
|
88
|
+
const stateUpdate = spyEvent(observer, SUBSCRIBE_EVENTS.UPDATE_STATE);
|
|
89
|
+
const updateFast = spyEvent(observer, SUBSCRIBE_EVENTS.UPDATE_FAST);
|
|
90
|
+
|
|
91
|
+
grid.incRow();
|
|
92
|
+
|
|
93
|
+
expect(grid.gridRow).toBe(0);
|
|
94
|
+
expect(grid.gridColumn).toBe(0);
|
|
95
|
+
expect(stateUpdate).toHaveBeenCalledExactlyOnceWith({ gridRow: 0, gridColumn: 0 });
|
|
96
|
+
expect(updateFast).toHaveBeenCalledOnce();
|
|
97
|
+
});
|
|
98
|
+
|
|
99
|
+
it("GRID_UPDATE_ITEMS loads slots via PAGE_ITEMS_GET and emits gridItems", async () => {
|
|
100
|
+
const { module, observer } = createGalleryTestModule(GalleryControllerGrid);
|
|
101
|
+
const grid = module as GalleryControllerGrid;
|
|
102
|
+
|
|
103
|
+
grid.PARAMS.GALLERY.TABS = {
|
|
104
|
+
cg: {
|
|
105
|
+
locKey: "tabs.cg",
|
|
106
|
+
content: [{ check: "a", mediaType: "gallery", name: "a", fullName: "a" }],
|
|
107
|
+
},
|
|
108
|
+
};
|
|
109
|
+
|
|
110
|
+
const pageItemsGet = spyEvent(observer, SUBSCRIBE_EVENTS.PAGE_ITEMS_GET);
|
|
111
|
+
const stateUpdate = spyEvent(observer, SUBSCRIBE_EVENTS.UPDATE_STATE);
|
|
112
|
+
|
|
113
|
+
await observer.emit(SUBSCRIBE_EVENTS.UPDATE_STATE, {
|
|
114
|
+
gridIndex: 0,
|
|
115
|
+
gridsCount: 1,
|
|
116
|
+
tab: "cg",
|
|
117
|
+
});
|
|
118
|
+
await observer.emit(SUBSCRIBE_EVENTS.GRID_UPDATE_ITEMS);
|
|
119
|
+
|
|
120
|
+
expect(pageItemsGet).toHaveBeenCalledOnce();
|
|
121
|
+
expect(stateUpdate).toHaveBeenCalledWith({ gridItems: expect.any(Array) });
|
|
122
|
+
});
|
|
123
|
+
|
|
124
|
+
it("does not count stub slots toward navigation bounds", async () => {
|
|
125
|
+
const { module, observer } = createGalleryTestModule(GalleryControllerGrid);
|
|
126
|
+
const grid = module as GalleryControllerGrid;
|
|
127
|
+
|
|
128
|
+
await observer.emit(SUBSCRIBE_EVENTS.UPDATE_STATE, {
|
|
129
|
+
gridIndex: 0,
|
|
130
|
+
gridsCount: 1,
|
|
131
|
+
gridItems: [
|
|
132
|
+
{ isOpened: true, fullName: "a" },
|
|
133
|
+
{ isOpened: true, fullName: "b" },
|
|
134
|
+
{ isStub: true },
|
|
135
|
+
{ isStub: true },
|
|
136
|
+
{ isStub: true },
|
|
137
|
+
{ isStub: true },
|
|
138
|
+
{ isStub: true },
|
|
139
|
+
{ isStub: true },
|
|
140
|
+
{ isStub: true },
|
|
141
|
+
],
|
|
142
|
+
});
|
|
143
|
+
|
|
144
|
+
expect(grid.cachedItemsCount).toBe(2);
|
|
145
|
+
expect(grid.isCellInGrid(0, 1)).toBe(true);
|
|
146
|
+
expect(grid.isCellInGrid(0, 2)).toBe(false);
|
|
147
|
+
expect(grid.isCellInGrid(1, 0)).toBe(false);
|
|
148
|
+
|
|
149
|
+
grid.gridRow = 0;
|
|
150
|
+
grid.gridColumn = 0;
|
|
151
|
+
grid.incColumn();
|
|
152
|
+
grid.incColumn();
|
|
153
|
+
|
|
154
|
+
expect(grid.gridRow).toBe(0);
|
|
155
|
+
expect(grid.gridColumn).toBe(1);
|
|
156
|
+
});
|
|
157
|
+
|
|
158
|
+
it("GRID_UPDATE_ITEMS snaps selection from a stub cell to the nearest real slot", async () => {
|
|
159
|
+
const { module, observer } = createGalleryTestModule(GalleryControllerGrid);
|
|
160
|
+
const grid = module as GalleryControllerGrid;
|
|
161
|
+
|
|
162
|
+
grid.PARAMS.GALLERY.TABS = {
|
|
163
|
+
cg: {
|
|
164
|
+
locKey: "tabs.cg",
|
|
165
|
+
content: [
|
|
166
|
+
{ check: "a", mediaType: "gallery", name: "a", fullName: "a" },
|
|
167
|
+
{ check: "b", mediaType: "gallery", name: "b", fullName: "b" },
|
|
168
|
+
],
|
|
169
|
+
},
|
|
170
|
+
};
|
|
171
|
+
|
|
172
|
+
await observer.emit(SUBSCRIBE_EVENTS.UPDATE_STATE, {
|
|
173
|
+
gridIndex: 0,
|
|
174
|
+
gridsCount: 1,
|
|
175
|
+
tab: "cg",
|
|
176
|
+
gridRow: 1,
|
|
177
|
+
gridColumn: 0,
|
|
178
|
+
});
|
|
179
|
+
|
|
180
|
+
const stateUpdate = spyEvent(observer, SUBSCRIBE_EVENTS.UPDATE_STATE);
|
|
181
|
+
|
|
182
|
+
await observer.emit(SUBSCRIBE_EVENTS.GRID_UPDATE_ITEMS);
|
|
183
|
+
|
|
184
|
+
expect(grid.cachedItemsCount).toBe(2);
|
|
185
|
+
expect(grid.gridRow).toBe(0);
|
|
186
|
+
expect(grid.gridColumn).toBe(0);
|
|
187
|
+
expect(stateUpdate).toHaveBeenCalledWith({ gridRow: 0, gridColumn: 0 });
|
|
188
|
+
});
|
|
189
|
+
});
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import { beforeEach, describe, expect, it } from "vitest";
|
|
2
|
+
|
|
3
|
+
import { spyEvent } from "@vnejs/test-utils";
|
|
4
|
+
|
|
5
|
+
import { GalleryHideControls } from "../modules/hide.controls.js";
|
|
6
|
+
|
|
7
|
+
import { CONTROLS_EVENTS, createGalleryTestModule, registerGalleryPluginVne, SUBSCRIBE_EVENTS } from "./setup.js";
|
|
8
|
+
|
|
9
|
+
describe("GalleryHideControls", () => {
|
|
10
|
+
beforeEach(() => {
|
|
11
|
+
registerGalleryPluginVne();
|
|
12
|
+
});
|
|
13
|
+
|
|
14
|
+
it("SHOW pushes BACK, MENU and GAMEMENU controls", async () => {
|
|
15
|
+
const { module, observer } = createGalleryTestModule(GalleryHideControls);
|
|
16
|
+
const hide = module as GalleryHideControls;
|
|
17
|
+
const push = spyEvent(observer, CONTROLS_EVENTS.PUSH);
|
|
18
|
+
|
|
19
|
+
await observer.emit(SUBSCRIBE_EVENTS.SHOW);
|
|
20
|
+
|
|
21
|
+
expect(push).toHaveBeenCalledExactlyOnceWith(
|
|
22
|
+
expect.objectContaining({
|
|
23
|
+
key: "gallery.hide.controls",
|
|
24
|
+
checkNext: true,
|
|
25
|
+
index: hide.PARAMS.GALLERY.ZINDEX + 1,
|
|
26
|
+
}),
|
|
27
|
+
);
|
|
28
|
+
expect(push.mock.calls[0][0].controls).toHaveProperty(hide.CONST.CONTROLS.BUTTONS.BACK);
|
|
29
|
+
expect(push.mock.calls[0][0].controls).toHaveProperty(hide.CONST.CONTROLS.BUTTONS.MENU);
|
|
30
|
+
expect(push.mock.calls[0][0].controls).toHaveProperty(hide.CONST.CONTROLS.BUTTONS.GAMEMENU);
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
it("HIDE pops hide.controls", async () => {
|
|
34
|
+
const { observer } = createGalleryTestModule(GalleryHideControls);
|
|
35
|
+
const pop = spyEvent(observer, CONTROLS_EVENTS.POP);
|
|
36
|
+
|
|
37
|
+
await observer.emit(SUBSCRIBE_EVENTS.SHOW);
|
|
38
|
+
await observer.emit(SUBSCRIBE_EVENTS.HIDE);
|
|
39
|
+
|
|
40
|
+
expect(pop).toHaveBeenCalledExactlyOnceWith({ key: "gallery.hide.controls" });
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
it("BACK, MENU and GAMEMENU emit GALLERY.HIDE", async () => {
|
|
44
|
+
const { module, observer } = createGalleryTestModule(GalleryHideControls);
|
|
45
|
+
const hide = module as GalleryHideControls;
|
|
46
|
+
const hideEvent = spyEvent(observer, SUBSCRIBE_EVENTS.HIDE);
|
|
47
|
+
|
|
48
|
+
hide.CONTROLS[hide.CONST.CONTROLS.BUTTONS.BACK]();
|
|
49
|
+
hide.CONTROLS[hide.CONST.CONTROLS.BUTTONS.MENU]();
|
|
50
|
+
hide.CONTROLS[hide.CONST.CONTROLS.BUTTONS.GAMEMENU]();
|
|
51
|
+
await new Promise((resolve) => setTimeout(resolve, 0));
|
|
52
|
+
|
|
53
|
+
expect(hideEvent).toHaveBeenCalledTimes(3);
|
|
54
|
+
});
|
|
55
|
+
});
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { beforeEach, describe, expect, it } from "vitest";
|
|
2
|
+
|
|
3
|
+
import { spyEvent } from "@vnejs/test-utils";
|
|
4
|
+
|
|
5
|
+
import { SUBSCRIBE_EVENTS as STATE_EVENTS } from "@vnejs/contracts.core.state";
|
|
6
|
+
|
|
7
|
+
import { GalleryHideState } from "../modules/hide.state.js";
|
|
8
|
+
|
|
9
|
+
import { createGalleryTestModule, registerGalleryPluginVne, SUBSCRIBE_EVENTS } from "./setup.js";
|
|
10
|
+
|
|
11
|
+
describe("GalleryHideState", () => {
|
|
12
|
+
beforeEach(() => {
|
|
13
|
+
registerGalleryPluginVne();
|
|
14
|
+
});
|
|
15
|
+
|
|
16
|
+
it("STATE.SET and STATE.CLEAR emit HIDE with isForce", async () => {
|
|
17
|
+
const { observer } = createGalleryTestModule(GalleryHideState);
|
|
18
|
+
const hide = spyEvent(observer, SUBSCRIBE_EVENTS.HIDE);
|
|
19
|
+
|
|
20
|
+
await observer.emit(STATE_EVENTS.SET);
|
|
21
|
+
await observer.emit(STATE_EVENTS.CLEAR);
|
|
22
|
+
|
|
23
|
+
expect(hide).toHaveBeenCalledTimes(2);
|
|
24
|
+
expect(hide).toHaveBeenNthCalledWith(1, { isForce: true });
|
|
25
|
+
expect(hide).toHaveBeenNthCalledWith(2, { isForce: true });
|
|
26
|
+
});
|
|
27
|
+
});
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { beforeEach, describe, expect, it } from "vitest";
|
|
2
|
+
|
|
3
|
+
import { spyEvent, stubEvent } from "@vnejs/test-utils";
|
|
4
|
+
|
|
5
|
+
import { SUBSCRIBE_EVENTS as MEDIA_EVENTS } from "@vnejs/contracts.core.media";
|
|
6
|
+
|
|
7
|
+
import { GalleryControllerPagesItems } from "../modules/controller.pages.items.js";
|
|
8
|
+
|
|
9
|
+
import { createGalleryTestModule, registerGalleryPluginVne, SUBSCRIBE_EVENTS } from "./setup.js";
|
|
10
|
+
|
|
11
|
+
describe("GalleryControllerPagesItems", () => {
|
|
12
|
+
beforeEach(() => {
|
|
13
|
+
registerGalleryPluginVne();
|
|
14
|
+
});
|
|
15
|
+
|
|
16
|
+
it("PAGE_ITEMS_GET returns locked item without media load when CHECK is false", async () => {
|
|
17
|
+
const { module, observer } = createGalleryTestModule(GalleryControllerPagesItems);
|
|
18
|
+
const items = module as GalleryControllerPagesItems;
|
|
19
|
+
const mediaLoad = spyEvent(observer, MEDIA_EVENTS.LOAD);
|
|
20
|
+
|
|
21
|
+
const item = await items.onPageItemsGet({
|
|
22
|
+
check: "cg1",
|
|
23
|
+
mediaType: "gallery",
|
|
24
|
+
name: "cg1",
|
|
25
|
+
fullName: "cg1",
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
expect(mediaLoad).not.toHaveBeenCalled();
|
|
29
|
+
expect(item).toMatchObject({ isOpened: false, fullName: "cg1", src: "", mediaType: "gallery" });
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
it("PAGE_ITEMS_GET loads media when CHECK is true", async () => {
|
|
33
|
+
const { module, observer } = createGalleryTestModule(GalleryControllerPagesItems);
|
|
34
|
+
const items = module as GalleryControllerPagesItems;
|
|
35
|
+
|
|
36
|
+
stubEvent(observer, SUBSCRIBE_EVENTS.CHECK, () => true);
|
|
37
|
+
stubEvent(observer, MEDIA_EVENTS.LOAD, () => ({ src: "media://cg1" }));
|
|
38
|
+
|
|
39
|
+
const item = await items.onPageItemsGet({
|
|
40
|
+
check: "cg1",
|
|
41
|
+
mediaType: "gallery",
|
|
42
|
+
name: "cg1",
|
|
43
|
+
fullName: "cg1",
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
expect(item).toMatchObject({ isOpened: true, fullName: "cg1", src: "media://cg1" });
|
|
47
|
+
});
|
|
48
|
+
});
|