Files
memind/mindspace-workspace-thumbnails.test.mjs
T
John 2e14873f2d Initial commit: Memind H5 portal with MindSpace, Plaza, and agent jobs.
Track application source and tests; exclude local env, user workspaces, and runtime data via .gitignore.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-06-15 15:04:43 -07:00

30 lines
1.4 KiB
JavaScript

import assert from 'node:assert/strict';
import test from 'node:test';
import fs from 'node:fs/promises';
import os from 'node:os';
import path from 'node:path';
import {
ensureWorkspaceHtmlThumbnail,
workspaceThumbnailRelativePath,
} from './mindspace-workspace-thumbnails.mjs';
import { isModernFeedThumbnail } from './mindspace-thumbnails.mjs';
test('workspaceThumbnailRelativePath maps html to sidecar svg', () => {
assert.equal(workspaceThumbnailRelativePath('pilates.html'), 'pilates.thumbnail.svg');
assert.equal(workspaceThumbnailRelativePath('public/pilates.html'), 'public/pilates.thumbnail.svg');
});
test('ensureWorkspaceHtmlThumbnail writes sidecar on html save', async () => {
const root = await fs.mkdtemp(path.join(os.tmpdir(), 'workspace-thumb-'));
const html = `<!doctype html><html><head>
<title>普拉提618</title>
<meta name="mindspace-cover" content='{"tag":"运动","accent":"#eeb04e","accent2":"#1a0a2e","subtitle":"限时活动"}' />
<style>body { background:#0a0a0a; color:#eeb04e; }</style>
</head><body></body></html>`;
await fs.writeFile(path.join(root, 'pilates.html'), html, 'utf8');
const svg = await ensureWorkspaceHtmlThumbnail(root, 'pilates.html', html, { title: '普拉提618' });
assert.equal(isModernFeedThumbnail(svg), true);
assert.match(svg, /运动|普拉提618/i);
await fs.access(path.join(root, 'pilates.thumbnail.svg'));
});