import { describe, expect, it } from "vitest"; import { readFileSync } from "node:fs"; import { resolve } from "node:path"; const source = readFileSync(resolve(__dirname, "./OfficePreviewWorkspace.vue"), "utf8"); const hostSource = readFileSync(resolve(__dirname, "../components/OnlyOfficeViewer.vue"), "utf8"); describe("OfficePreviewWorkspace contract", () => { it("uses a full-page viewer without dialogs, cards, downloads, or browser iframe fallback", () => { expect(source).toContain("OnlyOfficeViewer"); expect(source).not.toContain("el-dialog"); expect(source).not.toContain("downloadDocumentVersion"); expect(source).not.toContain("downloadAttachment"); expect(source).not.toContain(" { expect(source).toContain("onDeactivated"); expect(source).toContain("DESKTOP_SERVER_URL_CHANGED_EVENT"); expect(source.match(/destroyViewer\(\)/g)?.length).toBeGreaterThanOrEqual(3); expect(hostSource).toContain('frameRef.value.src = "about:blank"'); }); it("closes a desktop transient preview task before falling back to browser history", () => { expect(source).toContain("inject(workspaceTaskControllerKey, null)"); expect(source).toContain("workspaceTaskController?.closeTransientTask(route.path)"); expect(source).toContain('workspaceTaskController ? "关闭预览并返回" : "返回"'); expect(source).toContain("router.back()"); }); });