mirror of
https://github.com/EchoSixHIYA/WebSpeak-client-for-TeamSpeak.git
synced 2026-12-03 12:02:50 +08:00
test(skins): verify editor focus restoration
This commit is contained in:
1 parent
16f28ca348
commit
100a8f49ee
1 file changed
+8
-1
@@ -12,6 +12,7 @@ import vuePlugin from "@vitejs/plugin-vue";
|
|||||||
let vite;
|
let vite;
|
||||||
let SkinPluginEditor;
|
let SkinPluginEditor;
|
||||||
let authoring;
|
let authoring;
|
||||||
|
let focusedNode;
|
||||||
const localStorageDescriptor = Object.getOwnPropertyDescriptor(globalThis, "localStorage");
|
const localStorageDescriptor = Object.getOwnPropertyDescriptor(globalThis, "localStorage");
|
||||||
|
|
||||||
class MemoryStorage {
|
class MemoryStorage {
|
||||||
@@ -22,7 +23,7 @@ class MemoryStorage {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const hostNode = (tag, type = "element") => ({
|
const hostNode = (tag, type = "element") => ({
|
||||||
tag, type, props: {}, text: "", children: [], parent: null, value: "", listeners: new Map(), focus() {},
|
tag, type, props: {}, text: "", children: [], parent: null, value: "", listeners: new Map(), focus() { focusedNode = this; },
|
||||||
addEventListener(name, listener) {
|
addEventListener(name, listener) {
|
||||||
const listeners = this.listeners.get(name) ?? [];
|
const listeners = this.listeners.get(name) ?? [];
|
||||||
listeners.push(listener);
|
listeners.push(listener);
|
||||||
@@ -156,6 +157,7 @@ after(async () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
test("component editor creates, changes, and deletes a skin component tree through its UI", async () => {
|
test("component editor creates, changes, and deletes a skin component tree through its UI", async () => {
|
||||||
|
focusedNode = null;
|
||||||
Object.defineProperty(globalThis, "localStorage", { configurable: true, value: new MemoryStorage() });
|
Object.defineProperty(globalThis, "localStorage", { configurable: true, value: new MemoryStorage() });
|
||||||
const baseDocument = {
|
const baseDocument = {
|
||||||
schemaVersion: 3,
|
schemaVersion: 3,
|
||||||
@@ -187,7 +189,10 @@ test("component editor creates, changes, and deletes a skin component tree throu
|
|||||||
try {
|
try {
|
||||||
clickButton(root, "组件结构");
|
clickButton(root, "组件结构");
|
||||||
await nextTick();
|
await nextTick();
|
||||||
|
await nextTick();
|
||||||
assert.equal(app._instance.setupState.open, true, "the trigger opens the editor");
|
assert.equal(app._instance.setupState.open, true, "the trigger opens the editor");
|
||||||
|
assert.equal(focusedNode?.props["aria-label"], "关闭", "opening moves keyboard focus to the close control");
|
||||||
|
assert.equal(visit(root, node => node.tag === "button" && nodeText(node).trim() === "组件结构")?.props["aria-expanded"], true);
|
||||||
clickButton(root, "新增组件");
|
clickButton(root, "新增组件");
|
||||||
await nextTick();
|
await nextTick();
|
||||||
const key = authoring.getSkinPluginAuthoringStorageKey("community.example", "1.0.0");
|
const key = authoring.getSkinPluginAuthoringStorageKey("community.example", "1.0.0");
|
||||||
@@ -275,8 +280,10 @@ test("component editor creates, changes, and deletes a skin component tree throu
|
|||||||
assert.equal(panel.props["aria-modal"], "false");
|
assert.equal(panel.props["aria-modal"], "false");
|
||||||
panel.props.onKeydown({ key: "Escape", preventDefault() {}, stopPropagation() {} });
|
panel.props.onKeydown({ key: "Escape", preventDefault() {}, stopPropagation() {} });
|
||||||
await nextTick();
|
await nextTick();
|
||||||
|
await nextTick();
|
||||||
assert.equal(visit(root, node => node.tag === "section" && node.props.role === "dialog"), null,
|
assert.equal(visit(root, node => node.tag === "section" && node.props.role === "dialog"), null,
|
||||||
"Escape closes the editor dialog");
|
"Escape closes the editor dialog");
|
||||||
|
assert.equal(nodeText(focusedNode), "组件结构", "closing returns keyboard focus to the trigger");
|
||||||
} finally {
|
} finally {
|
||||||
app.unmount();
|
app.unmount();
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in new issue
Block a user