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

1.6 KB
Raw Blame
import test from 'node:test';
import assert from 'node:assert/strict';
import { codePreviewHtml, codePreviewText } from '../extension/code-case.js';
import { classifyContent } from '../extension/classifier.js';
import { CONTENT_IDS, createDefaultTaxonomy, normalizeTaxonomy } from '../extension/taxonomy.js';

test('runnable preview roundtrips exact code including markdown fences without replacing original sources', () => {
  const html = '<!doctype html><html><body><script>let a="```";</script></body></html>';
  const original = 'CSS original\nReact original\nPrompt original';
  const text = original + '\n' + codePreviewText(html);
  assert.equal(codePreviewHtml(text), html); assert(text.startsWith(original));
  assert.deepEqual(classifyContent({ text, sourceFacts: { codePreviewAvailable: true } }).pathIds, [CONTENT_IDS.codeCase]);
  assert.notDeepEqual(classifyContent({ text }).pathIds, [CONTENT_IDS.codeCase], 'webpage text alone does not authorize a runnable code case');
  assert.equal(codePreviewHtml('```html\n<p>ordinary article</p>\n```'), '', 'ordinary article snippets do not become executable previews');
});
test('existing libraries gain a code type while custom names and original classifications remain intact', () => {
  const taxonomy = createDefaultTaxonomy(); taxonomy.nodes = taxonomy.nodes.filter(node => node.id !== CONTENT_IDS.codeCase);
  taxonomy.nodes[0].name = 'My tutorial';
  const updated = normalizeTaxonomy(taxonomy);
  assert(updated.nodes.some(node => node.id === CONTENT_IDS.codeCase));
  assert.equal(updated.nodes[0].name, 'My tutorial');
});