From fd4b0c6da23d5abd38af627defb7d1f142bd1e02 Mon Sep 17 00:00:00 2001 From: illusia <64828020+EchoSixHIYA@users.noreply.github.com> Date: Sat, 10 Oct 2026 12:18:04 +0800 Subject: [PATCH] test(skins): verify live component CRUD preview --- docs/OPEN_SKIN_SYSTEM_ROADMAP.zh-CN.md | 2 +- web/test/skin-plugin-editor.test.mjs | 70 ++++++++++++++++++++++++++ 2 files changed, 71 insertions(+), 1 deletion(-) diff --git a/docs/OPEN_SKIN_SYSTEM_ROADMAP.zh-CN.md b/docs/OPEN_SKIN_SYSTEM_ROADMAP.zh-CN.md index 61404ef..853e261 100644 --- a/docs/OPEN_SKIN_SYSTEM_ROADMAP.zh-CN.md +++ b/docs/OPEN_SKIN_SYSTEM_ROADMAP.zh-CN.md @@ -140,7 +140,7 @@ schema v2 支持公开组件布局、桌面/平板/手机配置、本地覆盖 - 存储现按皮肤 ID 和版本分键;单份损坏数据可以单独清除并恢复原包,不影响其他皮肤。宿主保留的 data-ws-* 属性不会由作者节点写入渲染 DOM。 - 编辑器操作按钮和选择器现在保留至少 44 px 触控高度,支持 Escape 关闭并在打开/关闭时移动焦点;继续打磨窄屏布局和可理解的校验提示。组件新增权限仍由宿主按既有权限机制要求批准;删除整页 surface 后应自然回到 WebSpeak 页面和宿主恢复控件。 - 稳定门禁至少覆盖:组件/节点完整 CRUD 与撤销重做;导入导出往返;空组件文档;旧 schema v1/v2 只读兼容并在首次编辑时安全升到 v3;存储按皮肤版本隔离且坏数据可独立恢复;非法或越权文档不保存、不渲染;页面切换、皮肤切换及恢复入口不丢失。 -- 2026-10-10 的统一验证通过:619 项测试通过,服务端 TypeScript 构建、前端类型检查与 Vite 生产构建通过。这确认了自动化核心 CRUD 路径和组件素材生命周期回归,不代表作者体验、跨浏览器行为或插件安全边界已经验收。 +- 2026-10-10 的统一验证通过:620 项测试通过,服务端 TypeScript 构建、前端类型检查与 Vite 生产构建通过。编辑器到渲染出口的集成回归已证明新增、修改、删除会即时更新页面预览;这仍不代表真实窄屏作者体验、跨浏览器行为或插件安全边界已经验收。 - 当前补查发现客户端曾接受 v4 包级 `layout.json`,服务端却未读取该字段,造成同一个包本地可导入但服务端拒绝;已为校验一致性修复补充回归用例。后续只在整批修改后统一验证。 - 组件渲染器原先只按素材路径缓存 Blob URL,切换皮肤后同名图片可能沿用旧皮肤素材,旧 URL 也会一直留到卸载;现改为同时绑定 Blob,并在资源替换、皮肤切换或组件卸载时释放。对应缺失素材和换包回归已加入自动化验证。 - R5 完成门槛包括:编辑器能完整管理组件和节点;更新后页面即时预览;导入、导出、版本隔离、坏数据恢复及旧格式迁移可靠;客户端与服务端对每种包格式采用一致校验;键盘与窄屏作者流程可用;授权拒绝/撤销、恢复原生页面、插件销毁与资源回收通过针对性验证;跨浏览器动作和资源边界完成独立复核。 diff --git a/web/test/skin-plugin-editor.test.mjs b/web/test/skin-plugin-editor.test.mjs index 0c1fbb0..23918d9 100644 --- a/web/test/skin-plugin-editor.test.mjs +++ b/web/test/skin-plugin-editor.test.mjs @@ -11,6 +11,7 @@ import vuePlugin from "@vitejs/plugin-vue"; let vite; let SkinPluginEditor; +let SkinPluginOutlet; let authoring; let focusedNode; const localStorageDescriptor = Object.getOwnPropertyDescriptor(globalThis, "localStorage"); @@ -133,6 +134,7 @@ before(async () => { appType: "custom", }); ({ default: SkinPluginEditor } = await vite.ssrLoadModule("/src/components/SkinPluginEditor.vue")); + ({ default: SkinPluginOutlet } = await vite.ssrLoadModule("/src/components/SkinPluginOutlet.ts")); const require = createRequire(import.meta.url); const { parse, compileScript, compileTemplate } = require("../node_modules/@vue/compiler-sfc"); const filename = fileURLToPath(new URL("../src/components/SkinPluginEditor.vue", import.meta.url)); @@ -288,3 +290,71 @@ test("component editor creates, changes, and deletes a skin component tree throu app.unmount(); } }); + +test("component create, update, and delete immediately change the rendered skin preview", async () => { + Object.defineProperty(globalThis, "localStorage", { configurable: true, value: new MemoryStorage() }); + const skinId = "community.preview"; + const skinVersion = "1.0.0"; + const baseDocument = { schemaVersion: 3, components: [] }; + const revision = Vue.ref(0); + const props = { skinId, skinVersion, baseDocument, page: "voice", lang: "zh" }; + const preview = Vue.defineComponent({ + setup() { + const currentDocument = () => { + revision.value; + return authoring.loadSkinPluginAuthoringDocument(skinId, skinVersion) ?? baseDocument; + }; + return () => Vue.h("main", null, [ + Vue.h(SkinPluginOutlet, { + skinId, + skinVersion, + document: currentDocument(), + page: "voice", + data: {}, + assets: {}, + actions: {}, + }), + Vue.h(SkinPluginEditor, { ...props, onUpdated: () => { revision.value += 1; } }), + ]); + }, + }); + const root = hostNode("root"); + const app = renderer.createApp(preview); + app.provide(ssrContextKey, { modules: new Set() }); + app.mount(root); + + try { + clickButton(root, "组件结构"); + await nextTick(); + await nextTick(); + clickButton(root, "新增组件"); + await nextTick(); + + let rendered = visit(root, node => node.props["data-ws-plugin-component"] === "custom-component-1"); + assert.ok(rendered, "the newly created component is rendered in the page preview"); + assert.match(nodeText(rendered), /新建组件/); + + const saved = authoring.loadSkinPluginAuthoringDocument(skinId, skinVersion); + const updated = { + ...saved.components[0], + name: "Preview component", + accessibleName: "Preview component", + root: { tag: "section", children: [{ text: "预览已更新" }] }, + }; + editTextarea(root, JSON.stringify(updated, null, 2)); + await nextTick(); + clickButton(root, "应用定义"); + await nextTick(); + + rendered = visit(root, node => node.props["data-ws-plugin-component"] === "custom-component-1"); + assert.ok(rendered); + assert.match(nodeText(rendered), /预览已更新/, "applying a component definition updates the rendered preview immediately"); + + clickButton(root, "删除组件"); + await nextTick(); + assert.equal(visit(root, node => node.props["data-ws-plugin-component"] === "custom-component-1"), null, + "deleting the component removes it from the rendered page preview"); + } finally { + app.unmount(); + } +});