@celestia-island/hikari 0.55.441 → 0.55.445
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 +1 -1
- package/src/components/HkAdminHeader.tsx +12 -14
- package/src/components/HkAdminShell.tsx +9 -3
- package/src/components/HkAvatar.test.tsx +107 -0
- package/src/components/HkAvatar.tsx +8 -2
- package/src/components/HkAvatarButton.test.tsx +69 -0
- package/src/components/HkAvatarButton.tsx +7 -10
- package/src/components/HkDebugFloat.scss +21 -0
- package/src/components/HkDebugFloat.test.tsx +95 -0
- package/src/components/HkDebugFloat.tsx +54 -12
- package/src/components/HkDeleteGateWindow.test.ts +22 -9
- package/src/components/HkMenuIdentityItem.test.tsx +88 -0
- package/src/components/HkMenuIdentityItem.tsx +11 -2
- package/src/components/HkThemeToggle.test.ts +5 -2
- package/src/components/avatarImage.ts +50 -0
- package/src/composables/useActionBar.test.ts +303 -0
- package/src/composables/useActionBar.ts +164 -21
- package/src/index.ts +2 -2
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
import { afterEach, describe, expect, it } from "vitest";
|
|
2
|
+
import { createApp, defineComponent, h, nextTick, ref } from "vue";
|
|
3
|
+
|
|
4
|
+
import HkMenuIdentityItem from "./HkMenuIdentityItem";
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* HkMenuIdentityItem — the standard menu identity row.
|
|
8
|
+
*
|
|
9
|
+
* Same 2026-11-20 rule as HkAvatar: a stored avatar URL that 404s must fall
|
|
10
|
+
* back to the initial-letter chip, never to the browser's broken-picture
|
|
11
|
+
* glyph, and a new URL on the same instance must retry.
|
|
12
|
+
*/
|
|
13
|
+
|
|
14
|
+
const mounts: Array<{ app: ReturnType<typeof createApp>; container: HTMLElement }> = [];
|
|
15
|
+
|
|
16
|
+
function mount(node: ReturnType<typeof h>) {
|
|
17
|
+
const container = document.createElement("div");
|
|
18
|
+
document.body.appendChild(container);
|
|
19
|
+
const app = createApp({ render: () => node });
|
|
20
|
+
app.mount(container);
|
|
21
|
+
mounts.push({ app, container });
|
|
22
|
+
return container;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
afterEach(() => {
|
|
26
|
+
for (const { app, container } of mounts.splice(0)) {
|
|
27
|
+
app.unmount();
|
|
28
|
+
container.remove();
|
|
29
|
+
}
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
describe("HkMenuIdentityItem", () => {
|
|
33
|
+
it("renders the initial fallback when no avatar URL is given", () => {
|
|
34
|
+
const c = mount(h(HkMenuIdentityItem, { name: "yuzu", subtitle: "y@zu" }));
|
|
35
|
+
expect(c.querySelector(".hk-menu-identity-item__fallback")?.textContent).toBe("Y");
|
|
36
|
+
expect(c.querySelector("img")).toBeNull();
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
it("swaps a broken avatar for the initial fallback", async () => {
|
|
40
|
+
const c = mount(h(HkMenuIdentityItem, {
|
|
41
|
+
name: "yuzu",
|
|
42
|
+
subtitle: "y@zu",
|
|
43
|
+
avatarUrl: "/static/avatars/gone.webp",
|
|
44
|
+
}));
|
|
45
|
+
const img = c.querySelector("img") as HTMLImageElement;
|
|
46
|
+
expect(img).toBeTruthy();
|
|
47
|
+
img.dispatchEvent(new Event("error"));
|
|
48
|
+
await nextTick();
|
|
49
|
+
expect(c.querySelector("img")).toBeNull();
|
|
50
|
+
expect(c.querySelector(".hk-menu-identity-item__fallback")?.textContent).toBe("Y");
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
it("renders the NORMALIZED url, not the raw prop", () => {
|
|
54
|
+
// Pins the BINDING, not just the decision (R3 mutation C): a padded
|
|
55
|
+
// URL must reach the <img> trimmed. A revert to the raw prop renders
|
|
56
|
+
// ` /a.webp ` in the src attribute and fails this test (a
|
|
57
|
+
// whitespace-ONLY input cannot discriminate — the guard hides the img
|
|
58
|
+
// in both implementations).
|
|
59
|
+
const c = mount(h(HkMenuIdentityItem, { name: "yuzu", avatarUrl: " /a.webp " }));
|
|
60
|
+
const img = c.querySelector("img.hk-menu-identity-item__img") as HTMLImageElement | null;
|
|
61
|
+
expect(img).toBeTruthy();
|
|
62
|
+
expect(img!.getAttribute("src")).toBe("/a.webp");
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
it("treats a whitespace-only avatarUrl as absent — the <img> never mounts", () => {
|
|
66
|
+
const c = mount(h(HkMenuIdentityItem, { name: "yuzu", avatarUrl: " " }));
|
|
67
|
+
expect(c.querySelector("img.hk-menu-identity-item__img")).toBeNull();
|
|
68
|
+
expect(c.querySelector(".hk-menu-identity-item__fallback")?.textContent).toBe("Y");
|
|
69
|
+
});
|
|
70
|
+
|
|
71
|
+
it("retries when the avatar URL changes on the same instance", async () => {
|
|
72
|
+
const url = ref("/a.webp");
|
|
73
|
+
const Host = defineComponent({
|
|
74
|
+
setup: () => () => h(HkMenuIdentityItem, { name: "yuzu", avatarUrl: url.value }),
|
|
75
|
+
});
|
|
76
|
+
const c = mount(h(Host));
|
|
77
|
+
(c.querySelector("img") as HTMLImageElement).dispatchEvent(new Event("error"));
|
|
78
|
+
await nextTick();
|
|
79
|
+
expect(c.querySelector("img")).toBeNull();
|
|
80
|
+
|
|
81
|
+
url.value = "/b.webp";
|
|
82
|
+
await nextTick();
|
|
83
|
+
await nextTick();
|
|
84
|
+
const retry = c.querySelector("img") as HTMLImageElement | null;
|
|
85
|
+
expect(retry, "the latch reset — the new URL gets a fresh attempt").toBeTruthy();
|
|
86
|
+
expect(retry!.getAttribute("src")).toBe("/b.webp");
|
|
87
|
+
});
|
|
88
|
+
});
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { defineComponent } from "vue";
|
|
2
|
+
import { useAvatarImage } from "./avatarImage";
|
|
2
3
|
import "./HkMenuIdentityItem.scss";
|
|
3
4
|
|
|
4
5
|
/**
|
|
@@ -18,11 +19,19 @@ export default defineComponent({
|
|
|
18
19
|
avatarAlt: { type: String, default: "" },
|
|
19
20
|
},
|
|
20
21
|
setup(props, { slots }) {
|
|
22
|
+
// Same failed-load latch as HkAvatar: a stored URL that 404s must not
|
|
23
|
+
// leave the browser's broken-picture glyph in the menu header.
|
|
24
|
+
const avatar = useAvatarImage(() => props.avatarUrl);
|
|
21
25
|
return () => (
|
|
22
26
|
<div class="hk-menu-identity-item" role="presentation">
|
|
23
27
|
<div class="hk-menu-identity-item__avatar" aria-hidden="true">
|
|
24
|
-
{
|
|
25
|
-
<img
|
|
28
|
+
{avatar.src.value ? (
|
|
29
|
+
<img
|
|
30
|
+
src={avatar.src.value}
|
|
31
|
+
alt={props.avatarAlt || props.name}
|
|
32
|
+
class="hk-menu-identity-item__img"
|
|
33
|
+
onError={avatar.onError}
|
|
34
|
+
/>
|
|
26
35
|
) : (
|
|
27
36
|
<span class="hk-menu-identity-item__fallback">
|
|
28
37
|
{(props.name || "?").charAt(0).toUpperCase()}
|
|
@@ -230,9 +230,12 @@ describe("HkThemeToggle color-mode group", () => {
|
|
|
230
230
|
expect(cell!.parentElement!.getAttribute("data-slots")).toBe("");
|
|
231
231
|
expect(document.body.querySelector(".hk-tabs-overlay")).toBeNull();
|
|
232
232
|
// The merged Light/Dark triggers leave the radio order entirely —
|
|
233
|
-
// the strip is the single pointer surface while auto is active.
|
|
233
|
+
// the strip is the single pointer surface while auto is active. The
|
|
234
|
+
// swap commits after the transition settles; poll instead of trusting
|
|
235
|
+
// one fixed sleep window (a loaded CI runner still saw the old
|
|
236
|
+
// three-way order when the merge had not landed yet).
|
|
237
|
+
await vi.waitFor(() => expect(modeSegments()).toHaveLength(1));
|
|
234
238
|
const segments = modeSegments();
|
|
235
|
-
expect(segments).toHaveLength(1);
|
|
236
239
|
expect(segments[0].textContent).toContain("Auto");
|
|
237
240
|
expect(segments[0].getAttribute("aria-checked")).toBe("true");
|
|
238
241
|
});
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
// ------
|
|
2
|
+
// Shared avatar image state
|
|
3
|
+
// ------
|
|
4
|
+
//
|
|
5
|
+
// ONE failed-load latch for every avatar surface in the library. An
|
|
6
|
+
// `<img>` that 404s renders the browser's broken-picture glyph — the exact
|
|
7
|
+
// "missing image" look 2026-11-20 user report called out for the workspace
|
|
8
|
+
// roster (demiurge's `/static/avatars/…` blob had gone stale; the component
|
|
9
|
+
// kept the broken image instead of its own letter chip). A stored avatar URL
|
|
10
|
+
// can always 404 (deleted upload, external provider unreachable, mirror cache
|
|
11
|
+
// cold), so "the URL exists" is not "there is an avatar": every face must
|
|
12
|
+
// degrade to the SAME letter fallback it renders when the URL is absent.
|
|
13
|
+
//
|
|
14
|
+
// The latch is per-URL: a new `src` (account switch, avatar re-upload) gets a
|
|
15
|
+
// fresh attempt, or one broken URL would poison the chip for the rest of the
|
|
16
|
+
// component's life. Same contract as HkAvatarButton's hand-rolled latch
|
|
17
|
+
// (2026-10-29), now shared so the four call sites cannot drift (HkAvatar,
|
|
18
|
+
// HkAvatarButton, HkMenuIdentityItem, HkAdminHeader's dropdown image).
|
|
19
|
+
|
|
20
|
+
import { computed, ref, watch, type ComputedRef } from "vue";
|
|
21
|
+
|
|
22
|
+
/** `src` getter — pass the component prop, e.g. `() => props.src`. */
|
|
23
|
+
export interface AvatarImageState {
|
|
24
|
+
/** The URL to render, or "" when the letter fallback must show instead. */
|
|
25
|
+
src: ComputedRef<string>;
|
|
26
|
+
/** Wire to the `<img @error>` binding. */
|
|
27
|
+
onError: () => void;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/** Failed-load latch shared by HkAvatar / HkAvatarButton / HkMenuIdentityItem /
|
|
31
|
+
* HkAdminHeader's dropdown identity image. */
|
|
32
|
+
export function useAvatarImage(source: () => string | undefined): AvatarImageState {
|
|
33
|
+
const failed = ref(false);
|
|
34
|
+
// A new URL deserves a fresh attempt: reset on every source change. The
|
|
35
|
+
// getter makes this work for prop-driven updates on the same instance
|
|
36
|
+
// (a remount would restart unlatched anyway and prove nothing).
|
|
37
|
+
watch(source, () => {
|
|
38
|
+
failed.value = false;
|
|
39
|
+
});
|
|
40
|
+
const src = computed(() => {
|
|
41
|
+
const url = (source() ?? "").trim();
|
|
42
|
+
return url && !failed.value ? url : "";
|
|
43
|
+
});
|
|
44
|
+
return {
|
|
45
|
+
src,
|
|
46
|
+
onError: () => {
|
|
47
|
+
failed.value = true;
|
|
48
|
+
},
|
|
49
|
+
};
|
|
50
|
+
}
|
|
@@ -0,0 +1,303 @@
|
|
|
1
|
+
import { createApp, defineComponent, h, nextTick, ref } from "vue";
|
|
2
|
+
import { afterEach, describe, expect, it } from "vitest";
|
|
3
|
+
|
|
4
|
+
import {
|
|
5
|
+
orderActionRegistrations,
|
|
6
|
+
PageActionSlot,
|
|
7
|
+
provideActionBar,
|
|
8
|
+
useActionBar,
|
|
9
|
+
type ActionBarRegistration,
|
|
10
|
+
} from "./useActionBar";
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* The unified action bar's registration contract, exercised through real
|
|
14
|
+
* mounts (no mock of the module under test; repo convention: raw
|
|
15
|
+
* createApp + container queries, no @vue/test-utils dependency):
|
|
16
|
+
* - a descendant's setActions/setCenter render into the layout's slots;
|
|
17
|
+
* - the registration is per-component-scope — unmounting the registering
|
|
18
|
+
* view clears its registrations so a stale page's refresh button or
|
|
19
|
+
* filter group can never linger under the next page (the property the
|
|
20
|
+
* whole header-chrome design leans on);
|
|
21
|
+
* - canonical slots render by rank regardless of registration order;
|
|
22
|
+
* customs stuff right-to-left (first-registered = rightmost);
|
|
23
|
+
* - the identity guard keeps a leaving view's dispose from wiping the
|
|
24
|
+
* entering view's chrome (the crossfade instant).
|
|
25
|
+
*/
|
|
26
|
+
|
|
27
|
+
const mounts: Array<{ app: ReturnType<typeof createApp>; container: HTMLElement }> = [];
|
|
28
|
+
|
|
29
|
+
function mountApp(content: () => unknown) {
|
|
30
|
+
const container = document.createElement("div");
|
|
31
|
+
document.body.appendChild(container);
|
|
32
|
+
const app = createApp({ setup: () => content });
|
|
33
|
+
app.mount(container);
|
|
34
|
+
mounts.push({ app, container });
|
|
35
|
+
return container;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
afterEach(() => {
|
|
39
|
+
for (const { app, container } of mounts.splice(0)) {
|
|
40
|
+
app.unmount();
|
|
41
|
+
container.remove();
|
|
42
|
+
}
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
function makeView(tag: string, slot: string) {
|
|
46
|
+
return defineComponent({
|
|
47
|
+
name: `View-${tag}`,
|
|
48
|
+
setup() {
|
|
49
|
+
const bar = useActionBar();
|
|
50
|
+
bar.setActions(() => [h("button", { class: `reg-action reg-${tag}` }, tag)], slot);
|
|
51
|
+
return () => h("div", { class: `view-body view-${tag}` }, "view");
|
|
52
|
+
},
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
function makeCenterView(tag: string) {
|
|
57
|
+
return defineComponent({
|
|
58
|
+
name: `CenterView-${tag}`,
|
|
59
|
+
setup() {
|
|
60
|
+
const bar = useActionBar();
|
|
61
|
+
bar.setCenter(() => [h("nav", { class: `reg-center reg-center-${tag}` }, tag)]);
|
|
62
|
+
return () => h("div", { class: `view-body view-${tag}` }, "view");
|
|
63
|
+
},
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
function makeLayout(views: () => unknown[]) {
|
|
68
|
+
return defineComponent({
|
|
69
|
+
name: "Layout",
|
|
70
|
+
setup() {
|
|
71
|
+
const bar = provideActionBar();
|
|
72
|
+
return () => [
|
|
73
|
+
h("div", { class: "layout-actions" }, bar.actions.value.flatMap((r) => r())),
|
|
74
|
+
views(),
|
|
75
|
+
h("div", { class: "layout-center" }, bar.center.value?.() ?? []),
|
|
76
|
+
];
|
|
77
|
+
},
|
|
78
|
+
});
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
async function mountWithViews(views: () => unknown[]) {
|
|
82
|
+
const container = mountApp(() => h(makeLayout(views)));
|
|
83
|
+
await nextTick();
|
|
84
|
+
return container;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
function registeredButtons(container: HTMLElement): string[] {
|
|
88
|
+
return Array.from(container.querySelectorAll<HTMLElement>(".layout-actions .reg-action")).map(
|
|
89
|
+
(b) => b.textContent ?? "",
|
|
90
|
+
);
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
describe("useActionBar", () => {
|
|
94
|
+
it("renders a descendant's registered actions and centre group", async () => {
|
|
95
|
+
// Built ONCE outside the render fn — a component created per render
|
|
96
|
+
// remounts (and re-registers) on every layout update, the infinite
|
|
97
|
+
// register/update loop, not the contract under test.
|
|
98
|
+
const view = makeView("refresh", PageActionSlot.Refresh);
|
|
99
|
+
const centerView = makeCenterView("filter");
|
|
100
|
+
const container = await mountWithViews(() => [h(view), h(centerView)]);
|
|
101
|
+
expect(container.querySelector(".layout-actions .reg-action")?.textContent).toBe("refresh");
|
|
102
|
+
expect(container.querySelector(".layout-center .reg-center")?.textContent).toBe("filter");
|
|
103
|
+
// The view body renders too — the probes mirror, never replace.
|
|
104
|
+
expect(container.querySelector(".view-body")).not.toBeNull();
|
|
105
|
+
});
|
|
106
|
+
|
|
107
|
+
it("leaves both slots empty when the view registers nothing", async () => {
|
|
108
|
+
const bare = defineComponent({
|
|
109
|
+
name: "BareView",
|
|
110
|
+
setup: () => () => h("div", { class: "view-body" }, "view"),
|
|
111
|
+
});
|
|
112
|
+
const container = await mountWithViews(() => [h(bare)]);
|
|
113
|
+
expect(container.querySelector(".layout-actions .reg-action")).toBeNull();
|
|
114
|
+
expect(container.querySelector(".layout-center .reg-center")).toBeNull();
|
|
115
|
+
});
|
|
116
|
+
|
|
117
|
+
it("clears the registrations when the registering view unmounts", async () => {
|
|
118
|
+
const show = ref(true);
|
|
119
|
+
// Built ONCE outside the render fn: a component created per render
|
|
120
|
+
// would remount (and re-register) on every layout update — an
|
|
121
|
+
// infinite register/update loop, not the contract under test.
|
|
122
|
+
const view = makeView("refresh", PageActionSlot.Refresh);
|
|
123
|
+
const centerView = makeCenterView("filter");
|
|
124
|
+
const container = await mountWithViews(() =>
|
|
125
|
+
show.value ? [h(view), h(centerView)] : [],
|
|
126
|
+
);
|
|
127
|
+
expect(container.querySelector(".layout-actions .reg-action")).not.toBeNull();
|
|
128
|
+
expect(container.querySelector(".layout-center .reg-center")).not.toBeNull();
|
|
129
|
+
|
|
130
|
+
// The page switches: the view unmounts and its chrome must go with
|
|
131
|
+
// it — both slots, not just the actions.
|
|
132
|
+
show.value = false;
|
|
133
|
+
await nextTick();
|
|
134
|
+
expect(container.querySelector(".layout-actions .reg-action")).toBeNull();
|
|
135
|
+
expect(container.querySelector(".layout-center .reg-center")).toBeNull();
|
|
136
|
+
});
|
|
137
|
+
|
|
138
|
+
it("renders one page's several affordances in SLOT order, not call order", async () => {
|
|
139
|
+
// The composition contract: a page registering its filter trigger
|
|
140
|
+
// and then its refresh gets [filter][refresh] left-to-right — and
|
|
141
|
+
// one that registers refresh first and create last still gets the
|
|
142
|
+
// canonical rank order [create][filter][refresh].
|
|
143
|
+
const view = defineComponent({
|
|
144
|
+
name: "DualView",
|
|
145
|
+
setup() {
|
|
146
|
+
const bar = useActionBar();
|
|
147
|
+
bar.setActions(
|
|
148
|
+
() => [h("button", { class: "reg-action reg-filter" }, "filter")],
|
|
149
|
+
PageActionSlot.Filter,
|
|
150
|
+
);
|
|
151
|
+
bar.setActions(
|
|
152
|
+
() => [h("button", { class: "reg-action reg-refresh" }, "refresh")],
|
|
153
|
+
PageActionSlot.Refresh,
|
|
154
|
+
);
|
|
155
|
+
return () => h("div", { class: "view-body" }, "view");
|
|
156
|
+
},
|
|
157
|
+
});
|
|
158
|
+
const container = await mountWithViews(() => [h(view)]);
|
|
159
|
+
expect(registeredButtons(container)).toEqual(["filter", "refresh"]);
|
|
160
|
+
});
|
|
161
|
+
|
|
162
|
+
it("places a late-registered create LEFTMOST (rank beats call order)", async () => {
|
|
163
|
+
const view = defineComponent({
|
|
164
|
+
name: "LateCreateView",
|
|
165
|
+
setup() {
|
|
166
|
+
const bar = useActionBar();
|
|
167
|
+
bar.setActions(
|
|
168
|
+
() => [h("button", { class: "reg-action reg-refresh" }, "refresh")],
|
|
169
|
+
PageActionSlot.Refresh,
|
|
170
|
+
);
|
|
171
|
+
bar.setActions(
|
|
172
|
+
() => [h("button", { class: "reg-action reg-create" }, "create")],
|
|
173
|
+
PageActionSlot.Create,
|
|
174
|
+
);
|
|
175
|
+
return () => h("div", { class: "view-body" }, "view");
|
|
176
|
+
},
|
|
177
|
+
});
|
|
178
|
+
const container = await mountWithViews(() => [h(view)]);
|
|
179
|
+
expect(registeredButtons(container)).toEqual(["create", "refresh"]);
|
|
180
|
+
});
|
|
181
|
+
|
|
182
|
+
it("is a silent no-op outside any layout provider", async () => {
|
|
183
|
+
// Views render in tests (and anywhere without a layout) without a
|
|
184
|
+
// provider: registering must neither throw nor render anything.
|
|
185
|
+
const container = mountApp(() => h(makeView("refresh", PageActionSlot.Refresh)));
|
|
186
|
+
await nextTick();
|
|
187
|
+
expect(container.querySelector(".reg-action")).toBeNull();
|
|
188
|
+
expect(container.querySelector(".view-body")).not.toBeNull();
|
|
189
|
+
});
|
|
190
|
+
|
|
191
|
+
it("keeps the SURVIVING registration when an overlapped view unmounts (identity guard)", async () => {
|
|
192
|
+
// The crossfade property the whole header design leans on: during a
|
|
193
|
+
// page transition the entering and leaving views are alive at the
|
|
194
|
+
// same instant, so the entering view registers OVER the leaving one
|
|
195
|
+
// and then the leaving one disposes. The per-scope clear must fire
|
|
196
|
+
// only for ITS OWN renderer — an unconditional clear would wipe the
|
|
197
|
+
// entering page's chrome the moment the leaving view unmounts.
|
|
198
|
+
const showA = ref(true);
|
|
199
|
+
const showB = ref(true);
|
|
200
|
+
const viewA = makeView("a", "custom");
|
|
201
|
+
const viewB = makeView("b", "custom");
|
|
202
|
+
const container = await mountWithViews(() => [
|
|
203
|
+
showA.value ? h(viewA) : null,
|
|
204
|
+
showB.value ? h(viewB) : null,
|
|
205
|
+
]);
|
|
206
|
+
// Both alive (the crossfade instant): registrations are ADDITIVE —
|
|
207
|
+
// both pages' buttons render. Both declare the CUSTOM slot, so the
|
|
208
|
+
// stuffing rule orders them right-to-left: first-registered (a) is
|
|
209
|
+
// RIGHTMOST → visual order [b, a].
|
|
210
|
+
expect(registeredButtons(container)).toEqual(["b", "a"]);
|
|
211
|
+
|
|
212
|
+
// The LEAVING view (a — registered first) unmounts after b took
|
|
213
|
+
// over: b's chrome must survive a's disposal (the identity guard —
|
|
214
|
+
// an unconditional clear here wipes the entering page's header).
|
|
215
|
+
showA.value = false;
|
|
216
|
+
await nextTick();
|
|
217
|
+
expect(registeredButtons(container)).toEqual(["b"]);
|
|
218
|
+
|
|
219
|
+
// Then b leaves too: only now does the slot go empty.
|
|
220
|
+
showB.value = false;
|
|
221
|
+
await nextTick();
|
|
222
|
+
expect(registeredButtons(container)).toEqual([]);
|
|
223
|
+
});
|
|
224
|
+
|
|
225
|
+
it("keeps the SURVIVING centre when an overlapped view unmounts (centre identity guard)", async () => {
|
|
226
|
+
// setCenter's dispose must clear only when ITS OWN renderer is
|
|
227
|
+
// still the current one — a later view's centre must survive the
|
|
228
|
+
// earlier view's unmount.
|
|
229
|
+
const showA = ref(true);
|
|
230
|
+
const showB = ref(true);
|
|
231
|
+
const centerA = makeCenterView("a");
|
|
232
|
+
const centerB = makeCenterView("b");
|
|
233
|
+
const container = await mountWithViews(() => [
|
|
234
|
+
showA.value ? h(centerA) : null,
|
|
235
|
+
showB.value ? h(centerB) : null,
|
|
236
|
+
]);
|
|
237
|
+
// B registered last — B owns the centre slot now.
|
|
238
|
+
expect(container.querySelector(".layout-center .reg-center")?.textContent).toBe("b");
|
|
239
|
+
|
|
240
|
+
showA.value = false;
|
|
241
|
+
await nextTick();
|
|
242
|
+
expect(container.querySelector(".layout-center .reg-center")?.textContent).toBe("b");
|
|
243
|
+
|
|
244
|
+
showB.value = false;
|
|
245
|
+
await nextTick();
|
|
246
|
+
expect(container.querySelector(".layout-center .reg-center")).toBeNull();
|
|
247
|
+
});
|
|
248
|
+
});
|
|
249
|
+
|
|
250
|
+
describe("orderActionRegistrations (slot ranks + right-to-left customs)", () => {
|
|
251
|
+
function reg(slot: string, seq: number): ActionBarRegistration {
|
|
252
|
+
return { renderer: () => [], slot, seq };
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
it("orders the canonical slots by rank regardless of registration order", () => {
|
|
256
|
+
const out = orderActionRegistrations([
|
|
257
|
+
reg("refresh", 0),
|
|
258
|
+
reg("custom-x", 1),
|
|
259
|
+
reg("filter", 2),
|
|
260
|
+
reg("create", 3),
|
|
261
|
+
]);
|
|
262
|
+
expect(out.map((r) => r.slot)).toEqual(["create", "filter", "refresh", "custom-x"]);
|
|
263
|
+
});
|
|
264
|
+
|
|
265
|
+
it("ranks the window slot right of the refresh, left of customs", () => {
|
|
266
|
+
// The secondary-window opener is canonical:
|
|
267
|
+
// [create][filter][search][refresh][window] — regardless of the
|
|
268
|
+
// order the page registered them in.
|
|
269
|
+
const out = orderActionRegistrations([
|
|
270
|
+
reg("window", 0),
|
|
271
|
+
reg("refresh", 1),
|
|
272
|
+
reg("search", 2),
|
|
273
|
+
reg("custom-x", 3),
|
|
274
|
+
reg("filter", 4),
|
|
275
|
+
reg("create", 5),
|
|
276
|
+
]);
|
|
277
|
+
expect(out.map((r) => r.slot)).toEqual([
|
|
278
|
+
"create",
|
|
279
|
+
"filter",
|
|
280
|
+
"search",
|
|
281
|
+
"refresh",
|
|
282
|
+
"window",
|
|
283
|
+
"custom-x",
|
|
284
|
+
]);
|
|
285
|
+
});
|
|
286
|
+
|
|
287
|
+
it("stuffs customs right-to-left: the FIRST-registered custom is rightmost", () => {
|
|
288
|
+
// The customs zone grows LEFTWARD (user rule 2026-10-11): the right
|
|
289
|
+
// edge takes the first arrival, later customs land to its left.
|
|
290
|
+
const out = orderActionRegistrations([
|
|
291
|
+
reg("create", 0),
|
|
292
|
+
reg("first", 1),
|
|
293
|
+
reg("second", 2),
|
|
294
|
+
reg("third", 3),
|
|
295
|
+
]);
|
|
296
|
+
expect(out.map((r) => r.slot)).toEqual(["create", "third", "second", "first"]);
|
|
297
|
+
});
|
|
298
|
+
|
|
299
|
+
it("keeps same-slot registrations stable by sequence", () => {
|
|
300
|
+
const out = orderActionRegistrations([reg("create", 5), reg("create", 2)]);
|
|
301
|
+
expect(out.map((r) => r.seq)).toEqual([2, 5]);
|
|
302
|
+
});
|
|
303
|
+
});
|