@jskit-ai/shell-web 0.2.4 → 0.2.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +10 -4
- package/src/client/asyncModuleRecovery/index.js +1 -0
- package/src/client/asyncModuleRecovery/inject.js +30 -18
- package/src/client/asyncModuleRecovery/runtime.js +14 -22
- package/src/client/bootstrap/bootstrapPayloadHandlerRegistry.js +13 -6
- package/src/client/browser.js +56 -0
- package/src/client/clientUpdate/runtime.js +28 -18
- package/src/client/components/ShellErrorHost.vue +19 -219
- package/src/client/components/ShellLayout.vue +19 -227
- package/src/client/components/ShellOutlet.vue +16 -53
- package/src/client/components/ShellRouteTransition.vue +2 -291
- package/src/client/composables/shellLayoutDrawerPreference.js +15 -8
- package/src/client/composables/useShellDrawer.js +194 -0
- package/src/client/composables/useShellErrorHost.js +171 -0
- package/src/client/composables/useShellLayoutState.js +10 -20
- package/src/client/composables/useShellNavigationLink.js +6 -6
- package/src/client/composables/useShellPullToRefresh.js +15 -19
- package/src/client/composables/useShellRouteTransition.js +218 -0
- package/src/client/error/index.js +1 -1
- package/src/client/error/inject.js +36 -48
- package/src/client/error/normalize.js +2 -3
- package/src/client/error/policy.js +9 -0
- package/src/client/error/presentation.js +67 -0
- package/src/client/error/presentationDefaults.js +2 -2
- package/src/client/error/presenters.js +44 -19
- package/src/client/error/runtime.js +20 -17
- package/src/client/error/store.js +4 -0
- package/src/client/navigation/linkResolver.js +6 -2
- package/src/client/navigation/usePaths.js +11 -8
- package/src/client/navigation/useSurfaceRouteContext.js +3 -3
- package/src/client/placement/debug.js +2 -2
- package/src/client/placement/index.js +1 -0
- package/src/client/placement/inject.js +49 -46
- package/src/client/placement/pathname.js +3 -9
- package/src/client/placement/runtime.js +4 -16
- package/src/client/placement/surfaceContext.js +14 -33
- package/src/client/placement/validators.js +6 -1
- package/src/client/providers/ShellWebClientProvider.js +14 -32
- package/src/client/providers/appModuleLoadFailure.js +1 -1
- package/src/client/requestRecovery/index.js +1 -0
- package/src/client/requestRecovery/inject.js +29 -17
- package/src/client/requestRecovery/runtime.js +33 -84
- package/src/client/runtime/bootstrapRuntime.js +10 -32
- package/src/client/runtime/refreshRuntime.js +24 -21
- package/src/client/stores/useShellErrorPresentationStore.js +5 -19
- package/src/client/support/drawerWidth.js +39 -0
- package/src/client/support/gestureTargets.js +4 -2
- package/src/client/support/menuLinkTarget.js +1 -1
- package/src/client/support/navigationLinkKeyboard.js +1 -1
- package/src/client/support/primaryNavigation.js +93 -0
- package/src/client/support/routeSwipeGesture.js +13 -3
- package/src/client/support/shellLayoutClass.js +4 -6
- package/src/client/types.js +38 -0
- package/test/asyncModuleRecoveryInject.test.js +13 -18
- package/test/browser.test.js +51 -0
- package/test/clientUpdate.test.js +12 -1
- package/test/drawerWidth.test.js +64 -0
- package/test/errorActions.test.js +7 -2
- package/test/errorPresentation.test.js +51 -0
- package/test/placementInject.test.js +60 -0
- package/test/primaryNavigation.test.js +75 -0
- package/test/provider.test.js +18 -4
- package/test/requestRecovery.test.js +13 -18
- package/test/settingsPlacementContract.test.js +12 -8
- package/test/support/mountComposable.js +90 -0
- package/test/useShellDrawer.test.js +213 -0
- package/test/useShellErrorHost.test.js +149 -0
- package/test/useShellRouteTransition.test.js +129 -0
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
import { createRenderer, defineComponent } from "vue";
|
|
2
|
+
|
|
3
|
+
function node(type) {
|
|
4
|
+
return { type, props: {}, children: [], parent: null, text: "" };
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
const renderer = createRenderer({
|
|
8
|
+
createElement: node,
|
|
9
|
+
createText: () => node("text"),
|
|
10
|
+
createComment: () => node("comment"),
|
|
11
|
+
setText() {},
|
|
12
|
+
setElementText() {},
|
|
13
|
+
patchProp() {},
|
|
14
|
+
parentNode: (item) => item.parent,
|
|
15
|
+
nextSibling: () => null,
|
|
16
|
+
insert(item, parent) {
|
|
17
|
+
item.parent = parent;
|
|
18
|
+
parent.children.push(item);
|
|
19
|
+
},
|
|
20
|
+
remove(item) {
|
|
21
|
+
item.parent?.children.splice(item.parent.children.indexOf(item), 1);
|
|
22
|
+
}
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
// Runs a composable inside a mounted component, with what the application provides.
|
|
26
|
+
function mountComposable(useComposable, { provide = [], plugins = [] } = {}) {
|
|
27
|
+
let result = null;
|
|
28
|
+
const app = renderer.createApp(defineComponent({
|
|
29
|
+
setup() {
|
|
30
|
+
result = useComposable();
|
|
31
|
+
return () => null;
|
|
32
|
+
}
|
|
33
|
+
}));
|
|
34
|
+
for (const plugin of plugins) {
|
|
35
|
+
app.use(plugin);
|
|
36
|
+
}
|
|
37
|
+
for (const [key, value] of provide) {
|
|
38
|
+
app.provide(key, value);
|
|
39
|
+
}
|
|
40
|
+
app.mount(node("root"));
|
|
41
|
+
return { app, result };
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
// A window whose listeners a test can dispatch to, and a document with what the shell's composables read.
|
|
45
|
+
function installPage(t, { window: windowMembers = {}, document: documentMembers = {} } = {}) {
|
|
46
|
+
const listeners = new Map();
|
|
47
|
+
const classes = new Set();
|
|
48
|
+
globalThis.window = {
|
|
49
|
+
location: { href: "https://app.test/", origin: "https://app.test" },
|
|
50
|
+
addEventListener(type, handler) {
|
|
51
|
+
listeners.set(type, handler);
|
|
52
|
+
},
|
|
53
|
+
removeEventListener(type, handler) {
|
|
54
|
+
if (listeners.get(type) === handler) {
|
|
55
|
+
listeners.delete(type);
|
|
56
|
+
}
|
|
57
|
+
},
|
|
58
|
+
...windowMembers
|
|
59
|
+
};
|
|
60
|
+
globalThis.document = {
|
|
61
|
+
documentElement: {
|
|
62
|
+
classList: {
|
|
63
|
+
toggle(name, enabled) {
|
|
64
|
+
if (enabled) {
|
|
65
|
+
classes.add(name);
|
|
66
|
+
} else {
|
|
67
|
+
classes.delete(name);
|
|
68
|
+
}
|
|
69
|
+
},
|
|
70
|
+
remove(name) {
|
|
71
|
+
classes.delete(name);
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
},
|
|
75
|
+
...documentMembers
|
|
76
|
+
};
|
|
77
|
+
t.after(() => {
|
|
78
|
+
delete globalThis.window;
|
|
79
|
+
delete globalThis.document;
|
|
80
|
+
});
|
|
81
|
+
return {
|
|
82
|
+
classes,
|
|
83
|
+
listeners,
|
|
84
|
+
dispatch(type, event) {
|
|
85
|
+
listeners.get(type)({ preventDefault() {}, target: { closest: () => null, setPointerCapture() {} }, ...event });
|
|
86
|
+
}
|
|
87
|
+
};
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
export { installPage, mountComposable };
|
|
@@ -0,0 +1,213 @@
|
|
|
1
|
+
import assert from "node:assert/strict";
|
|
2
|
+
import test from "node:test";
|
|
3
|
+
import { computed, nextTick, ref } from "vue";
|
|
4
|
+
import { useShellDrawer } from "../src/client/composables/useShellDrawer.js";
|
|
5
|
+
import { installPage, mountComposable } from "./support/mountComposable.js";
|
|
6
|
+
|
|
7
|
+
const LABEL_TEXT_WIDTH = 150;
|
|
8
|
+
|
|
9
|
+
function createDrawerElement() {
|
|
10
|
+
const label = { style: { display: "block", visibility: "visible" } };
|
|
11
|
+
return {
|
|
12
|
+
label,
|
|
13
|
+
getBoundingClientRect: () => ({ left: 0, right: 248 }),
|
|
14
|
+
querySelector: () => null,
|
|
15
|
+
querySelectorAll: () => [label]
|
|
16
|
+
};
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
function mountDrawer(t, { compact = false, props = {} } = {}) {
|
|
20
|
+
const frames = [];
|
|
21
|
+
const drawerElement = createDrawerElement();
|
|
22
|
+
const fontListeners = new Set();
|
|
23
|
+
const page = installPage(t, {
|
|
24
|
+
window: {
|
|
25
|
+
requestAnimationFrame(callback) {
|
|
26
|
+
frames.push(callback);
|
|
27
|
+
return frames.length;
|
|
28
|
+
},
|
|
29
|
+
cancelAnimationFrame(id) {
|
|
30
|
+
frames[id - 1] = null;
|
|
31
|
+
},
|
|
32
|
+
getComputedStyle: (element) => element.style || { direction: "ltr", borderRightWidth: "1px" }
|
|
33
|
+
},
|
|
34
|
+
document: {
|
|
35
|
+
fonts: {
|
|
36
|
+
ready: Promise.resolve(),
|
|
37
|
+
addEventListener: (_type, listener) => fontListeners.add(listener),
|
|
38
|
+
removeEventListener: (_type, listener) => fontListeners.delete(listener)
|
|
39
|
+
},
|
|
40
|
+
getElementById: () => drawerElement,
|
|
41
|
+
createRange: () => ({
|
|
42
|
+
selectNodeContents() {},
|
|
43
|
+
getBoundingClientRect: () => ({ left: 16, right: 16 + LABEL_TEXT_WIDTH, width: LABEL_TEXT_WIDTH })
|
|
44
|
+
})
|
|
45
|
+
}
|
|
46
|
+
});
|
|
47
|
+
const observers = [];
|
|
48
|
+
globalThis.MutationObserver = class {
|
|
49
|
+
constructor(callback) {
|
|
50
|
+
this.callback = callback;
|
|
51
|
+
this.connected = false;
|
|
52
|
+
observers.push(this);
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
observe() {
|
|
56
|
+
this.connected = true;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
disconnect() {
|
|
60
|
+
this.connected = false;
|
|
61
|
+
}
|
|
62
|
+
};
|
|
63
|
+
t.after(() => {
|
|
64
|
+
delete globalThis.MutationObserver;
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
const isCompactLayout = ref(compact);
|
|
68
|
+
const drawerOpen = ref(true);
|
|
69
|
+
const focused = [];
|
|
70
|
+
const navigationToggle = ref({ $el: { focus: (options) => focused.push(options) } });
|
|
71
|
+
const { app, result } = mountComposable(() => useShellDrawer({
|
|
72
|
+
props: {
|
|
73
|
+
desktopDrawerClosedMode: "rail",
|
|
74
|
+
drawerWidth: null,
|
|
75
|
+
railWidth: 80,
|
|
76
|
+
navigationItemSpacing: 12,
|
|
77
|
+
...props
|
|
78
|
+
},
|
|
79
|
+
isCompactLayout,
|
|
80
|
+
navigationToggle,
|
|
81
|
+
layoutState: {
|
|
82
|
+
drawerDefaultOpen: ref(true),
|
|
83
|
+
drawerOpen,
|
|
84
|
+
resolvedSurface: computed(() => "home"),
|
|
85
|
+
setDrawerOpen(open) {
|
|
86
|
+
drawerOpen.value = open;
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
}));
|
|
90
|
+
return { app, drawerOpen, focused, fontListeners, frames, isCompactLayout, observers, page, result };
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
async function runFrames(frames) {
|
|
94
|
+
await nextTick();
|
|
95
|
+
await nextTick();
|
|
96
|
+
for (const frame of frames.splice(0)) {
|
|
97
|
+
frame?.();
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
test("a compact layout closes the drawer and a wide one restores how it was left there", async (t) => {
|
|
102
|
+
const { app, drawerOpen, isCompactLayout, result } = mountDrawer(t);
|
|
103
|
+
assert.equal(drawerOpen.value, true);
|
|
104
|
+
assert.equal(result.drawerPresentation.value.kind, "drawer");
|
|
105
|
+
|
|
106
|
+
drawerOpen.value = false;
|
|
107
|
+
await nextTick();
|
|
108
|
+
assert.equal(result.drawerPresentation.value.kind, "rail");
|
|
109
|
+
|
|
110
|
+
isCompactLayout.value = true;
|
|
111
|
+
await nextTick();
|
|
112
|
+
assert.equal(drawerOpen.value, false);
|
|
113
|
+
assert.equal(result.drawerPresentation.value.kind, "modal");
|
|
114
|
+
|
|
115
|
+
drawerOpen.value = true;
|
|
116
|
+
await nextTick();
|
|
117
|
+
isCompactLayout.value = false;
|
|
118
|
+
await nextTick();
|
|
119
|
+
assert.equal(drawerOpen.value, false);
|
|
120
|
+
app.unmount();
|
|
121
|
+
});
|
|
122
|
+
|
|
123
|
+
test("a wide layout reopens a drawer left open there", async (t) => {
|
|
124
|
+
const { app, drawerOpen, isCompactLayout } = mountDrawer(t);
|
|
125
|
+
|
|
126
|
+
isCompactLayout.value = true;
|
|
127
|
+
await nextTick();
|
|
128
|
+
assert.equal(drawerOpen.value, false);
|
|
129
|
+
|
|
130
|
+
isCompactLayout.value = false;
|
|
131
|
+
await nextTick();
|
|
132
|
+
assert.equal(drawerOpen.value, true);
|
|
133
|
+
app.unmount();
|
|
134
|
+
});
|
|
135
|
+
|
|
136
|
+
test("a compact layout starts closed", (t) => {
|
|
137
|
+
const { app, drawerOpen, result } = mountDrawer(t, { compact: true });
|
|
138
|
+
assert.equal(drawerOpen.value, false);
|
|
139
|
+
assert.equal(result.drawerPresentation.value.visible, false);
|
|
140
|
+
app.unmount();
|
|
141
|
+
});
|
|
142
|
+
|
|
143
|
+
test("Escape closes the compact drawer and returns focus to its toggle", async (t) => {
|
|
144
|
+
const { app, drawerOpen, focused, page } = mountDrawer(t, { compact: true });
|
|
145
|
+
|
|
146
|
+
page.dispatch("keydown", { key: "Escape" });
|
|
147
|
+
assert.deepEqual(focused, []);
|
|
148
|
+
|
|
149
|
+
drawerOpen.value = true;
|
|
150
|
+
await nextTick();
|
|
151
|
+
page.dispatch("keydown", { key: "Enter" });
|
|
152
|
+
assert.equal(drawerOpen.value, true);
|
|
153
|
+
page.dispatch("keydown", { key: "Escape", defaultPrevented: true });
|
|
154
|
+
assert.equal(drawerOpen.value, true);
|
|
155
|
+
|
|
156
|
+
page.dispatch("keydown", { key: "Escape" });
|
|
157
|
+
assert.equal(drawerOpen.value, false);
|
|
158
|
+
await nextTick();
|
|
159
|
+
await nextTick();
|
|
160
|
+
assert.deepEqual(focused, [{ preventScroll: true }]);
|
|
161
|
+
app.unmount();
|
|
162
|
+
});
|
|
163
|
+
|
|
164
|
+
test("the drawer's width follows its measured labels", async (t) => {
|
|
165
|
+
const { app, frames, observers, result } = mountDrawer(t);
|
|
166
|
+
assert.equal(result.resolvedDrawerWidth.value, 248);
|
|
167
|
+
|
|
168
|
+
await runFrames(frames);
|
|
169
|
+
|
|
170
|
+
assert.equal(result.resolvedDrawerWidth.value, 16 + LABEL_TEXT_WIDTH + 12 + 1);
|
|
171
|
+
assert.equal(observers.length, 1);
|
|
172
|
+
assert.equal(observers[0].connected, true);
|
|
173
|
+
app.unmount();
|
|
174
|
+
});
|
|
175
|
+
|
|
176
|
+
test("a fixed drawer width is never measured", async (t) => {
|
|
177
|
+
const { app, frames, result } = mountDrawer(t, { props: { drawerWidth: 300 } });
|
|
178
|
+
|
|
179
|
+
await runFrames(frames);
|
|
180
|
+
|
|
181
|
+
assert.equal(result.fixedDrawerWidth.value, true);
|
|
182
|
+
assert.equal(result.resolvedDrawerWidth.value, 300);
|
|
183
|
+
assert.equal(frames.length, 0);
|
|
184
|
+
app.unmount();
|
|
185
|
+
});
|
|
186
|
+
|
|
187
|
+
test("a closed wide drawer only ignores a request to open it", (t) => {
|
|
188
|
+
const { app, drawerOpen, result } = mountDrawer(t);
|
|
189
|
+
|
|
190
|
+
drawerOpen.value = false;
|
|
191
|
+
result.handleDrawerVisibilityChange(true);
|
|
192
|
+
assert.equal(drawerOpen.value, false);
|
|
193
|
+
|
|
194
|
+
drawerOpen.value = true;
|
|
195
|
+
result.handleDrawerVisibilityChange(false);
|
|
196
|
+
assert.equal(drawerOpen.value, false);
|
|
197
|
+
app.unmount();
|
|
198
|
+
});
|
|
199
|
+
|
|
200
|
+
test("unmounting detaches every listener and pending measurement", async (t) => {
|
|
201
|
+
const { app, fontListeners, frames, observers, page } = mountDrawer(t);
|
|
202
|
+
await nextTick();
|
|
203
|
+
await nextTick();
|
|
204
|
+
assert.equal(page.listeners.size, 2);
|
|
205
|
+
assert.equal(fontListeners.size, 1);
|
|
206
|
+
|
|
207
|
+
app.unmount();
|
|
208
|
+
|
|
209
|
+
assert.equal(page.listeners.size, 0);
|
|
210
|
+
assert.equal(fontListeners.size, 0);
|
|
211
|
+
assert.equal(observers[0].connected, false);
|
|
212
|
+
assert.deepEqual(frames.filter(Boolean), []);
|
|
213
|
+
});
|
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
import assert from "node:assert/strict";
|
|
2
|
+
import test from "node:test";
|
|
3
|
+
import { markRaw, nextTick, shallowRef } from "vue";
|
|
4
|
+
import { createPinia } from "pinia";
|
|
5
|
+
import { useShellErrorHost } from "../src/client/composables/useShellErrorHost.js";
|
|
6
|
+
import { SHELL_WEB_ERROR_RUNTIME_KEY } from "../src/client/error/inject.js";
|
|
7
|
+
import { createErrorPresentationStore } from "../src/client/error/store.js";
|
|
8
|
+
import { useShellErrorPresentationStore } from "../src/client/stores/useShellErrorPresentationStore.js";
|
|
9
|
+
import { mountComposable } from "./support/mountComposable.js";
|
|
10
|
+
|
|
11
|
+
function mountHost(t, { top = 0 } = {}) {
|
|
12
|
+
const heights = new Map();
|
|
13
|
+
globalThis.document = {
|
|
14
|
+
documentElement: {
|
|
15
|
+
style: {
|
|
16
|
+
setProperty: (name, value) => heights.set(name, value),
|
|
17
|
+
removeProperty: (name) => heights.delete(name)
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
};
|
|
21
|
+
const observers = [];
|
|
22
|
+
globalThis.ResizeObserver = class {
|
|
23
|
+
constructor(callback) {
|
|
24
|
+
this.callback = callback;
|
|
25
|
+
observers.push(this);
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
observe(element) {
|
|
29
|
+
this.element = element;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
disconnect() {
|
|
33
|
+
this.element = null;
|
|
34
|
+
}
|
|
35
|
+
};
|
|
36
|
+
t.after(() => {
|
|
37
|
+
delete globalThis.document;
|
|
38
|
+
delete globalThis.ResizeObserver;
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
const pinia = createPinia();
|
|
42
|
+
const store = createErrorPresentationStore();
|
|
43
|
+
useShellErrorPresentationStore(pinia).attachRuntimeStore(store);
|
|
44
|
+
const reports = [];
|
|
45
|
+
const layoutRect = shallowRef({ top, left: 0, right: 0, bottom: 0 });
|
|
46
|
+
const { app, result } = mountComposable(useShellErrorHost, {
|
|
47
|
+
plugins: [pinia],
|
|
48
|
+
provide: [
|
|
49
|
+
[SHELL_WEB_ERROR_RUNTIME_KEY, { report: (event) => reports.push(event) }],
|
|
50
|
+
[Symbol.for("vuetify:layout"), { mainRect: layoutRect }]
|
|
51
|
+
]
|
|
52
|
+
});
|
|
53
|
+
return { app, heights, host: result, layoutRect, observers, reports, store };
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
test("snackbars show one at a time and the next opens after the last one leaves", async (t) => {
|
|
57
|
+
const { app, host, store } = mountHost(t);
|
|
58
|
+
const first = store.present("snackbar", { message: "First" });
|
|
59
|
+
store.present("snackbar", { message: "Second" });
|
|
60
|
+
await nextTick();
|
|
61
|
+
|
|
62
|
+
assert.equal(host.displayedSnackbarEntry.value.id, first);
|
|
63
|
+
assert.equal(host.snackbarOpen.value, true);
|
|
64
|
+
|
|
65
|
+
host.onSnackbarModelValue(false);
|
|
66
|
+
await nextTick();
|
|
67
|
+
assert.equal(host.snackbarOpen.value, false);
|
|
68
|
+
assert.equal(host.displayedSnackbarEntry.value.id, first);
|
|
69
|
+
|
|
70
|
+
host.onSnackbarAfterLeave();
|
|
71
|
+
assert.equal(host.displayedSnackbarEntry.value.message, "Second");
|
|
72
|
+
assert.equal(host.snackbarOpen.value, true);
|
|
73
|
+
|
|
74
|
+
host.onSnackbarModelValue(false);
|
|
75
|
+
await nextTick();
|
|
76
|
+
host.onSnackbarAfterLeave();
|
|
77
|
+
assert.equal(host.displayedSnackbarEntry.value, null);
|
|
78
|
+
assert.equal(host.snackbarOpen.value, false);
|
|
79
|
+
app.unmount();
|
|
80
|
+
});
|
|
81
|
+
|
|
82
|
+
test("a dialog closes on request unless it persists", async (t) => {
|
|
83
|
+
const { app, host, store } = mountHost(t);
|
|
84
|
+
store.present("dialog", { message: "Closable" });
|
|
85
|
+
await nextTick();
|
|
86
|
+
host.onDialogModelValue(false);
|
|
87
|
+
await nextTick();
|
|
88
|
+
assert.equal(host.dialogEntry.value, null);
|
|
89
|
+
|
|
90
|
+
store.present("dialog", { message: "Stays", persist: true });
|
|
91
|
+
await nextTick();
|
|
92
|
+
host.onDialogModelValue(false);
|
|
93
|
+
await nextTick();
|
|
94
|
+
assert.equal(host.dialogEntry.value.message, "Stays");
|
|
95
|
+
app.unmount();
|
|
96
|
+
});
|
|
97
|
+
|
|
98
|
+
test("a failed action reports through the shell and still dismisses its entry", async (t) => {
|
|
99
|
+
const { app, host, reports, store } = mountHost(t);
|
|
100
|
+
store.present("snackbar", { message: "Saved" });
|
|
101
|
+
await nextTick();
|
|
102
|
+
const failure = new Error("Undo failed");
|
|
103
|
+
|
|
104
|
+
await host.runAction(host.displayedSnackbarEntry.value, {
|
|
105
|
+
async handler() {
|
|
106
|
+
throw failure;
|
|
107
|
+
}
|
|
108
|
+
});
|
|
109
|
+
|
|
110
|
+
assert.equal(reports[0].cause, failure);
|
|
111
|
+
assert.equal(reports[0].intent, "blocking");
|
|
112
|
+
assert.equal(store.getState().channels.snackbar.length, 0);
|
|
113
|
+
app.unmount();
|
|
114
|
+
});
|
|
115
|
+
|
|
116
|
+
test("an action can keep its entry open", async (t) => {
|
|
117
|
+
const { app, host, store } = mountHost(t);
|
|
118
|
+
store.present("snackbar", { message: "Saved" });
|
|
119
|
+
await nextTick();
|
|
120
|
+
|
|
121
|
+
await host.runAction(host.displayedSnackbarEntry.value, { handler() {}, dismissOnRun: false });
|
|
122
|
+
|
|
123
|
+
assert.equal(store.getState().channels.snackbar.length, 1);
|
|
124
|
+
app.unmount();
|
|
125
|
+
});
|
|
126
|
+
|
|
127
|
+
test("inline banners publish their height and withdraw it when they float or go", async (t) => {
|
|
128
|
+
const { app, heights, host, layoutRect, observers } = mountHost(t);
|
|
129
|
+
const element = markRaw({ getBoundingClientRect: () => ({ height: 40.2 }) });
|
|
130
|
+
assert.equal(host.bannerPlacement.value.inline, true);
|
|
131
|
+
|
|
132
|
+
host.bannersElement.value = element;
|
|
133
|
+
await nextTick();
|
|
134
|
+
assert.equal(heights.get("--shell-error-banners-inline-height"), "41px");
|
|
135
|
+
assert.equal(observers[0].element, element);
|
|
136
|
+
|
|
137
|
+
layoutRect.value = { top: 64, left: 0, right: 0, bottom: 0 };
|
|
138
|
+
await nextTick();
|
|
139
|
+
assert.equal(host.bannerPlacement.value.inline, false);
|
|
140
|
+
assert.equal(heights.size, 0);
|
|
141
|
+
assert.equal(observers[0].element, null);
|
|
142
|
+
|
|
143
|
+
layoutRect.value = { top: 0, left: 0, right: 0, bottom: 0 };
|
|
144
|
+
await nextTick();
|
|
145
|
+
assert.equal(heights.size, 1);
|
|
146
|
+
|
|
147
|
+
app.unmount();
|
|
148
|
+
assert.equal(heights.size, 0);
|
|
149
|
+
});
|
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
import assert from "node:assert/strict";
|
|
2
|
+
import test from "node:test";
|
|
3
|
+
import { reactive, ref } from "vue";
|
|
4
|
+
import { routeLocationKey, routerKey } from "vue-router";
|
|
5
|
+
import { useShellRouteTransition } from "../src/client/composables/useShellRouteTransition.js";
|
|
6
|
+
import { SHELL_WEB_PLACEMENT_RUNTIME_KEY } from "../src/client/placement/inject.js";
|
|
7
|
+
import { installPage, mountComposable } from "./support/mountComposable.js";
|
|
8
|
+
|
|
9
|
+
const SURFACE_CONFIG = Object.freeze({
|
|
10
|
+
defaultSurfaceId: "home",
|
|
11
|
+
enabledSurfaceIds: ["home"],
|
|
12
|
+
surfacesById: {
|
|
13
|
+
home: { id: "home", pagesRoot: "home", routeBase: "/home", enabled: true }
|
|
14
|
+
}
|
|
15
|
+
});
|
|
16
|
+
|
|
17
|
+
function createPlacementRuntime() {
|
|
18
|
+
const placements = [
|
|
19
|
+
{ id: "home", target: "shell.primary-nav", props: { to: "/home", exact: true } },
|
|
20
|
+
{ id: "contacts", target: "shell.primary-nav", props: { to: "/home/contacts" } },
|
|
21
|
+
{ id: "bookings", target: "shell.primary-nav", props: { to: "/home/bookings" } }
|
|
22
|
+
];
|
|
23
|
+
return {
|
|
24
|
+
getContext: () => ({ surfaceConfig: SURFACE_CONFIG }),
|
|
25
|
+
getPlacements: () => placements,
|
|
26
|
+
getRevision: () => 1,
|
|
27
|
+
subscribe: () => () => {}
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
function mountTransition(t, { path = "/home/contacts", displayName = "xs", props = {} } = {}) {
|
|
32
|
+
const page = installPage(t);
|
|
33
|
+
const route = reactive({ path, params: {} });
|
|
34
|
+
const pushes = [];
|
|
35
|
+
const router = {
|
|
36
|
+
async push(href) {
|
|
37
|
+
pushes.push(href);
|
|
38
|
+
route.path = href;
|
|
39
|
+
}
|
|
40
|
+
};
|
|
41
|
+
const { app, result } = mountComposable(
|
|
42
|
+
() => useShellRouteTransition({
|
|
43
|
+
enabled: true,
|
|
44
|
+
target: "shell-layout:primary-bottom-nav",
|
|
45
|
+
semanticTarget: "shell.primary-nav",
|
|
46
|
+
swipeEnabled: true,
|
|
47
|
+
...props
|
|
48
|
+
}),
|
|
49
|
+
{
|
|
50
|
+
provide: [
|
|
51
|
+
[routerKey, router],
|
|
52
|
+
[routeLocationKey, route],
|
|
53
|
+
[Symbol.for("vuetify:display"), { name: ref(displayName), mobile: ref(false) }],
|
|
54
|
+
[SHELL_WEB_PLACEMENT_RUNTIME_KEY, createPlacementRuntime()]
|
|
55
|
+
]
|
|
56
|
+
}
|
|
57
|
+
);
|
|
58
|
+
return { app, page, pushes, result, route };
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
const touch = { isPrimary: true, button: 0, pointerType: "touch", pointerId: 3 };
|
|
62
|
+
|
|
63
|
+
test("a swipe moves between destinations and names the direction of the motion", (t) => {
|
|
64
|
+
const { app, page, pushes, result } = mountTransition(t);
|
|
65
|
+
assert.equal(page.classes.has("shell-route-swipe-enabled"), true);
|
|
66
|
+
assert.equal(result.routeTransitionName.value, "");
|
|
67
|
+
|
|
68
|
+
page.dispatch("pointerdown", { ...touch, clientX: 300, clientY: 100 });
|
|
69
|
+
page.dispatch("pointermove", { ...touch, clientX: 200, clientY: 102 });
|
|
70
|
+
|
|
71
|
+
assert.deepEqual(pushes, ["/home/bookings"]);
|
|
72
|
+
assert.equal(result.routeTransitionName.value, "shell-route-slide-forward");
|
|
73
|
+
assert.equal(result.routeTransitionKey.value, "/home/bookings");
|
|
74
|
+
|
|
75
|
+
page.dispatch("pointerdown", { ...touch, clientX: 100, clientY: 100 });
|
|
76
|
+
page.dispatch("pointermove", { ...touch, clientX: 200, clientY: 102 });
|
|
77
|
+
|
|
78
|
+
assert.deepEqual(pushes, ["/home/bookings", "/home/contacts"]);
|
|
79
|
+
assert.equal(result.routeTransitionName.value, "shell-route-slide-reverse");
|
|
80
|
+
app.unmount();
|
|
81
|
+
});
|
|
82
|
+
|
|
83
|
+
test("a route change away from every destination has no motion", (t) => {
|
|
84
|
+
const { app, result, route } = mountTransition(t);
|
|
85
|
+
|
|
86
|
+
route.path = "/home/bookings";
|
|
87
|
+
assert.equal(result.routeTransitionName.value, "shell-route-slide-forward");
|
|
88
|
+
|
|
89
|
+
route.path = "/away";
|
|
90
|
+
assert.equal(result.routeTransitionName.value, "");
|
|
91
|
+
assert.equal(result.routeTransitionKey.value, "surface:home");
|
|
92
|
+
app.unmount();
|
|
93
|
+
});
|
|
94
|
+
|
|
95
|
+
test("wide layouts keep the pane still and never start a swipe", (t) => {
|
|
96
|
+
const { app, page, pushes, result, route } = mountTransition(t, { displayName: "lg" });
|
|
97
|
+
assert.equal(page.classes.has("shell-route-swipe-enabled"), false);
|
|
98
|
+
|
|
99
|
+
page.dispatch("pointerdown", { ...touch, clientX: 300, clientY: 100 });
|
|
100
|
+
page.dispatch("pointermove", { ...touch, clientX: 200, clientY: 102 });
|
|
101
|
+
assert.deepEqual(pushes, []);
|
|
102
|
+
|
|
103
|
+
route.path = "/home/bookings";
|
|
104
|
+
assert.equal(result.routeTransitionName.value, "");
|
|
105
|
+
assert.equal(result.routeTransitionKey.value, "surface:home");
|
|
106
|
+
app.unmount();
|
|
107
|
+
});
|
|
108
|
+
|
|
109
|
+
test("a swipe from an interactive control or with swipes off does nothing", (t) => {
|
|
110
|
+
const off = mountTransition(t, { props: { swipeEnabled: false } });
|
|
111
|
+
assert.equal(off.page.classes.has("shell-route-swipe-enabled"), false);
|
|
112
|
+
off.app.unmount();
|
|
113
|
+
|
|
114
|
+
const { app, page, pushes } = mountTransition(t);
|
|
115
|
+
page.dispatch("pointerdown", { ...touch, clientX: 300, clientY: 100, target: { closest: () => ({}) } });
|
|
116
|
+
page.dispatch("pointermove", { ...touch, clientX: 200, clientY: 102 });
|
|
117
|
+
assert.deepEqual(pushes, []);
|
|
118
|
+
app.unmount();
|
|
119
|
+
});
|
|
120
|
+
|
|
121
|
+
test("unmounting removes the swipe listeners and the page class", (t) => {
|
|
122
|
+
const { app, page } = mountTransition(t);
|
|
123
|
+
assert.equal(page.listeners.size, 4);
|
|
124
|
+
|
|
125
|
+
app.unmount();
|
|
126
|
+
|
|
127
|
+
assert.equal(page.listeners.size, 0);
|
|
128
|
+
assert.equal(page.classes.has("shell-route-swipe-enabled"), false);
|
|
129
|
+
});
|