Skip to content

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. 提示词导演

9.8 KB
Raw Blame
import test from "node:test";
import assert from "node:assert/strict";
import { readFile } from "node:fs/promises";

const html = await readFile(new URL("../extension/library.html", import.meta.url), "utf8");
const source = await readFile(new URL("../extension/library.js", import.meta.url), "utf8");

test("top navigation keeps search-adjacent actions focused on adding, creating, and settings", () => {
  const actions = html.slice(html.indexOf('<div class="top-actions">'), html.indexOf('<input id="media-file"'));
  assert.match(actions, /id="add-menu"/);
  assert.doesNotMatch(actions, /id="open-curated"|id="open-skills"/);
  assert.match(actions, /id="start-compose"/);
  assert.match(actions, /id="open-settings"[^>]*aria-label="设置"[^>]*title="设置"/);
  assert.doesNotMatch(actions, /id="package-menu"|id="select-cases"|id="open-batch-tools"|id="open-import-job"|id="open-about"/);
  assert.match(html.slice(html.indexOf('id="gallery-heading"'), html.indexOf('id="case-list"')), /id="select-cases"[^>]*aria-label="管理案例"[^>]*title="管理案例"/);
  assert.match(html, /class="button-secondary gallery-select-button"[\s\S]*data-i18n="管理">管理/);
  assert.doesNotMatch(actions, /id="share-cases"|id="combine-cases"|id="manage-facets"/);
  assert.match(html, /<aside[^>]*id="filter-sidebar"[\s\S]*id="manage-facets"/);
  const workspace = html.slice(html.indexOf('<nav class="workspace-navigation"'), html.indexOf('</nav>', html.indexOf('<nav class="workspace-navigation"')));
  assert.match(workspace, /id="workspace-library"[^>]*aria-current="page"/);
  assert.match(workspace, /id="workspace-unassigned"/);
  assert.match(workspace, /id="open-curated"/);
  assert.match(workspace, /id="open-skills"/);
  assert.ok(workspace.indexOf('id="workspace-library"') < workspace.indexOf('id="workspace-unassigned"'));
  assert.ok(workspace.indexOf('id="workspace-unassigned"') < workspace.indexOf('id="open-curated"'));
  assert.doesNotMatch(html, /动态视图|save-dynamic-view|dynamic-view-list/);
});

test("about details are on demand while version stays at the bottom of settings", async () => {
  const about = html.slice(html.indexOf('<footer class="settings-about"'), html.indexOf("</footer>", html.indexOf('<footer class="settings-about"')));
  const script = await readFile(new URL("../extension/library.js", import.meta.url), "utf8");
  assert.match(about, /id="about-version">PromptDirector</);
  assert.match(about, /id="open-about"/);
  assert.doesNotMatch(about, /Apache-2\.0|github\.com/);
  assert.match(script, /async function showExtensionAbout/);
  assert.match(script, /免费、开源、本地优先 · Apache-2\.0/);
  assert.match(script, /safeHttpUrl\(manifest\.homepage_url\)/);
});

test("closed dialogs cannot enter the page layout", async () => {
  const css = await readFile(new URL("../extension/ui-foundation.css", import.meta.url), "utf8");
  assert.match(css, /dialog:not\(\[open\]\)\s*\{\s*display:\s*none\s*!important/);
});

test("sidebar separates projects, content types, and on-demand attribute filters", () => {
  const sidebar = html.slice(html.indexOf('<aside id="filter-sidebar"'), html.indexOf('</aside>'));
  assert.match(sidebar, /class="workspace-navigation"/);
  assert.match(sidebar, /id="project-section"/);
  assert.match(sidebar, /id="content-filters"/);
  assert.match(sidebar, /id="facet-filters"/);
  assert.match(sidebar, /data-i18n="属性筛选"/);
  assert.doesNotMatch(source.slice(source.indexOf("function renderContentFilters"), source.indexOf("function renderFacetFilters")), /All types|\"全部\"/);
  assert.doesNotMatch(source.slice(source.indexOf("function renderFacetFilters"), source.indexOf("function createFacetFilterButton")), /name:\s*currentLocale\(\) === "en" \? "All"/);
});

test("desktop sidebar width is adjustable and persists as a bounded UI preference", async () => {
  const css = await readFile(new URL("../extension/library.css", import.meta.url), "utf8");
  assert.match(html, /id="sidebar-resizer"[^>]*role="separator"[^>]*tabindex="0"/);
  assert.match(css, /grid-template-columns: var\(--sidebar-width, 244px\) 6px minmax\(0, 1fr\)/);
  assert.match(css, /@media \(max-width: 900px\)[\s\S]*?\.sidebar-resizer \{ display: none; \}/);
  assert.match(source, /event\.key === "ArrowRight" \? 16 : -16/);
  assert.match(source, /updateUiPreferences\(\{ sidebarWidth \}\)/);
  assert.match(source, /Math\.floor\(innerWidth \* 0\.45\)/);
});

test("share and combine are contextual actions after entering selection mode", () => {
  const selection = html.slice(html.indexOf('id="gallery-heading"'), html.indexOf('<p id="feedback"'));
  assert.match(selection, /id="selection-copy-project"/);
  assert.match(selection, /id="selection-new-project"/);
  assert.match(selection, /id="selection-combine"/);
  assert.match(selection, /id="selection-analyze"/);
  assert.match(selection, /id="share-export"/);
  assert.match(selection, /id="selection-label-menu"/);
  assert.match(selection, /id="selection-project-menu"/);
  assert.match(selection, /id="selection-more-menu"/);
});

test("project heading keeps only creation and collapse while selected projects toggle off in place", () => {
  const sidebar = html.slice(html.indexOf('<aside id="filter-sidebar"'), html.indexOf('</aside>'));
  assert.doesNotMatch(html, /id="active-filter-bar"|id="active-filters"/);
  assert.doesNotMatch(sidebar, /id="clear-filters"|id="active-filter-badge"|sidebar-filter-tools|清除全部筛选/);
  const projectHeading = sidebar.slice(sidebar.indexOf('id="project-section"'), sidebar.indexOf('id="collection-filters"'));
  assert.match(projectHeading, /id="create-collection"[\s\S]*icon-plus[\s\S]*data-i18n="新建"/);
  assert.match(projectHeading, /id="collapse-projects"/);
  assert.ok(projectHeading.indexOf('id="create-collection"') < projectHeading.indexOf('id="collapse-projects"'));
  assert.match(source, /selectedCollectionId = selectedCollectionId === collection\.id \? "" : collection\.id/);
  assert.match(source, /toggleFilters\.dataset\.filterCount/);
});

test("classification manager keeps taxonomy work while settings owns AI services", () => {
  const manager = html.slice(html.indexOf('<dialog id="manager-dialog"'), html.indexOf('</dialog>', html.indexOf('<dialog id="manager-dialog"')));
  const settings = html.slice(html.indexOf('<dialog id="settings-dialog"'), html.indexOf('</dialog>', html.indexOf('<dialog id="settings-dialog"')));
  assert.match(manager, /data-manager-tab="pending"/);
  assert.match(manager, /data-manager-tab="content-types"/);
  assert.match(manager, /data-manager-tab="vocabulary"/);
  assert.doesNotMatch(manager, /data-manager-tab="batch"|data-manager-tab="analysis-settings"/);
  assert.match(settings, /data-settings-tab="general"/);
  assert.match(settings, /data-settings-tab="ai"/);
  assert.match(settings, /data-settings-tab="tasks"/);
  assert.match(settings, /data-settings-panel="tasks"/);
  assert.doesNotMatch(settings, /id="open-text-batch"/);
  assert.match(settings, /id="preview-analysis-batch"/);
  const batch = html.slice(html.indexOf('<dialog id="text-batch-dialog"'), html.indexOf('</dialog>', html.indexOf('<dialog id="text-batch-dialog"')));
  assert.match(batch, /id="text-batch-content"/);
  assert.match(batch, /id="batch-scope-project"/);
  assert.match(settings, /id="preview-reanalyze"/);
  assert.match(settings, /id="ai-settings-form"/);
  assert.match(settings, /id="vision-settings-form"/);
  assert.match(settings, /id="composer-settings-form"/);
  assert.doesNotMatch(settings, /id="deepseek-api-key"|id="text-ai-provider"|id="vision-provider"|id="vision-compatible-endpoint"/);
});

test("collector opens the library while keeping the unified assistant side panel available", async () => {
  const collector = await readFile(new URL("../extension/collector.js", import.meta.url), "utf8");
  assert.match(collector, /chrome\.tabs\.create\(\{\s*url:\s*chrome\.runtime\.getURL\("library\.html"\),\s*active:\s*false\s*\}\)/);
  assert.doesNotMatch(collector, /chrome\.sidePanel\?\.setOptions\?\.\(\{\s*tabId:\s*tab\.id,\s*enabled:\s*false\s*\}\)/);
  assert.match(collector, /chrome\.tabs\.update\(tab\.id,\s*\{\s*active:\s*true\s*\}\)/);
  assert.doesNotMatch(collector, /location\.assign\(chrome\.runtime\.getURL\("library\.html"\)\)/);
});

test("Skill details keep creation primary and place refine and export in one More menu", async () => {
  const [skillsHtml, skillsSource] = await Promise.all([
    readFile(new URL("../extension/skills.html", import.meta.url), "utf8"),
    readFile(new URL("../extension/skills-page.js", import.meta.url), "utf8")
  ]);
  assert.match(skillsHtml, /id="skill-detail-more"/);
  assert.match(skillsHtml, /id="skill-export"/);
  assert.match(skillsSource, /function exportSkill/);
  assert.match(skillsSource, /exportStoredSkillPackage/);
  assert.match(skillsSource, /elements\.skillSearch\.hidden = !listView/);
  assert.match(skillsSource, /elements\.skillImport\.hidden = !listView/);
  assert.match(skillsSource, /elements\.skillCreate\.hidden = !listView/);
  assert.match(skillsHtml, /id="skill-test"/);
  assert.match(skillsHtml, /id="skill-detail-edit"/);
  assert.match(skillsHtml, /id="skill-detail-refine"/);
  assert.doesNotMatch(skillsHtml, /PORTABLE CREATIVE METHODS|CREATIVE SKILL|IMPORT SKILL|VERSIONS/);
});

test("model options stay concise and put capability uncertainty below the selected field once", () => {
  const optionsSource = source.slice(source.indexOf("function discoveredModelOptions"), source.indexOf("function taskModelOptions"));
  assert.doesNotMatch(optionsSource, /厂商声明|协议确认|由你分配|首次执行时验证/);
  assert.match(optionsSource, /model\.name \|\| model\.id/);
  assert.match(optionsSource, /modelPriceLabel\(model\.pricing\)/);
  assert.match(source, /function modelAssignmentHelp/);
  assert.match(source, /model-capability-help/);
  assert.match(source, /当前模型未声明这项能力;是否可用以真实执行结果为准/);
});