fix(web): 任务中心 - 资源失效时显示预览占位 (#286)

This commit is contained in:
MasterChiefCN
2026-08-21 13:26:27 +08:00
committed by GitHub
parent 8be5334d9c
commit 38f596e28a
7 changed files with 138 additions and 21 deletions

View File

@@ -0,0 +1,29 @@
import { describe, expect, test } from "bun:test";
import { readFileSync } from "node:fs";
import { resolve } from "node:path";
function source(path: string) {
return readFileSync(resolve(import.meta.dir, path), "utf8");
}
describe("task media fallback", () => {
test("replaces failed image and video elements with an unavailable state", () => {
const preview = source("../src/pages/tasks/task-media-preview.tsx");
expect(preview).toContain("failedSrc === src");
expect(preview).toContain("onError={handleUnavailable}");
expect(preview).toContain("预览不可用,素材可能已删除");
expect(preview).toContain("<ImageOff");
});
test("uses the fallback in list, grid, detail and enlarged previews", () => {
const list = source("../src/pages/tasks/task-list-row.tsx");
const grid = source("../src/pages/tasks/task-grid-card.tsx");
const page = source("../src/pages/tasks/index.tsx");
expect(list).toContain("<TaskMediaPreview");
expect(list).toContain("disabled={previewUnavailable}");
expect(grid).toContain("<TaskMediaPreview");
expect(page.match(/<TaskMediaPreview/g)).toHaveLength(2);
});
});