/** Second batch of the owner's chat feedback: reasoning that opens smoothly, code blocks, the preview icon button, the sidebar preview's motion. */ import test from 'node:test'; import assert from 'node:assert/strict'; import { readFile } from 'node:fs/promises'; import { transform } from 'esbuild'; const read = p => readFile(new URL(`../${p}`, import.meta.url), 'utf8'); const { code } = await transform((await read('src/lib/code-preview.ts')).replace("import { useSyncExternalStore } from 'react';", 'const useSyncExternalStore = () => null;').replace("import type { PreviewArtifact } from './artifacts';", ''), { loader: 'ts', format: 'esm' }); const lib = await import(`data:text/javascript;base64,${Buffer.from(code).toString('base64')}`); const liquid = await read('src/styles/liquid.css'); test('only HTML and Markdown blocks have a preview; each block has its own stable id', () => { assert.equal(lib.codePreviewKind('html'), 'website'); assert.equal(lib.codePreviewKind('HTML'), 'website'); assert.equal(lib.codePreviewKind('md'), 'markdown'); assert.equal(lib.codePreviewKind('markdown'), 'markdown'); assert.equal(lib.codePreviewKind('bash'), null); const a = lib.codePreview('m1', 'html', '
a
'), b = lib.codePreview('m1', 'html', 'b
'); assert.notEqual(a.id, b.id, 'two blocks in one answer are two previews'); assert.equal(a.id, lib.codePreview('m1', 'html', 'a
').id, 'the same block keeps its id'); assert.equal(lib.codePreview('m1', 'bash', 'ls'), null); }); test('a finished answer with exactly one whole HTML page goes to the sidebar by itself; snippets and several blocks do not', () => { const page = '\nhi'; assert.equal(lib.mainCodePreview('m', `Here:\n\n\`\`\`html\n${page}\n\`\`\`\n`)?.kind, 'website'); assert.equal(lib.mainCodePreview('m', 'A snippet:\n\n```html\nx\n```\n'), null); assert.equal(lib.mainCodePreview('m', `\`\`\`html\n${page}\n\`\`\`\n\n\`\`\`html\n${page}\n\`\`\`\n`), null); assert.equal(lib.mainCodePreview('m', 'Notes:\n\n```markdown\n# a\n```\n'), null, 'Markdown blocks keep the button only'); }); test('the code block has an icon preview button left of Copy, with an open state, and no text button', async () => { const md = await read('src/components/Markdown.tsx'), btn = await read('src/components/CodePreviewBtn.tsx'); assert.ok(!/