Spot it. Save it. Free, local-first Chrome extension for images, videos and prompts. Explore 2,000+ curated cases and connect your library to AI Agents via MCP. 提示词导演
JavaScript ai-artai-videochrome-extensionclaude-codecodexhiggsfieldjimenglocal-firstmcpmidjourneymoodboardprompt-engineeringprompt-libraryprompt-managerreference-libraryseedancevisual-bookmarksweb-clipper
import test from "node:test";
import assert from "node:assert/strict";
import { readFile } from "node:fs/promises";
const [html, source, styles] = await Promise.all([
readFile(new URL("../extension/library.html", import.meta.url), "utf8"),
readFile(new URL("../extension/library.js", import.meta.url), "utf8"),
readFile(new URL("../extension/library.css", import.meta.url), "utf8")
]);
test("first paint keeps the real shell visible with an inline loading status and no fake counts", () => {
assert.match(html, /<body[^>]*data-library-state="loading"/);
assert.match(html, /id="library-loading"[\s\S]*正在打开资料库/);
assert.doesNotMatch(html, /正在读取本地案例/);
assert.doesNotMatch(html, /id="result-count">0 个案例/);
assert.doesNotMatch(html, /id="pending-count">0</);
assert.match(html, /<main class="gallery-shell">\s*<div id="library-loading"/);
assert.doesNotMatch(styles, /body\[data-library-state="loading"\]\s*>[^}]*visibility:\s*hidden/);
assert.doesNotMatch(styles, /\.library-loading\s*\{[^}]*position:\s*fixed/);
});
test("core cases render before PDF derived cache and the cache cannot trigger a full gallery refresh", () => {
const refresh = source.slice(source.indexOf("async function refreshLibrary"), source.indexOf("async function loadDocumentDerivedCache"));
const render = refresh.indexOf("renderGallery(");
assert.ok(render >= 0 && render < refresh.indexOf("loadDocumentDerivedCache(entries)"));
assert.doesNotMatch(refresh, /await loadDocumentDerivedCache\(entries\)/);
assert.match(refresh, /dataset\.libraryState/);
const derived = source.slice(source.indexOf("async function loadDocumentDerivedCache"), source.indexOf("function renderGallery"));
assert.doesNotMatch(derived, /renderGallery\(/);
});
test("tablet and phone headers have explicit safe layouts", () => {
assert.match(styles, /@media \(max-width: 900px\)[\s\S]*\.topbar\s*\{[^}]*grid-template-areas/);
assert.match(styles, /@media \(max-width: 640px\)[\s\S]*\.topbar\s*\{[^}]*grid-template-areas/);
assert.match(styles, /@media \(max-width: 640px\)[\s\S]*padding:\s*10px 12px/);
});