@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,145 @@
|
|
|
1
|
+
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
|
|
2
|
+
import { createRenderer, h, nextTick, onUnmounted } from "vue";
|
|
3
|
+
import type { App, Component, SetupContext } from "vue";
|
|
4
|
+
|
|
5
|
+
import MapoDetailLangSwitch from "../runtime/components/MapoDetailLangSwitch.vue";
|
|
6
|
+
|
|
7
|
+
const route = vi.hoisted(() => ({ query: {} as Record<string, string> }));
|
|
8
|
+
const router = vi.hoisted(() => ({ replace: vi.fn() }));
|
|
9
|
+
|
|
10
|
+
vi.mock("#app", () => ({ useRoute: () => route, useRouter: () => router }));
|
|
11
|
+
|
|
12
|
+
// Tests run in Node without a DOM. A renderer whose nodes are plain objects is
|
|
13
|
+
// enough to mount the component with real reactivity, watchers and events. The
|
|
14
|
+
// tabs are template refs the switch scrolls into view, hence the no-op method.
|
|
15
|
+
interface HeadlessNode {
|
|
16
|
+
parent: HeadlessNode | null;
|
|
17
|
+
children: HeadlessNode[];
|
|
18
|
+
scrollIntoView(): void;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
const headlessNode = (): HeadlessNode => ({
|
|
22
|
+
parent: null,
|
|
23
|
+
children: [],
|
|
24
|
+
scrollIntoView: () => {},
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
const { createApp } = createRenderer<HeadlessNode, HeadlessNode>({
|
|
28
|
+
createElement: headlessNode,
|
|
29
|
+
createText: headlessNode,
|
|
30
|
+
createComment: headlessNode,
|
|
31
|
+
setText: () => {},
|
|
32
|
+
setElementText: () => {},
|
|
33
|
+
patchProp: () => {},
|
|
34
|
+
insert(child, parent, anchor) {
|
|
35
|
+
child.parent = parent;
|
|
36
|
+
const at = anchor ? parent.children.indexOf(anchor) : -1;
|
|
37
|
+
parent.children.splice(at < 0 ? parent.children.length : at, 0, child);
|
|
38
|
+
},
|
|
39
|
+
remove(child) {
|
|
40
|
+
child.parent?.children.splice(child.parent.children.indexOf(child), 1);
|
|
41
|
+
child.parent = null;
|
|
42
|
+
},
|
|
43
|
+
parentNode: (node) => node.parent,
|
|
44
|
+
nextSibling: (node) =>
|
|
45
|
+
node.parent?.children[node.parent.children.indexOf(node) + 1] ?? null,
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
// `USelectMenu` declares the contract the switch binds: `modelValue` and `items`
|
|
49
|
+
// in, `update:modelValue` out with the picked item's value (`value-key="value"`),
|
|
50
|
+
// and a default slot that receives `modelValue` and `open`.
|
|
51
|
+
interface SelectItem {
|
|
52
|
+
label: string;
|
|
53
|
+
value: string;
|
|
54
|
+
}
|
|
55
|
+
let select: { readonly items: SelectItem[]; pick(value: string): void } | null =
|
|
56
|
+
null;
|
|
57
|
+
|
|
58
|
+
const USelectMenu: Component = {
|
|
59
|
+
name: "USelectMenu",
|
|
60
|
+
props: { modelValue: String, items: Array },
|
|
61
|
+
emits: ["update:modelValue"],
|
|
62
|
+
setup(
|
|
63
|
+
props: { modelValue?: string; items?: SelectItem[] },
|
|
64
|
+
{ emit, slots }: SetupContext<["update:modelValue"]>,
|
|
65
|
+
) {
|
|
66
|
+
select = {
|
|
67
|
+
get items() {
|
|
68
|
+
return props.items ?? [];
|
|
69
|
+
},
|
|
70
|
+
pick: (value) => emit("update:modelValue", value),
|
|
71
|
+
};
|
|
72
|
+
onUnmounted(() => {
|
|
73
|
+
select = null;
|
|
74
|
+
});
|
|
75
|
+
return () =>
|
|
76
|
+
h(
|
|
77
|
+
"button",
|
|
78
|
+
null,
|
|
79
|
+
slots.default?.({ modelValue: props.modelValue, open: false }),
|
|
80
|
+
);
|
|
81
|
+
},
|
|
82
|
+
};
|
|
83
|
+
|
|
84
|
+
const NINE_LANGS = ["it", "en", "fr", "de", "es", "pt", "nl", "pl", "ru"];
|
|
85
|
+
const changes = vi.fn();
|
|
86
|
+
|
|
87
|
+
let app: App<HeadlessNode> | undefined;
|
|
88
|
+
|
|
89
|
+
function mountSwitch(props: Record<string, unknown>) {
|
|
90
|
+
const root: Component = {
|
|
91
|
+
render: () =>
|
|
92
|
+
h(MapoDetailLangSwitch as Component, {
|
|
93
|
+
modelValue: "it",
|
|
94
|
+
"onUpdate:modelValue": changes,
|
|
95
|
+
...props,
|
|
96
|
+
}),
|
|
97
|
+
};
|
|
98
|
+
app = createApp(root);
|
|
99
|
+
app.component("USelectMenu", USelectMenu);
|
|
100
|
+
app.mount(headlessNode());
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
beforeEach(() => {
|
|
104
|
+
route.query = {};
|
|
105
|
+
router.replace.mockReset();
|
|
106
|
+
changes.mockReset();
|
|
107
|
+
});
|
|
108
|
+
|
|
109
|
+
afterEach(() => {
|
|
110
|
+
app?.unmount();
|
|
111
|
+
app = undefined;
|
|
112
|
+
});
|
|
113
|
+
|
|
114
|
+
describe("MapoDetailLangSwitch", () => {
|
|
115
|
+
it("shows only the tabs up to the threshold", async () => {
|
|
116
|
+
mountSwitch({ langs: NINE_LANGS.slice(0, 8) });
|
|
117
|
+
await nextTick();
|
|
118
|
+
|
|
119
|
+
expect(select).toBeNull();
|
|
120
|
+
});
|
|
121
|
+
|
|
122
|
+
it("adds the select above the threshold", async () => {
|
|
123
|
+
mountSwitch({ langs: NINE_LANGS });
|
|
124
|
+
await nextTick();
|
|
125
|
+
|
|
126
|
+
expect(select?.items.map((item) => item.value)).toEqual(NINE_LANGS);
|
|
127
|
+
});
|
|
128
|
+
|
|
129
|
+
it("follows a custom threshold", async () => {
|
|
130
|
+
mountSwitch({ langs: ["it", "en"], langThreshold: 0 });
|
|
131
|
+
await nextTick();
|
|
132
|
+
|
|
133
|
+
expect(select).not.toBeNull();
|
|
134
|
+
});
|
|
135
|
+
|
|
136
|
+
it("switches language from the select", async () => {
|
|
137
|
+
mountSwitch({ langs: NINE_LANGS });
|
|
138
|
+
await nextTick();
|
|
139
|
+
|
|
140
|
+
select?.pick("de");
|
|
141
|
+
|
|
142
|
+
expect(changes).toHaveBeenCalledWith("de");
|
|
143
|
+
expect(router.replace).toHaveBeenCalledWith({ query: { lang: "de" } });
|
|
144
|
+
});
|
|
145
|
+
});
|
|
@@ -0,0 +1,166 @@
|
|
|
1
|
+
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
|
|
2
|
+
import { createRenderer, h, nextTick } from "vue";
|
|
3
|
+
import type { App, Component, SetupContext } from "vue";
|
|
4
|
+
|
|
5
|
+
import MapoList from "../runtime/components/MapoList.vue";
|
|
6
|
+
|
|
7
|
+
// Where MapoList puts its bulk actions: in the table's toolbar, next to the
|
|
8
|
+
// search, together with the app's `dtable.toolbar` content. Its children are
|
|
9
|
+
// stubs: the table renders the toolbar slot it gets and reports selections.
|
|
10
|
+
|
|
11
|
+
const route = vi.hoisted(() => ({ query: {} as Record<string, string> }));
|
|
12
|
+
const router = vi.hoisted(() => ({ replace: vi.fn() }));
|
|
13
|
+
vi.mock("#app", () => ({ useRoute: () => route, useRouter: () => router }));
|
|
14
|
+
|
|
15
|
+
// Nodes are plain objects that keep their tag and props.
|
|
16
|
+
interface HeadlessNode {
|
|
17
|
+
type: string;
|
|
18
|
+
parent: HeadlessNode | null;
|
|
19
|
+
children: HeadlessNode[];
|
|
20
|
+
props: Record<string, unknown>;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
const headlessNode = (type: string): HeadlessNode => ({
|
|
24
|
+
type,
|
|
25
|
+
parent: null,
|
|
26
|
+
children: [],
|
|
27
|
+
props: {},
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
const { createApp } = createRenderer<HeadlessNode, HeadlessNode>({
|
|
31
|
+
createElement: (type) => headlessNode(type),
|
|
32
|
+
createText: () => headlessNode("#text"),
|
|
33
|
+
createComment: () => headlessNode("#comment"),
|
|
34
|
+
setText: () => {},
|
|
35
|
+
setElementText: () => {},
|
|
36
|
+
patchProp(node, key, _previous, next) {
|
|
37
|
+
node.props[key] = next;
|
|
38
|
+
},
|
|
39
|
+
insert(child, parent, anchor) {
|
|
40
|
+
child.parent = parent;
|
|
41
|
+
const at = anchor ? parent.children.indexOf(anchor) : -1;
|
|
42
|
+
parent.children.splice(at < 0 ? parent.children.length : at, 0, child);
|
|
43
|
+
},
|
|
44
|
+
remove(child) {
|
|
45
|
+
child.parent?.children.splice(child.parent.children.indexOf(child), 1);
|
|
46
|
+
child.parent = null;
|
|
47
|
+
},
|
|
48
|
+
parentNode: (node) => node.parent,
|
|
49
|
+
nextSibling: (node) =>
|
|
50
|
+
node.parent?.children[node.parent.children.indexOf(node) + 1] ?? null,
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
// What the table stub was given, and how to make it report a selection.
|
|
54
|
+
const table = vi.hoisted(() => ({
|
|
55
|
+
slotNames: [] as string[],
|
|
56
|
+
select: undefined as ((rows: unknown[]) => void) | undefined,
|
|
57
|
+
}));
|
|
58
|
+
|
|
59
|
+
const stubs: Record<string, Component> = {
|
|
60
|
+
MapoListHead: { render: () => null },
|
|
61
|
+
MapoListTabs: { render: () => null },
|
|
62
|
+
MapoListFilters: { render: () => null },
|
|
63
|
+
MapoListActions: {
|
|
64
|
+
props: { selection: { type: [Array, String], default: () => [] } },
|
|
65
|
+
setup: (props: Record<string, unknown>) => () =>
|
|
66
|
+
h("actions", { selection: props.selection }),
|
|
67
|
+
},
|
|
68
|
+
MapoListTable: {
|
|
69
|
+
emits: ["update:selection", "update:selectionQuery", "update:items"],
|
|
70
|
+
setup(_props: unknown, { slots, emit, expose }: SetupContext) {
|
|
71
|
+
expose({ refresh: () => {} });
|
|
72
|
+
table.select = (rows) => emit("update:selection", rows);
|
|
73
|
+
return () => {
|
|
74
|
+
table.slotNames = Object.keys(slots);
|
|
75
|
+
return h("table", null, [
|
|
76
|
+
slots["dtable.toolbar"]
|
|
77
|
+
? h("toolbar", null, slots["dtable.toolbar"]())
|
|
78
|
+
: null,
|
|
79
|
+
]);
|
|
80
|
+
};
|
|
81
|
+
},
|
|
82
|
+
},
|
|
83
|
+
};
|
|
84
|
+
|
|
85
|
+
let app: App<HeadlessNode> | undefined;
|
|
86
|
+
let root: HeadlessNode;
|
|
87
|
+
|
|
88
|
+
function mount(
|
|
89
|
+
props: Record<string, unknown> = {},
|
|
90
|
+
slots: Record<string, () => unknown> = {},
|
|
91
|
+
) {
|
|
92
|
+
root = headlessNode("root");
|
|
93
|
+
const host: Component = {
|
|
94
|
+
render: () =>
|
|
95
|
+
h(
|
|
96
|
+
MapoList as Component,
|
|
97
|
+
{ endpoint: "/api/news/", columns: [], ...props },
|
|
98
|
+
slots,
|
|
99
|
+
),
|
|
100
|
+
};
|
|
101
|
+
app = createApp(host);
|
|
102
|
+
for (const [name, stub] of Object.entries(stubs)) app.component(name, stub);
|
|
103
|
+
app.mount(root);
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
const all = (node: HeadlessNode): HeadlessNode[] => [
|
|
107
|
+
node,
|
|
108
|
+
...node.children.flatMap(all),
|
|
109
|
+
];
|
|
110
|
+
const find = (type: string) => all(root).find((node) => node.type === type);
|
|
111
|
+
/** The toolbar's elements in order, without the anchors of fragments. */
|
|
112
|
+
const toolbarItems = () =>
|
|
113
|
+
find("toolbar")!.children.filter((node) => !node.type.startsWith("#"));
|
|
114
|
+
|
|
115
|
+
beforeEach(() => {
|
|
116
|
+
route.query = {};
|
|
117
|
+
table.slotNames = [];
|
|
118
|
+
table.select = undefined;
|
|
119
|
+
});
|
|
120
|
+
|
|
121
|
+
afterEach(() => {
|
|
122
|
+
app?.unmount();
|
|
123
|
+
app = undefined;
|
|
124
|
+
});
|
|
125
|
+
|
|
126
|
+
describe("MapoList bulk actions", () => {
|
|
127
|
+
it("puts them in the table's toolbar, where the search is", () => {
|
|
128
|
+
mount();
|
|
129
|
+
|
|
130
|
+
const actions = find("actions")!;
|
|
131
|
+
expect(actions.parent).toBe(find("toolbar"));
|
|
132
|
+
expect(actions.props.class).toBe("ml-auto");
|
|
133
|
+
});
|
|
134
|
+
|
|
135
|
+
it("puts the app's dtable.toolbar content before them", () => {
|
|
136
|
+
mount({}, { "dtable.toolbar": () => h("custom") });
|
|
137
|
+
|
|
138
|
+
expect(toolbarItems().map((node) => node.type)).toEqual([
|
|
139
|
+
"custom",
|
|
140
|
+
"actions",
|
|
141
|
+
]);
|
|
142
|
+
});
|
|
143
|
+
|
|
144
|
+
it("gives a list without search a toolbar only while rows are selected", async () => {
|
|
145
|
+
mount({ searchable: false });
|
|
146
|
+
expect(table.slotNames).not.toContain("dtable.toolbar");
|
|
147
|
+
expect(find("actions")).toBeUndefined();
|
|
148
|
+
|
|
149
|
+
table.select!([{ id: 1 }]);
|
|
150
|
+
await nextTick();
|
|
151
|
+
|
|
152
|
+
expect(find("actions")!.props.selection).toEqual([{ id: 1 }]);
|
|
153
|
+
|
|
154
|
+
table.select!([]);
|
|
155
|
+
await nextTick();
|
|
156
|
+
expect(find("toolbar")).toBeUndefined();
|
|
157
|
+
});
|
|
158
|
+
|
|
159
|
+
it("forwards the other slots to the table unchanged", () => {
|
|
160
|
+
mount({}, { "cell.title": () => h("cell"), "dtable.empty": () => null });
|
|
161
|
+
|
|
162
|
+
expect(table.slotNames).toEqual(
|
|
163
|
+
expect.arrayContaining(["cell.title", "dtable.empty", "dtable.toolbar"]),
|
|
164
|
+
);
|
|
165
|
+
});
|
|
166
|
+
});
|
|
@@ -0,0 +1,175 @@
|
|
|
1
|
+
import { beforeEach, describe, expect, it, vi } from "vitest";
|
|
2
|
+
import {
|
|
3
|
+
createRenderer,
|
|
4
|
+
defineComponent,
|
|
5
|
+
h,
|
|
6
|
+
nextTick,
|
|
7
|
+
onMounted,
|
|
8
|
+
watchEffect,
|
|
9
|
+
} from "vue";
|
|
10
|
+
import type { App, Component } from "vue";
|
|
11
|
+
|
|
12
|
+
import MapoListActions from "../runtime/components/MapoListActions.vue";
|
|
13
|
+
import type { ActionDescriptor } from "../runtime/types/list";
|
|
14
|
+
|
|
15
|
+
const permissions = vi.hoisted(() => ({
|
|
16
|
+
canDelete: vi.fn(),
|
|
17
|
+
checkPermission: vi.fn(),
|
|
18
|
+
}));
|
|
19
|
+
const crud = vi.hoisted(() => ({ delete: vi.fn() }));
|
|
20
|
+
|
|
21
|
+
vi.mock("vue-i18n", () => ({ useI18n: () => ({ t: (key: string) => key }) }));
|
|
22
|
+
vi.mock("@mapomodule/store/runtime/stores/snack", () => ({
|
|
23
|
+
useSnackStore: () => ({ show: vi.fn() }),
|
|
24
|
+
}));
|
|
25
|
+
vi.mock("@mapomodule/store/runtime/stores/confirm", () => ({
|
|
26
|
+
useConfirmStore: () => ({ ask: vi.fn() }),
|
|
27
|
+
}));
|
|
28
|
+
vi.mock("@mapomodule/store/runtime/composables/usePermissions", () => ({
|
|
29
|
+
usePermissions: () => permissions,
|
|
30
|
+
}));
|
|
31
|
+
vi.mock("@mapomodule/core/runtime/api/crud", () => ({
|
|
32
|
+
useCrud: () => crud,
|
|
33
|
+
}));
|
|
34
|
+
|
|
35
|
+
interface HeadlessNode {
|
|
36
|
+
parent: HeadlessNode | null;
|
|
37
|
+
children: HeadlessNode[];
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
const headlessNode = (): HeadlessNode => ({ parent: null, children: [] });
|
|
41
|
+
|
|
42
|
+
const { createApp } = createRenderer<HeadlessNode, HeadlessNode>({
|
|
43
|
+
createElement: headlessNode,
|
|
44
|
+
createText: headlessNode,
|
|
45
|
+
createComment: headlessNode,
|
|
46
|
+
setText: () => {},
|
|
47
|
+
setElementText: () => {},
|
|
48
|
+
patchProp: () => {},
|
|
49
|
+
insert(child, parent, anchor) {
|
|
50
|
+
child.parent = parent;
|
|
51
|
+
const at = anchor ? parent.children.indexOf(anchor) : -1;
|
|
52
|
+
parent.children.splice(at < 0 ? parent.children.length : at, 0, child);
|
|
53
|
+
},
|
|
54
|
+
remove(child) {
|
|
55
|
+
child.parent?.children.splice(child.parent.children.indexOf(child), 1);
|
|
56
|
+
child.parent = null;
|
|
57
|
+
},
|
|
58
|
+
parentNode: (node) => node.parent,
|
|
59
|
+
nextSibling: (node) =>
|
|
60
|
+
node.parent?.children[node.parent.children.indexOf(node) + 1] ?? null,
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
let actionItems: { label: string }[];
|
|
64
|
+
let applyDisabled: boolean;
|
|
65
|
+
|
|
66
|
+
// eslint-disable-next-line vue/one-component-per-file
|
|
67
|
+
const USelect: Component = defineComponent({
|
|
68
|
+
name: "USelect",
|
|
69
|
+
props: {
|
|
70
|
+
items: { type: Array, default: () => [] },
|
|
71
|
+
modelValue: { type: String, default: undefined },
|
|
72
|
+
},
|
|
73
|
+
emits: ["update:modelValue"],
|
|
74
|
+
setup(
|
|
75
|
+
props: { items?: { label: string }[] },
|
|
76
|
+
{ emit }: { emit: (event: "update:modelValue", value: string) => void },
|
|
77
|
+
) {
|
|
78
|
+
actionItems = props.items ?? [];
|
|
79
|
+
onMounted(() => {
|
|
80
|
+
const firstAction = props.items?.[0];
|
|
81
|
+
if (firstAction) emit("update:modelValue", firstAction.label);
|
|
82
|
+
});
|
|
83
|
+
return () => h("select");
|
|
84
|
+
},
|
|
85
|
+
});
|
|
86
|
+
|
|
87
|
+
// eslint-disable-next-line vue/one-component-per-file -- Separate UI control stub.
|
|
88
|
+
const UButton: Component = defineComponent({
|
|
89
|
+
name: "UButton",
|
|
90
|
+
props: { disabled: Boolean },
|
|
91
|
+
setup(props: { disabled?: boolean }) {
|
|
92
|
+
watchEffect(() => {
|
|
93
|
+
applyDisabled = !!props.disabled;
|
|
94
|
+
});
|
|
95
|
+
return () => h("button");
|
|
96
|
+
},
|
|
97
|
+
});
|
|
98
|
+
|
|
99
|
+
function mount(props: {
|
|
100
|
+
permissionModel?: string;
|
|
101
|
+
defaultActions?: boolean;
|
|
102
|
+
actions?: ActionDescriptor<{ id: number }>[];
|
|
103
|
+
}): App<HeadlessNode> {
|
|
104
|
+
// eslint-disable-next-line vue/one-component-per-file -- Mount the generic component under test.
|
|
105
|
+
const app = createApp(MapoListActions as Component, {
|
|
106
|
+
selection: [{ id: 1 }],
|
|
107
|
+
selectionQuery: new URLSearchParams(),
|
|
108
|
+
endpoint: "/api/items/",
|
|
109
|
+
...props,
|
|
110
|
+
});
|
|
111
|
+
app.component("USelect", USelect);
|
|
112
|
+
app.component("UButton", UButton);
|
|
113
|
+
app.mount(headlessNode());
|
|
114
|
+
return app;
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
describe("MapoListActions", () => {
|
|
118
|
+
beforeEach(() => {
|
|
119
|
+
permissions.canDelete.mockReset();
|
|
120
|
+
permissions.checkPermission.mockReset();
|
|
121
|
+
crud.delete.mockReset();
|
|
122
|
+
actionItems = [];
|
|
123
|
+
applyDisabled = true;
|
|
124
|
+
});
|
|
125
|
+
|
|
126
|
+
it("uses the model delete permission for its built-in action", async () => {
|
|
127
|
+
permissions.canDelete.mockReturnValue(false);
|
|
128
|
+
const deniedApp = mount({ permissionModel: "article" });
|
|
129
|
+
await nextTick();
|
|
130
|
+
await nextTick();
|
|
131
|
+
|
|
132
|
+
expect(actionItems.map(({ label }) => label)).toContain(
|
|
133
|
+
"mapo.listActions.permanentDelete",
|
|
134
|
+
);
|
|
135
|
+
expect(permissions.canDelete).toHaveBeenCalledWith("article");
|
|
136
|
+
expect(applyDisabled).toBe(true);
|
|
137
|
+
|
|
138
|
+
deniedApp.unmount();
|
|
139
|
+
permissions.canDelete.mockReturnValue(true);
|
|
140
|
+
const allowedApp = mount({ permissionModel: "article" });
|
|
141
|
+
await nextTick();
|
|
142
|
+
await nextTick();
|
|
143
|
+
|
|
144
|
+
expect(applyDisabled).toBe(false);
|
|
145
|
+
allowedApp.unmount();
|
|
146
|
+
});
|
|
147
|
+
|
|
148
|
+
it("preserves the built-in action when no permission model is provided", async () => {
|
|
149
|
+
const app = mount({});
|
|
150
|
+
await nextTick();
|
|
151
|
+
await nextTick();
|
|
152
|
+
|
|
153
|
+
expect(actionItems.map(({ label }) => label)).toContain(
|
|
154
|
+
"mapo.listActions.permanentDelete",
|
|
155
|
+
);
|
|
156
|
+
expect(applyDisabled).toBe(false);
|
|
157
|
+
expect(permissions.canDelete).not.toHaveBeenCalled();
|
|
158
|
+
|
|
159
|
+
app.unmount();
|
|
160
|
+
});
|
|
161
|
+
|
|
162
|
+
it("can omit the built-in action without omitting custom actions", async () => {
|
|
163
|
+
const customAction: ActionDescriptor<{ id: number }> = {
|
|
164
|
+
label: "Archive",
|
|
165
|
+
handler: async () => {},
|
|
166
|
+
};
|
|
167
|
+
const app = mount({ defaultActions: false, actions: [customAction] });
|
|
168
|
+
await nextTick();
|
|
169
|
+
await nextTick();
|
|
170
|
+
|
|
171
|
+
expect(actionItems.map(({ label }) => label)).toEqual(["Archive"]);
|
|
172
|
+
|
|
173
|
+
app.unmount();
|
|
174
|
+
});
|
|
175
|
+
});
|