@mapomodule/uikit 2.0.0-beta.2 → 2.0.0-beta.20
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/README.md +46 -142
- package/dist/__tests__/MapoConfirmDialog.component.test.d.ts +2 -0
- package/dist/__tests__/MapoConfirmDialog.component.test.d.ts.map +1 -0
- package/dist/__tests__/MapoDetail.component.test.d.ts +2 -0
- package/dist/__tests__/MapoDetail.component.test.d.ts.map +1 -0
- package/dist/__tests__/MapoDetailLangSwitch.component.test.d.ts +2 -0
- package/dist/__tests__/MapoDetailLangSwitch.component.test.d.ts.map +1 -0
- package/dist/__tests__/MapoList.component.test.d.ts +2 -0
- package/dist/__tests__/MapoList.component.test.d.ts.map +1 -0
- package/dist/__tests__/MapoListActions.component.test.d.ts +2 -0
- package/dist/__tests__/MapoListActions.component.test.d.ts.map +1 -0
- package/dist/__tests__/MapoListTable.component.test.d.ts +2 -0
- package/dist/__tests__/MapoListTable.component.test.d.ts.map +1 -0
- package/dist/__tests__/MapoMediaEditor.component.test.d.ts +2 -0
- package/dist/__tests__/MapoMediaEditor.component.test.d.ts.map +1 -0
- package/dist/__tests__/MapoMediaFolderPicker.component.test.d.ts +2 -0
- package/dist/__tests__/MapoMediaFolderPicker.component.test.d.ts.map +1 -0
- package/dist/__tests__/MapoMediaFolders.component.test.d.ts +2 -0
- package/dist/__tests__/MapoMediaFolders.component.test.d.ts.map +1 -0
- package/dist/__tests__/MapoMediaGallery.component.test.d.ts +2 -0
- package/dist/__tests__/MapoMediaGallery.component.test.d.ts.map +1 -0
- package/dist/__tests__/MapoMediaUploadHandover.component.test.d.ts +2 -0
- package/dist/__tests__/MapoMediaUploadHandover.component.test.d.ts.map +1 -0
- package/dist/__tests__/MapoMenuManager.component.test.d.ts +2 -0
- package/dist/__tests__/MapoMenuManager.component.test.d.ts.map +1 -0
- package/dist/__tests__/MapoSnackBar.component.test.d.ts +2 -0
- package/dist/__tests__/MapoSnackBar.component.test.d.ts.map +1 -0
- package/dist/__tests__/__mocks__/nuxt-app.d.ts +9 -0
- package/dist/__tests__/__mocks__/nuxt-app.d.ts.map +1 -0
- package/dist/__tests__/langInfo.test.d.ts +2 -0
- package/dist/__tests__/langInfo.test.d.ts.map +1 -0
- package/dist/__tests__/listTable.test.d.ts +2 -0
- package/dist/__tests__/listTable.test.d.ts.map +1 -0
- package/dist/__tests__/mediaDrag.test.d.ts +2 -0
- package/dist/__tests__/mediaDrag.test.d.ts.map +1 -0
- package/dist/__tests__/mediaFolders.test.d.ts +2 -0
- package/dist/__tests__/mediaFolders.test.d.ts.map +1 -0
- package/dist/__tests__/mediaLanguages.test.d.ts +2 -0
- package/dist/__tests__/mediaLanguages.test.d.ts.map +1 -0
- package/dist/__tests__/mediaMetadata.test.d.ts +2 -0
- package/dist/__tests__/mediaMetadata.test.d.ts.map +1 -0
- package/dist/__tests__/mediaStore.test.d.ts +2 -0
- package/dist/__tests__/mediaStore.test.d.ts.map +1 -0
- package/dist/__tests__/mediaUrl.test.d.ts +2 -0
- package/dist/__tests__/mediaUrl.test.d.ts.map +1 -0
- package/dist/index.d.mts +3 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.mjs +1 -1
- package/dist/module.d.mts +48 -1
- package/dist/module.d.ts +44 -0
- package/dist/module.d.ts.map +1 -1
- package/dist/module.json +1 -1
- package/dist/module.mjs +71 -2
- package/dist/runtime/adapters/defaultMediaAdapter.d.ts +15 -0
- package/dist/runtime/adapters/defaultMediaAdapter.d.ts.map +1 -0
- package/dist/runtime/adapters/defaultMediaAdapter.js +35 -0
- package/dist/runtime/assets/main.css +1 -1
- package/dist/runtime/components/MapoConfirmDialog.vue +23 -4
- package/dist/runtime/components/MapoConfirmDialog.vue.d.ts.map +1 -1
- package/dist/runtime/components/MapoDetail.vue +127 -55
- package/dist/runtime/components/MapoDetail.vue.d.ts +102 -5
- package/dist/runtime/components/MapoDetail.vue.d.ts.map +1 -1
- package/dist/runtime/components/MapoDetailLangSwitch.vue +22 -26
- package/dist/runtime/components/MapoDetailLangSwitch.vue.d.ts +4 -3
- package/dist/runtime/components/MapoDetailLangSwitch.vue.d.ts.map +1 -1
- package/dist/runtime/components/MapoDropArea.vue +110 -0
- package/dist/runtime/components/MapoDropArea.vue.d.ts +33 -0
- package/dist/runtime/components/MapoDropArea.vue.d.ts.map +1 -0
- package/dist/runtime/components/MapoLangSwitcher.vue +39 -0
- package/dist/runtime/components/MapoLangSwitcher.vue.d.ts +18 -0
- package/dist/runtime/components/MapoLangSwitcher.vue.d.ts.map +1 -0
- package/dist/runtime/components/MapoList.vue +45 -31
- package/dist/runtime/components/MapoList.vue.d.ts +18 -5
- package/dist/runtime/components/MapoList.vue.d.ts.map +1 -1
- package/dist/runtime/components/MapoListActions.vue +27 -13
- package/dist/runtime/components/MapoListActions.vue.d.ts +4 -0
- package/dist/runtime/components/MapoListActions.vue.d.ts.map +1 -1
- package/dist/runtime/components/MapoListFilters.vue +4 -2
- package/dist/runtime/components/MapoListFilters.vue.d.ts.map +1 -1
- package/dist/runtime/components/MapoListQuickEdit.vue +20 -10
- package/dist/runtime/components/MapoListQuickEdit.vue.d.ts.map +1 -1
- package/dist/runtime/components/MapoListTable.vue +125 -49
- package/dist/runtime/components/MapoListTable.vue.d.ts +13 -5
- package/dist/runtime/components/MapoListTable.vue.d.ts.map +1 -1
- package/dist/runtime/components/MapoLogin.vue +13 -10
- package/dist/runtime/components/MapoLogin.vue.d.ts.map +1 -1
- package/dist/runtime/components/MapoLogoutButton.vue +4 -2
- package/dist/runtime/components/MapoLogoutButton.vue.d.ts.map +1 -1
- package/dist/runtime/components/MapoMediaBreadcrumbs.vue +47 -0
- package/dist/runtime/components/MapoMediaBreadcrumbs.vue.d.ts +4 -0
- package/dist/runtime/components/MapoMediaBreadcrumbs.vue.d.ts.map +1 -0
- package/dist/runtime/components/MapoMediaEditor.vue +382 -0
- package/dist/runtime/components/MapoMediaEditor.vue.d.ts +13 -0
- package/dist/runtime/components/MapoMediaEditor.vue.d.ts.map +1 -0
- package/dist/runtime/components/MapoMediaFileChanger.vue +112 -0
- package/dist/runtime/components/MapoMediaFileChanger.vue.d.ts +15 -0
- package/dist/runtime/components/MapoMediaFileChanger.vue.d.ts.map +1 -0
- package/dist/runtime/components/MapoMediaFolderPicker.vue +129 -0
- package/dist/runtime/components/MapoMediaFolderPicker.vue.d.ts +33 -0
- package/dist/runtime/components/MapoMediaFolderPicker.vue.d.ts.map +1 -0
- package/dist/runtime/components/MapoMediaFolders.vue +402 -0
- package/dist/runtime/components/MapoMediaFolders.vue.d.ts +4 -0
- package/dist/runtime/components/MapoMediaFolders.vue.d.ts.map +1 -0
- package/dist/runtime/components/MapoMediaGallery.vue +304 -0
- package/dist/runtime/components/MapoMediaGallery.vue.d.ts +8 -0
- package/dist/runtime/components/MapoMediaGallery.vue.d.ts.map +1 -0
- package/dist/runtime/components/MapoMediaManager.vue +144 -0
- package/dist/runtime/components/MapoMediaManager.vue.d.ts +44 -0
- package/dist/runtime/components/MapoMediaManager.vue.d.ts.map +1 -0
- package/dist/runtime/components/MapoMediaManagerDialog.vue +116 -0
- package/dist/runtime/components/MapoMediaManagerDialog.vue.d.ts +41 -0
- package/dist/runtime/components/MapoMediaManagerDialog.vue.d.ts.map +1 -0
- package/dist/runtime/components/MapoMediaPreview.vue +94 -0
- package/dist/runtime/components/MapoMediaPreview.vue.d.ts +19 -0
- package/dist/runtime/components/MapoMediaPreview.vue.d.ts.map +1 -0
- package/dist/runtime/components/MapoMediaUploader.vue +294 -0
- package/dist/runtime/components/MapoMediaUploader.vue.d.ts +8 -0
- package/dist/runtime/components/MapoMediaUploader.vue.d.ts.map +1 -0
- package/dist/runtime/components/MapoMenuManager.vue +301 -0
- package/dist/runtime/components/MapoMenuManager.vue.d.ts +92 -0
- package/dist/runtime/components/MapoMenuManager.vue.d.ts.map +1 -0
- package/dist/runtime/components/MapoMenuNodeEditor.vue +201 -0
- package/dist/runtime/components/MapoMenuNodeEditor.vue.d.ts +61 -0
- package/dist/runtime/components/MapoMenuNodeEditor.vue.d.ts.map +1 -0
- package/dist/runtime/components/MapoMenuTreeview.vue +181 -0
- package/dist/runtime/components/MapoMenuTreeview.vue.d.ts +57 -0
- package/dist/runtime/components/MapoMenuTreeview.vue.d.ts.map +1 -0
- package/dist/runtime/components/MapoMenuTreeviewNode.vue +175 -0
- package/dist/runtime/components/MapoMenuTreeviewNode.vue.d.ts +27 -0
- package/dist/runtime/components/MapoMenuTreeviewNode.vue.d.ts.map +1 -0
- package/dist/runtime/components/MapoSidebar.vue +3 -1
- package/dist/runtime/components/MapoSidebar.vue.d.ts.map +1 -1
- package/dist/runtime/components/MapoSidebarList.vue +1 -1
- package/dist/runtime/components/MapoSidebarProfile.vue +6 -2
- package/dist/runtime/components/MapoSidebarProfile.vue.d.ts.map +1 -1
- package/dist/runtime/components/MapoSnackBar.vue +11 -0
- package/dist/runtime/components/MapoSnackBar.vue.d.ts.map +1 -1
- package/dist/runtime/components/MapoThemeToggle.vue +5 -1
- package/dist/runtime/components/MapoThemeToggle.vue.d.ts.map +1 -1
- package/dist/runtime/components/menuDndContext.d.ts +19 -0
- package/dist/runtime/components/menuDndContext.d.ts.map +1 -0
- package/dist/runtime/components/menuDndContext.js +3 -0
- package/dist/runtime/page-meta.nuxt.d.ts +4 -0
- package/dist/runtime/pages/index.vue +4 -3
- package/dist/runtime/pages/index.vue.d.ts.map +1 -1
- package/dist/runtime/pages/login.vue +0 -4
- package/dist/runtime/pages/login.vue.d.ts.map +1 -1
- package/dist/runtime/plugins/media-adapter.d.ts +18 -0
- package/dist/runtime/plugins/media-adapter.d.ts.map +1 -0
- package/dist/runtime/plugins/media-adapter.js +8 -0
- package/dist/runtime/stores/media.d.ts +505 -0
- package/dist/runtime/stores/media.d.ts.map +1 -0
- package/dist/runtime/stores/media.js +545 -0
- package/dist/runtime/types/list.d.ts +10 -2
- package/dist/runtime/types/list.d.ts.map +1 -1
- package/dist/runtime/types/media.d.ts +131 -0
- package/dist/runtime/types/media.d.ts.map +1 -0
- package/dist/runtime/types/media.js +0 -0
- package/dist/runtime/types/menu.d.ts +66 -0
- package/dist/runtime/types/menu.d.ts.map +1 -0
- package/dist/runtime/types/menu.js +30 -0
- package/dist/runtime/utils/contentLanguages.d.ts +9 -0
- package/dist/runtime/utils/contentLanguages.d.ts.map +1 -0
- package/dist/runtime/utils/contentLanguages.js +8 -0
- package/dist/runtime/utils/langInfo.d.ts +43 -0
- package/dist/runtime/utils/langInfo.d.ts.map +1 -0
- package/dist/runtime/utils/langInfo.js +17 -0
- package/dist/runtime/utils/listTable.d.ts +29 -0
- package/dist/runtime/utils/listTable.d.ts.map +1 -0
- package/dist/runtime/utils/listTable.js +21 -0
- package/dist/runtime/utils/mediaDrag.d.ts +21 -0
- package/dist/runtime/utils/mediaDrag.d.ts.map +1 -0
- package/dist/runtime/utils/mediaDrag.js +11 -0
- package/dist/runtime/utils/mediaFolders.d.ts +65 -0
- package/dist/runtime/utils/mediaFolders.d.ts.map +1 -0
- package/dist/runtime/utils/mediaFolders.js +97 -0
- package/dist/runtime/utils/mediaMetadata.d.ts +39 -0
- package/dist/runtime/utils/mediaMetadata.d.ts.map +1 -0
- package/dist/runtime/utils/mediaMetadata.js +97 -0
- package/dist/runtime/utils/mediaUrl.d.ts +16 -0
- package/dist/runtime/utils/mediaUrl.d.ts.map +1 -0
- package/dist/runtime/utils/mediaUrl.js +12 -0
- package/dist/types.d.mts +1 -1
- package/package.json +15 -11
- package/src/__tests__/MapoConfirmDialog.component.test.ts +165 -0
- package/src/__tests__/MapoDetail.component.test.ts +393 -0
- package/src/__tests__/MapoDetailLangSwitch.component.test.ts +145 -0
- package/src/__tests__/MapoList.component.test.ts +166 -0
- package/src/__tests__/MapoListActions.component.test.ts +175 -0
- package/src/__tests__/MapoListTable.component.test.ts +545 -0
- package/src/__tests__/MapoMediaEditor.component.test.ts +447 -0
- package/src/__tests__/MapoMediaFolderPicker.component.test.ts +220 -0
- package/src/__tests__/MapoMediaFolders.component.test.ts +519 -0
- package/src/__tests__/MapoMediaGallery.component.test.ts +211 -0
- package/src/__tests__/MapoMediaUploadHandover.component.test.ts +241 -0
- package/src/__tests__/MapoMenuManager.component.test.ts +175 -0
- package/src/__tests__/MapoSnackBar.component.test.ts +79 -0
- package/src/__tests__/__mocks__/nuxt-app.ts +8 -0
- package/src/__tests__/langInfo.test.ts +85 -0
- package/src/__tests__/listTable.test.ts +82 -0
- package/src/__tests__/mediaDrag.test.ts +42 -0
- package/src/__tests__/mediaFolders.test.ts +204 -0
- package/src/__tests__/mediaLanguages.test.ts +66 -0
- package/src/__tests__/mediaMetadata.test.ts +169 -0
- package/src/__tests__/mediaStore.test.ts +569 -0
- package/src/__tests__/mediaUrl.test.ts +44 -0
- package/src/index.ts +21 -0
- package/src/module.ts +155 -0
- package/src/runtime/adapters/defaultMediaAdapter.ts +67 -0
- package/src/runtime/assets/main.css +9 -0
- package/src/runtime/components/MapoConfirmDialog.vue +33 -4
- package/src/runtime/components/MapoDetail.vue +229 -73
- package/src/runtime/components/MapoDetailLangSwitch.vue +27 -28
- package/src/runtime/components/MapoDropArea.vue +145 -0
- package/src/runtime/components/MapoLangSwitcher.vue +74 -0
- package/src/runtime/components/MapoList.vue +65 -34
- package/src/runtime/components/MapoListActions.vue +32 -14
- package/src/runtime/components/MapoListFilters.vue +5 -2
- package/src/runtime/components/MapoListQuickEdit.vue +22 -10
- package/src/runtime/components/MapoListTable.vue +159 -59
- package/src/runtime/components/MapoLogin.vue +13 -10
- package/src/runtime/components/MapoLogoutButton.vue +4 -2
- package/src/runtime/components/MapoMediaBreadcrumbs.vue +53 -0
- package/src/runtime/components/MapoMediaEditor.vue +447 -0
- package/src/runtime/components/MapoMediaFileChanger.vue +136 -0
- package/src/runtime/components/MapoMediaFolderPicker.vue +176 -0
- package/src/runtime/components/MapoMediaFolders.vue +478 -0
- package/src/runtime/components/MapoMediaGallery.vue +350 -0
- package/src/runtime/components/MapoMediaManager.vue +194 -0
- package/src/runtime/components/MapoMediaManagerDialog.vue +148 -0
- package/src/runtime/components/MapoMediaPreview.vue +116 -0
- package/src/runtime/components/MapoMediaUploader.vue +362 -0
- package/src/runtime/components/MapoMenuManager.vue +454 -0
- package/src/runtime/components/MapoMenuNodeEditor.vue +282 -0
- package/src/runtime/components/MapoMenuTreeview.vue +264 -0
- package/src/runtime/components/MapoMenuTreeviewNode.vue +234 -0
- package/src/runtime/components/MapoSidebar.vue +3 -1
- package/src/runtime/components/MapoSidebarList.vue +1 -1
- package/src/runtime/components/MapoSidebarProfile.vue +6 -2
- package/src/runtime/components/MapoSnackBar.vue +12 -0
- package/src/runtime/components/MapoThemeToggle.vue +5 -1
- package/src/runtime/components/menuDndContext.ts +22 -0
- package/src/runtime/page-meta.nuxt.d.ts +4 -0
- package/src/runtime/pages/index.vue +4 -3
- package/src/runtime/pages/login.vue +0 -4
- package/src/runtime/plugins/media-adapter.ts +33 -0
- package/src/runtime/stores/media.ts +820 -0
- package/src/runtime/types/list.ts +10 -2
- package/src/runtime/types/media.ts +144 -0
- package/src/runtime/types/menu.ts +105 -0
- package/src/runtime/utils/contentLanguages.ts +18 -0
- package/src/runtime/utils/langInfo.ts +63 -0
- package/src/runtime/utils/listTable.ts +54 -0
- package/src/runtime/utils/mediaDrag.ts +29 -0
- package/src/runtime/utils/mediaFolders.ts +182 -0
- package/src/runtime/utils/mediaMetadata.ts +165 -0
- package/src/runtime/utils/mediaUrl.ts +30 -0
|
@@ -0,0 +1,447 @@
|
|
|
1
|
+
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
|
|
2
|
+
import { createRenderer, h, inject, onUnmounted, provide } from "vue";
|
|
3
|
+
import type { App, Component, SetupContext, VNode } from "vue";
|
|
4
|
+
import { createPinia, setActivePinia } from "pinia";
|
|
5
|
+
import type { Pinia } from "pinia";
|
|
6
|
+
|
|
7
|
+
import MapoMediaEditor from "../runtime/components/MapoMediaEditor.vue";
|
|
8
|
+
import { useMediaStore } from "../runtime/stores/media";
|
|
9
|
+
import type { MediaItem } from "../runtime/types/media";
|
|
10
|
+
|
|
11
|
+
// The editor reads the store, which reads the CRUD layer and the runtime
|
|
12
|
+
// config: replace them with in-memory doubles. `vi.hoisted` lets the mock
|
|
13
|
+
// factories share them.
|
|
14
|
+
const crud = vi.hoisted(() => ({
|
|
15
|
+
options: vi.fn(),
|
|
16
|
+
list: vi.fn(),
|
|
17
|
+
detail: vi.fn(),
|
|
18
|
+
partialUpdate: vi.fn(),
|
|
19
|
+
delete: vi.fn(),
|
|
20
|
+
}));
|
|
21
|
+
const snack = vi.hoisted(() => ({ show: vi.fn() }));
|
|
22
|
+
// The app's `mapo.uikit` runtime config, changed by the content-language test.
|
|
23
|
+
const runtimeConfig = vi.hoisted(() => ({
|
|
24
|
+
public: { mapoUikit: { contentLanguages: [] as string[] } },
|
|
25
|
+
}));
|
|
26
|
+
|
|
27
|
+
vi.mock("#app", () => ({
|
|
28
|
+
useRuntimeConfig: () => runtimeConfig,
|
|
29
|
+
useNuxtApp: () => ({}),
|
|
30
|
+
}));
|
|
31
|
+
vi.mock("vue-i18n", () => ({ useI18n: () => ({ t: (key: string) => key }) }));
|
|
32
|
+
vi.mock("@mapomodule/core/runtime/api/crud", () => ({ useCrud: () => crud }));
|
|
33
|
+
vi.mock("@mapomodule/store/runtime/stores/snack", () => ({
|
|
34
|
+
useSnackStore: () => snack,
|
|
35
|
+
}));
|
|
36
|
+
vi.mock("@mapomodule/store/runtime/stores/confirm", () => ({
|
|
37
|
+
useConfirmStore: () => ({ ask: vi.fn() }),
|
|
38
|
+
}));
|
|
39
|
+
vi.mock("@mapomodule/store/runtime/composables/usePermissions", () => ({
|
|
40
|
+
usePermissions: () => ({ canChange: () => true, canDelete: () => true }),
|
|
41
|
+
}));
|
|
42
|
+
vi.mock("@mapomodule/i18n/runtime/composables/useMapoT", () => ({
|
|
43
|
+
useMapoT: () => (key: string) => key,
|
|
44
|
+
}));
|
|
45
|
+
|
|
46
|
+
// Tests run in Node without a DOM. A renderer whose nodes are plain objects is
|
|
47
|
+
// enough to mount the component with real reactivity, watchers and events.
|
|
48
|
+
interface HeadlessNode {
|
|
49
|
+
parent: HeadlessNode | null;
|
|
50
|
+
children: HeadlessNode[];
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
const headlessNode = (): HeadlessNode => ({ parent: null, children: [] });
|
|
54
|
+
|
|
55
|
+
const { createApp } = createRenderer<HeadlessNode, HeadlessNode>({
|
|
56
|
+
createElement: headlessNode,
|
|
57
|
+
createText: headlessNode,
|
|
58
|
+
createComment: headlessNode,
|
|
59
|
+
setText: () => {},
|
|
60
|
+
setElementText: () => {},
|
|
61
|
+
patchProp: () => {},
|
|
62
|
+
insert(child, parent, anchor) {
|
|
63
|
+
child.parent = parent;
|
|
64
|
+
const at = anchor ? parent.children.indexOf(anchor) : -1;
|
|
65
|
+
parent.children.splice(at < 0 ? parent.children.length : at, 0, child);
|
|
66
|
+
},
|
|
67
|
+
remove(child) {
|
|
68
|
+
child.parent?.children.splice(child.parent.children.indexOf(child), 1);
|
|
69
|
+
child.parent = null;
|
|
70
|
+
},
|
|
71
|
+
parentNode: (node) => node.parent,
|
|
72
|
+
nextSibling: (node) =>
|
|
73
|
+
node.parent?.children[node.parent.children.indexOf(node) + 1] ?? null,
|
|
74
|
+
});
|
|
75
|
+
|
|
76
|
+
const passthrough = (name: string): Component => ({
|
|
77
|
+
name,
|
|
78
|
+
inheritAttrs: false,
|
|
79
|
+
setup(_props: unknown, { slots }: SetupContext) {
|
|
80
|
+
return () => h("div", null, slots.default?.());
|
|
81
|
+
},
|
|
82
|
+
});
|
|
83
|
+
|
|
84
|
+
const slotText = (nodes: VNode[] | undefined) =>
|
|
85
|
+
(nodes ?? [])
|
|
86
|
+
.map((node) => (typeof node.children === "string" ? node.children : ""))
|
|
87
|
+
.join("")
|
|
88
|
+
.trim();
|
|
89
|
+
|
|
90
|
+
// `UButton`: its label is the slot text, `click` is what the editor listens to.
|
|
91
|
+
interface ButtonStub {
|
|
92
|
+
readonly label: string;
|
|
93
|
+
click(): void;
|
|
94
|
+
}
|
|
95
|
+
const buttons: ButtonStub[] = [];
|
|
96
|
+
|
|
97
|
+
const UButton: Component = {
|
|
98
|
+
name: "UButton",
|
|
99
|
+
emits: ["click"],
|
|
100
|
+
setup(_props: unknown, { emit, slots }: SetupContext<["click"]>) {
|
|
101
|
+
const stub: ButtonStub = {
|
|
102
|
+
get label() {
|
|
103
|
+
return slotText(slots.default?.());
|
|
104
|
+
},
|
|
105
|
+
click: () => emit("click"),
|
|
106
|
+
};
|
|
107
|
+
buttons.push(stub);
|
|
108
|
+
onUnmounted(() => {
|
|
109
|
+
buttons.splice(buttons.indexOf(stub), 1);
|
|
110
|
+
});
|
|
111
|
+
return () => h("button", null, slots.default?.());
|
|
112
|
+
},
|
|
113
|
+
};
|
|
114
|
+
|
|
115
|
+
// `UFormField` hands its label to the input inside, so a test finds an input
|
|
116
|
+
// by the label the user reads.
|
|
117
|
+
const FIELD_LABEL = Symbol("field-label");
|
|
118
|
+
const UFormField: Component = {
|
|
119
|
+
name: "UFormField",
|
|
120
|
+
props: { label: String },
|
|
121
|
+
setup(props: { label?: string }, { slots }: SetupContext) {
|
|
122
|
+
provide(FIELD_LABEL, props.label ?? "");
|
|
123
|
+
return () => h("div", null, slots.default?.());
|
|
124
|
+
},
|
|
125
|
+
};
|
|
126
|
+
|
|
127
|
+
interface InputStub {
|
|
128
|
+
readonly label: string;
|
|
129
|
+
readonly value: string;
|
|
130
|
+
type(value: string): void;
|
|
131
|
+
}
|
|
132
|
+
const inputs: InputStub[] = [];
|
|
133
|
+
|
|
134
|
+
const inputComponent = (name: string): Component => ({
|
|
135
|
+
name,
|
|
136
|
+
props: { modelValue: String },
|
|
137
|
+
emits: ["update:modelValue"],
|
|
138
|
+
setup(
|
|
139
|
+
props: { modelValue?: string },
|
|
140
|
+
{ emit }: SetupContext<["update:modelValue"]>,
|
|
141
|
+
) {
|
|
142
|
+
const stub: InputStub = {
|
|
143
|
+
label: inject(FIELD_LABEL, ""),
|
|
144
|
+
get value() {
|
|
145
|
+
return props.modelValue ?? "";
|
|
146
|
+
},
|
|
147
|
+
type: (value) => emit("update:modelValue", value),
|
|
148
|
+
};
|
|
149
|
+
inputs.push(stub);
|
|
150
|
+
onUnmounted(() => {
|
|
151
|
+
inputs.splice(inputs.indexOf(stub), 1);
|
|
152
|
+
});
|
|
153
|
+
return () => h("input");
|
|
154
|
+
},
|
|
155
|
+
});
|
|
156
|
+
|
|
157
|
+
// `USlideover` renders its `#content` slot while open.
|
|
158
|
+
const USlideover: Component = {
|
|
159
|
+
name: "USlideover",
|
|
160
|
+
props: { open: Boolean },
|
|
161
|
+
setup(props: { open?: boolean }, { slots }: SetupContext) {
|
|
162
|
+
return () => (props.open ? h("div", null, slots.content?.()) : null);
|
|
163
|
+
},
|
|
164
|
+
};
|
|
165
|
+
|
|
166
|
+
// `MapoDetailLangSwitch` declares the contract the editor binds: `modelValue`,
|
|
167
|
+
// `langs` and `noRouteChange` in, `update:modelValue` out.
|
|
168
|
+
interface LangSwitchStub {
|
|
169
|
+
readonly langs: string[];
|
|
170
|
+
readonly value: string;
|
|
171
|
+
readonly noRouteChange: boolean;
|
|
172
|
+
select(lang: string): void;
|
|
173
|
+
}
|
|
174
|
+
let langSwitch: LangSwitchStub | null = null;
|
|
175
|
+
|
|
176
|
+
const MapoDetailLangSwitch: Component = {
|
|
177
|
+
name: "MapoDetailLangSwitch",
|
|
178
|
+
props: { modelValue: String, langs: Array, noRouteChange: Boolean },
|
|
179
|
+
emits: ["update:modelValue"],
|
|
180
|
+
setup(
|
|
181
|
+
props: { modelValue?: string; langs?: string[]; noRouteChange?: boolean },
|
|
182
|
+
{ emit }: SetupContext<["update:modelValue"]>,
|
|
183
|
+
) {
|
|
184
|
+
langSwitch = {
|
|
185
|
+
get langs() {
|
|
186
|
+
return props.langs ?? [];
|
|
187
|
+
},
|
|
188
|
+
get value() {
|
|
189
|
+
return props.modelValue ?? "";
|
|
190
|
+
},
|
|
191
|
+
get noRouteChange() {
|
|
192
|
+
return props.noRouteChange ?? false;
|
|
193
|
+
},
|
|
194
|
+
select: (lang) => emit("update:modelValue", lang),
|
|
195
|
+
};
|
|
196
|
+
onUnmounted(() => {
|
|
197
|
+
langSwitch = null;
|
|
198
|
+
});
|
|
199
|
+
return () => h("div");
|
|
200
|
+
},
|
|
201
|
+
};
|
|
202
|
+
|
|
203
|
+
// `MapoMediaFolderPicker`: `open` in, `confirm` out with the picked folder.
|
|
204
|
+
let picker: { readonly open: boolean; pick(folder: unknown): void } | null =
|
|
205
|
+
null;
|
|
206
|
+
const MapoMediaFolderPicker: Component = {
|
|
207
|
+
name: "MapoMediaFolderPicker",
|
|
208
|
+
props: { open: Boolean },
|
|
209
|
+
emits: ["confirm", "update:open"],
|
|
210
|
+
setup(
|
|
211
|
+
props: { open?: boolean },
|
|
212
|
+
{ emit }: SetupContext<["confirm", "update:open"]>,
|
|
213
|
+
) {
|
|
214
|
+
picker = {
|
|
215
|
+
get open() {
|
|
216
|
+
return props.open ?? false;
|
|
217
|
+
},
|
|
218
|
+
pick(folder) {
|
|
219
|
+
emit("confirm", folder);
|
|
220
|
+
emit("update:open", false);
|
|
221
|
+
},
|
|
222
|
+
};
|
|
223
|
+
onUnmounted(() => {
|
|
224
|
+
picker = null;
|
|
225
|
+
});
|
|
226
|
+
return () => h("div");
|
|
227
|
+
},
|
|
228
|
+
};
|
|
229
|
+
|
|
230
|
+
const stubs: Record<string, Component> = {
|
|
231
|
+
MapoMediaFolderPicker,
|
|
232
|
+
UButton,
|
|
233
|
+
UFormField,
|
|
234
|
+
USlideover,
|
|
235
|
+
UInput: inputComponent("UInput"),
|
|
236
|
+
UTextarea: inputComponent("UTextarea"),
|
|
237
|
+
MapoDetailLangSwitch,
|
|
238
|
+
MapoMediaPreview: passthrough("MapoMediaPreview"),
|
|
239
|
+
MapoMediaFileChanger: passthrough("MapoMediaFileChanger"),
|
|
240
|
+
};
|
|
241
|
+
|
|
242
|
+
const button = (label: string) => buttons.find((stub) => stub.label === label);
|
|
243
|
+
const input = (label: string) => {
|
|
244
|
+
const found = inputs.find((stub) => stub.label === label);
|
|
245
|
+
if (!found) throw new Error(`no input ${label}`);
|
|
246
|
+
return found;
|
|
247
|
+
};
|
|
248
|
+
|
|
249
|
+
// Runs the pending CRUD promises and the renders they trigger.
|
|
250
|
+
const settle = () => new Promise((resolve) => setTimeout(resolve));
|
|
251
|
+
|
|
252
|
+
const stored: MediaItem = {
|
|
253
|
+
id: 7,
|
|
254
|
+
file: "/media/photo.jpg",
|
|
255
|
+
mime_type: "image/jpeg",
|
|
256
|
+
title: "Foto",
|
|
257
|
+
alt_text: "Una foto",
|
|
258
|
+
description: "",
|
|
259
|
+
size: 1000,
|
|
260
|
+
created: "2026-11-01T00:00:00Z",
|
|
261
|
+
modified: "2026-11-01T00:00:00Z",
|
|
262
|
+
translations: {
|
|
263
|
+
it: { title: "Foto", alt_text: "Una foto", description: "" },
|
|
264
|
+
en: { title: "Photo", alt_text: "A photo", description: "" },
|
|
265
|
+
},
|
|
266
|
+
};
|
|
267
|
+
|
|
268
|
+
let app: App<HeadlessNode> | undefined;
|
|
269
|
+
let pinia: Pinia;
|
|
270
|
+
|
|
271
|
+
async function mountEditor(props: Record<string, unknown> = {}) {
|
|
272
|
+
app = createApp({ render: () => h(MapoMediaEditor as Component, props) });
|
|
273
|
+
app.use(pinia);
|
|
274
|
+
for (const [name, stub] of Object.entries(stubs)) app.component(name, stub);
|
|
275
|
+
app.mount(headlessNode());
|
|
276
|
+
useMediaStore().editMedia = structuredClone(stored);
|
|
277
|
+
await settle();
|
|
278
|
+
}
|
|
279
|
+
|
|
280
|
+
async function openEditor(props: Record<string, unknown> = {}) {
|
|
281
|
+
await mountEditor(props);
|
|
282
|
+
button("mapo.edit")?.click();
|
|
283
|
+
await settle();
|
|
284
|
+
}
|
|
285
|
+
|
|
286
|
+
beforeEach(() => {
|
|
287
|
+
runtimeConfig.public.mapoUikit.contentLanguages = [];
|
|
288
|
+
pinia = createPinia();
|
|
289
|
+
setActivePinia(pinia);
|
|
290
|
+
for (const fn of Object.values(crud)) fn.mockReset();
|
|
291
|
+
snack.show.mockReset();
|
|
292
|
+
crud.options.mockResolvedValue({
|
|
293
|
+
lang_info: { translatable: true, languages: ["it", "en"] },
|
|
294
|
+
});
|
|
295
|
+
crud.list.mockResolvedValue({
|
|
296
|
+
media: { items: [], paginator: { page: 1, pages: 1 } },
|
|
297
|
+
folders: [],
|
|
298
|
+
parent_folder: null,
|
|
299
|
+
});
|
|
300
|
+
crud.partialUpdate.mockImplementation((_id: number, body: unknown) =>
|
|
301
|
+
Promise.resolve({ ...stored, ...(body as object) }),
|
|
302
|
+
);
|
|
303
|
+
});
|
|
304
|
+
|
|
305
|
+
afterEach(() => {
|
|
306
|
+
app?.unmount();
|
|
307
|
+
app = undefined;
|
|
308
|
+
});
|
|
309
|
+
|
|
310
|
+
describe("MapoMediaEditor", () => {
|
|
311
|
+
it("offers one tab per language and no untranslated one", async () => {
|
|
312
|
+
await openEditor();
|
|
313
|
+
|
|
314
|
+
expect(langSwitch?.langs).toEqual(["it", "en"]);
|
|
315
|
+
expect(langSwitch?.value).toBe("it");
|
|
316
|
+
expect(buttons.map((stub) => stub.label)).not.toContain(
|
|
317
|
+
"mapo.mediaEditor.defaultLang",
|
|
318
|
+
);
|
|
319
|
+
});
|
|
320
|
+
|
|
321
|
+
// The shared switch, so an app that replaces it (MapoOverride) replaces it
|
|
322
|
+
// in the media editor too; the drawer must leave the page's URL alone.
|
|
323
|
+
it("uses the shared language switch without touching the route", async () => {
|
|
324
|
+
await openEditor();
|
|
325
|
+
|
|
326
|
+
expect(langSwitch?.noRouteChange).toBe(true);
|
|
327
|
+
langSwitch?.select("en");
|
|
328
|
+
await settle();
|
|
329
|
+
expect(input("mapo.altTag").value).toBe("A photo");
|
|
330
|
+
});
|
|
331
|
+
|
|
332
|
+
it("shows no switch for a single language, and still writes it", async () => {
|
|
333
|
+
crud.options.mockResolvedValue({
|
|
334
|
+
lang_info: { translatable: true, languages: ["it"] },
|
|
335
|
+
});
|
|
336
|
+
await openEditor();
|
|
337
|
+
|
|
338
|
+
expect(langSwitch).toBeNull();
|
|
339
|
+
input("mapo.title").type("Solo italiano");
|
|
340
|
+
button("mapo.save")?.click();
|
|
341
|
+
await settle();
|
|
342
|
+
|
|
343
|
+
expect(crud.partialUpdate).toHaveBeenCalledWith(7, {
|
|
344
|
+
translations: { it: { title: "Solo italiano" } },
|
|
345
|
+
});
|
|
346
|
+
});
|
|
347
|
+
|
|
348
|
+
it("saves the edit as a translation, sending only what changed", async () => {
|
|
349
|
+
await openEditor();
|
|
350
|
+
expect(input("mapo.title").value).toBe("Foto");
|
|
351
|
+
|
|
352
|
+
input("mapo.title").type("Nuovo titolo");
|
|
353
|
+
button("mapo.save")?.click();
|
|
354
|
+
await settle();
|
|
355
|
+
|
|
356
|
+
expect(crud.partialUpdate).toHaveBeenCalledWith(7, {
|
|
357
|
+
translations: { it: { title: "Nuovo titolo" } },
|
|
358
|
+
});
|
|
359
|
+
expect(snack.show).toHaveBeenCalledWith(
|
|
360
|
+
"mapo.mediaManager.fileInfo",
|
|
361
|
+
"success",
|
|
362
|
+
);
|
|
363
|
+
expect(button("mapo.save")).toBeUndefined();
|
|
364
|
+
});
|
|
365
|
+
|
|
366
|
+
it("opens on the default language when it is offered", async () => {
|
|
367
|
+
await openEditor({ defaultLang: "en" });
|
|
368
|
+
|
|
369
|
+
expect(input("mapo.altTag").value).toBe("A photo");
|
|
370
|
+
input("mapo.altTag").type("A new photo");
|
|
371
|
+
button("mapo.save")?.click();
|
|
372
|
+
await settle();
|
|
373
|
+
|
|
374
|
+
expect(crud.partialUpdate).toHaveBeenCalledWith(7, {
|
|
375
|
+
translations: { en: { alt_text: "A new photo" } },
|
|
376
|
+
});
|
|
377
|
+
});
|
|
378
|
+
|
|
379
|
+
it("edits the plain fields of media that are not translated", async () => {
|
|
380
|
+
crud.options.mockResolvedValue({ lang_info: { translatable: false } });
|
|
381
|
+
await openEditor();
|
|
382
|
+
|
|
383
|
+
expect(langSwitch).toBeNull();
|
|
384
|
+
input("mapo.title").type("New title");
|
|
385
|
+
button("mapo.save")?.click();
|
|
386
|
+
await settle();
|
|
387
|
+
|
|
388
|
+
expect(crud.partialUpdate).toHaveBeenCalledWith(7, { title: "New title" });
|
|
389
|
+
});
|
|
390
|
+
|
|
391
|
+
it("keeps the editor open and shows the backend errors in a toast", async () => {
|
|
392
|
+
crud.partialUpdate.mockRejectedValue(
|
|
393
|
+
Object.assign(new Error("Bad Request"), {
|
|
394
|
+
status: 400,
|
|
395
|
+
data: {
|
|
396
|
+
title_it: ["Ensure this field has no more than 200 characters."],
|
|
397
|
+
},
|
|
398
|
+
}),
|
|
399
|
+
);
|
|
400
|
+
await openEditor();
|
|
401
|
+
|
|
402
|
+
input("mapo.title").type("x".repeat(300));
|
|
403
|
+
button("mapo.save")?.click();
|
|
404
|
+
await settle();
|
|
405
|
+
|
|
406
|
+
expect(snack.show).toHaveBeenCalledWith(
|
|
407
|
+
"mapo.title (IT): Ensure this field has no more than 200 characters.",
|
|
408
|
+
"error",
|
|
409
|
+
);
|
|
410
|
+
expect(snack.show).not.toHaveBeenCalledWith(
|
|
411
|
+
"mapo.mediaManager.fileInfo",
|
|
412
|
+
"success",
|
|
413
|
+
);
|
|
414
|
+
expect(button("mapo.save")).toBeDefined();
|
|
415
|
+
expect(input("mapo.title").value).toBe("x".repeat(300));
|
|
416
|
+
});
|
|
417
|
+
|
|
418
|
+
it("narrows an explicit languages prop to the app's content languages", async () => {
|
|
419
|
+
runtimeConfig.public.mapoUikit.contentLanguages = ["en"];
|
|
420
|
+
await openEditor({ languages: ["it", "en"] });
|
|
421
|
+
|
|
422
|
+
expect(langSwitch).toBeNull();
|
|
423
|
+
expect(input("mapo.title").value).toBe("Photo");
|
|
424
|
+
input("mapo.title").type("New photo");
|
|
425
|
+
button("mapo.save")?.click();
|
|
426
|
+
await settle();
|
|
427
|
+
|
|
428
|
+
expect(crud.partialUpdate).toHaveBeenCalledWith(7, {
|
|
429
|
+
translations: { en: { title: "New photo" } },
|
|
430
|
+
});
|
|
431
|
+
});
|
|
432
|
+
|
|
433
|
+
it("moves the media to the folder picked, then closes the drawer", async () => {
|
|
434
|
+
await mountEditor();
|
|
435
|
+
const store = useMediaStore();
|
|
436
|
+
|
|
437
|
+
button("mapo.mediaMove.moveTo")?.click();
|
|
438
|
+
await settle();
|
|
439
|
+
expect(picker?.open).toBe(true);
|
|
440
|
+
|
|
441
|
+
picker?.pick({ id: 3, name: "Archive", parent: null });
|
|
442
|
+
await settle();
|
|
443
|
+
|
|
444
|
+
expect(crud.partialUpdate).toHaveBeenCalledWith(7, { folder: 3 });
|
|
445
|
+
expect(store.editMedia).toBeNull();
|
|
446
|
+
});
|
|
447
|
+
});
|
|
@@ -0,0 +1,220 @@
|
|
|
1
|
+
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
|
|
2
|
+
import { createRenderer, h, onUnmounted } from "vue";
|
|
3
|
+
import type { App, Component, SetupContext } from "vue";
|
|
4
|
+
import { createPinia, setActivePinia } from "pinia";
|
|
5
|
+
import type { Pinia } from "pinia";
|
|
6
|
+
|
|
7
|
+
import MapoMediaFolderPicker from "../runtime/components/MapoMediaFolderPicker.vue";
|
|
8
|
+
import { useMediaStore } from "../runtime/stores/media";
|
|
9
|
+
import { findFolderNode, type FolderNode } from "../runtime/utils/mediaFolders";
|
|
10
|
+
import type { MediaFolder } from "../runtime/types/media";
|
|
11
|
+
|
|
12
|
+
const crud = vi.hoisted(() => ({
|
|
13
|
+
options: vi.fn(),
|
|
14
|
+
list: vi.fn(),
|
|
15
|
+
detail: vi.fn(),
|
|
16
|
+
}));
|
|
17
|
+
|
|
18
|
+
vi.mock("#app", () => ({
|
|
19
|
+
useRuntimeConfig: () => ({ public: {} }),
|
|
20
|
+
useNuxtApp: () => ({}),
|
|
21
|
+
}));
|
|
22
|
+
vi.mock("vue-i18n", () => ({ useI18n: () => ({ t: (key: string) => key }) }));
|
|
23
|
+
vi.mock("@mapomodule/core/runtime/api/crud", () => ({ useCrud: () => crud }));
|
|
24
|
+
vi.mock("@mapomodule/store/runtime/stores/snack", () => ({
|
|
25
|
+
useSnackStore: () => ({ show: vi.fn() }),
|
|
26
|
+
}));
|
|
27
|
+
vi.mock("@mapomodule/store/runtime/stores/confirm", () => ({
|
|
28
|
+
useConfirmStore: () => ({ ask: vi.fn() }),
|
|
29
|
+
}));
|
|
30
|
+
vi.mock("@mapomodule/i18n/runtime/composables/useMapoT", () => ({
|
|
31
|
+
useMapoT: () => (key: string) => key,
|
|
32
|
+
}));
|
|
33
|
+
|
|
34
|
+
// Tests run in Node without a DOM. A renderer whose nodes are plain objects is
|
|
35
|
+
// enough to mount the component with real reactivity, watchers and events.
|
|
36
|
+
interface HeadlessNode {
|
|
37
|
+
parent: HeadlessNode | null;
|
|
38
|
+
children: HeadlessNode[];
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
const headlessNode = (): HeadlessNode => ({ parent: null, children: [] });
|
|
42
|
+
|
|
43
|
+
const { createApp } = createRenderer<HeadlessNode, HeadlessNode>({
|
|
44
|
+
createElement: headlessNode,
|
|
45
|
+
createText: headlessNode,
|
|
46
|
+
createComment: headlessNode,
|
|
47
|
+
setText: () => {},
|
|
48
|
+
setElementText: () => {},
|
|
49
|
+
patchProp: () => {},
|
|
50
|
+
insert(child, parent, anchor) {
|
|
51
|
+
child.parent = parent;
|
|
52
|
+
const at = anchor ? parent.children.indexOf(anchor) : -1;
|
|
53
|
+
parent.children.splice(at < 0 ? parent.children.length : at, 0, child);
|
|
54
|
+
},
|
|
55
|
+
remove(child) {
|
|
56
|
+
child.parent?.children.splice(child.parent.children.indexOf(child), 1);
|
|
57
|
+
child.parent = null;
|
|
58
|
+
},
|
|
59
|
+
parentNode: (node) => node.parent,
|
|
60
|
+
nextSibling: (node) =>
|
|
61
|
+
node.parent?.children[node.parent.children.indexOf(node) + 1] ?? null,
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
// `UModal` renders its body and footer while open.
|
|
65
|
+
const UModal: Component = {
|
|
66
|
+
name: "UModal",
|
|
67
|
+
props: { open: Boolean },
|
|
68
|
+
setup(props: { open?: boolean }, { slots }: SetupContext) {
|
|
69
|
+
return () =>
|
|
70
|
+
props.open ? h("div", null, [slots.body?.(), slots.footer?.()]) : null;
|
|
71
|
+
},
|
|
72
|
+
};
|
|
73
|
+
|
|
74
|
+
// `UTree`: `items` in, `onSelect` called with Reka's event and the node.
|
|
75
|
+
let tree: { readonly items: FolderNode[]; pick(key: string): void } | null =
|
|
76
|
+
null;
|
|
77
|
+
const UTree: Component = {
|
|
78
|
+
name: "UTree",
|
|
79
|
+
props: { items: Array, onSelect: Function },
|
|
80
|
+
setup(props: {
|
|
81
|
+
items?: FolderNode[];
|
|
82
|
+
onSelect?: (e: { preventDefault(): void }, node: FolderNode) => void;
|
|
83
|
+
}) {
|
|
84
|
+
tree = {
|
|
85
|
+
get items() {
|
|
86
|
+
return props.items ?? [];
|
|
87
|
+
},
|
|
88
|
+
pick(key) {
|
|
89
|
+
const node = findFolderNode(props.items, key);
|
|
90
|
+
if (!node) throw new Error(`no node ${key}`);
|
|
91
|
+
props.onSelect?.({ preventDefault: () => {} }, node);
|
|
92
|
+
},
|
|
93
|
+
};
|
|
94
|
+
onUnmounted(() => {
|
|
95
|
+
tree = null;
|
|
96
|
+
});
|
|
97
|
+
return () => h("div");
|
|
98
|
+
},
|
|
99
|
+
};
|
|
100
|
+
|
|
101
|
+
// `UButton`: its label, `disabled` in, `click` out (none while disabled).
|
|
102
|
+
const buttons: { label: string; disabled: boolean; click(): void }[] = [];
|
|
103
|
+
const UButton: Component = {
|
|
104
|
+
name: "UButton",
|
|
105
|
+
props: { disabled: Boolean },
|
|
106
|
+
emits: ["click"],
|
|
107
|
+
setup(
|
|
108
|
+
props: { disabled?: boolean },
|
|
109
|
+
{ emit, slots }: SetupContext<["click"]>,
|
|
110
|
+
) {
|
|
111
|
+
const stub = {
|
|
112
|
+
get label() {
|
|
113
|
+
return (slots.default?.() ?? [])
|
|
114
|
+
.map((node) =>
|
|
115
|
+
typeof node.children === "string" ? node.children : "",
|
|
116
|
+
)
|
|
117
|
+
.join("")
|
|
118
|
+
.trim();
|
|
119
|
+
},
|
|
120
|
+
get disabled() {
|
|
121
|
+
return props.disabled ?? false;
|
|
122
|
+
},
|
|
123
|
+
click() {
|
|
124
|
+
if (!stub.disabled) emit("click");
|
|
125
|
+
},
|
|
126
|
+
};
|
|
127
|
+
buttons.push(stub);
|
|
128
|
+
onUnmounted(() => {
|
|
129
|
+
buttons.splice(buttons.indexOf(stub), 1);
|
|
130
|
+
});
|
|
131
|
+
return () => h("button", null, slots.default?.());
|
|
132
|
+
},
|
|
133
|
+
};
|
|
134
|
+
|
|
135
|
+
const stubs: Record<string, Component> = {
|
|
136
|
+
UModal,
|
|
137
|
+
UTree,
|
|
138
|
+
UButton,
|
|
139
|
+
UIcon: { name: "UIcon", render: () => null },
|
|
140
|
+
};
|
|
141
|
+
|
|
142
|
+
const photos: MediaFolder = { id: 1, name: "Photos", parent: null };
|
|
143
|
+
const videos: MediaFolder = { id: 2, name: "Videos", parent: null };
|
|
144
|
+
|
|
145
|
+
let app: App<HeadlessNode> | undefined;
|
|
146
|
+
let pinia: Pinia;
|
|
147
|
+
const confirmed: (MediaFolder | null)[] = [];
|
|
148
|
+
const openChanges: boolean[] = [];
|
|
149
|
+
|
|
150
|
+
async function mountPicker(props: Record<string, unknown> = {}) {
|
|
151
|
+
app = createApp({
|
|
152
|
+
render: () =>
|
|
153
|
+
h(MapoMediaFolderPicker as Component, {
|
|
154
|
+
open: true,
|
|
155
|
+
onConfirm: (folder: MediaFolder | null) => confirmed.push(folder),
|
|
156
|
+
"onUpdate:open": (open: boolean) => openChanges.push(open),
|
|
157
|
+
...props,
|
|
158
|
+
}),
|
|
159
|
+
});
|
|
160
|
+
app.use(pinia);
|
|
161
|
+
for (const [name, stub] of Object.entries(stubs)) app.component(name, stub);
|
|
162
|
+
app.mount(headlessNode());
|
|
163
|
+
await new Promise((resolve) => setTimeout(resolve));
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
const confirmButton = () =>
|
|
167
|
+
buttons.find((b) => b.label === "mapo.mediaMove.confirm");
|
|
168
|
+
|
|
169
|
+
beforeEach(() => {
|
|
170
|
+
pinia = createPinia();
|
|
171
|
+
setActivePinia(pinia);
|
|
172
|
+
for (const fn of Object.values(crud)) fn.mockReset();
|
|
173
|
+
confirmed.length = 0;
|
|
174
|
+
openChanges.length = 0;
|
|
175
|
+
useMediaStore().folderChildren = { root: [photos, videos] };
|
|
176
|
+
});
|
|
177
|
+
|
|
178
|
+
afterEach(() => {
|
|
179
|
+
app?.unmount();
|
|
180
|
+
app = undefined;
|
|
181
|
+
});
|
|
182
|
+
|
|
183
|
+
describe("MapoMediaFolderPicker", () => {
|
|
184
|
+
it("confirms nothing until a folder is picked", async () => {
|
|
185
|
+
await mountPicker();
|
|
186
|
+
|
|
187
|
+
expect(confirmButton()?.disabled).toBe(true);
|
|
188
|
+
confirmButton()?.click();
|
|
189
|
+
expect(confirmed).toEqual([]);
|
|
190
|
+
});
|
|
191
|
+
|
|
192
|
+
it("confirms the picked folder and closes", async () => {
|
|
193
|
+
await mountPicker();
|
|
194
|
+
|
|
195
|
+
tree?.pick("2");
|
|
196
|
+
await new Promise((resolve) => setTimeout(resolve));
|
|
197
|
+
confirmButton()?.click();
|
|
198
|
+
|
|
199
|
+
expect(confirmed).toEqual([videos]);
|
|
200
|
+
expect(openChanges).toEqual([false]);
|
|
201
|
+
});
|
|
202
|
+
|
|
203
|
+
it("confirms the root as null", async () => {
|
|
204
|
+
await mountPicker();
|
|
205
|
+
|
|
206
|
+
tree?.pick("root");
|
|
207
|
+
await new Promise((resolve) => setTimeout(resolve));
|
|
208
|
+
confirmButton()?.click();
|
|
209
|
+
|
|
210
|
+
expect(confirmed).toEqual([null]);
|
|
211
|
+
});
|
|
212
|
+
|
|
213
|
+
it("hides the excluded folders", async () => {
|
|
214
|
+
await mountPicker({ exclude: [1] });
|
|
215
|
+
|
|
216
|
+
expect(tree?.items[0]?.children?.map((node) => node.label)).toEqual([
|
|
217
|
+
"Videos",
|
|
218
|
+
]);
|
|
219
|
+
});
|
|
220
|
+
});
|