import { test } from 'node:test'; import assert from 'node:assert/strict'; import { createElement } from 'react'; import { renderToStaticMarkup } from 'react-dom/server'; import { ArticleComposer } from '@bitbaum/writingkit/react'; const transport = { publish: async () => {}, assist: async () => null }; const render = props => renderToStaticMarkup( createElement(ArticleComposer, { transport, draftKey: 'k', signedIn: true, ...props }) ); test('title and text both carry the microphone path, labelled', () => { const html = render({}); assert.equal((html.match(/ck-field-wrap/g) ?? []).length >= 2, true); assert.match(html, /]*>Title<\/label>/); assert.match(html, /Speak/); }); test('one primary action; a signed-in writer can also save a draft', () => { const html = render({}); assert.equal((html.match(/wk-btn-primary/g) ?? []).length, 1); assert.match(html, /Save as draft/); assert.match(html, />Publish { const html = render({ signedIn: false, signInHref: '/sign-in?next=/write' }); assert.match(html, /Sign in to publish/); assert.doesNotMatch(html, /Save as draft/); assert.match(html, /stays on this device/); }); test('editing a published article offers Save changes, and the photo tool only with a finder', () => { assert.match(render({ editingPublished: true }), /Save changes/); assert.doesNotMatch(render({}), />Photo null }), />Photo { const html = render({ above: createElement('p', { id: 'ctx' }, 'In response to X'), extraActions: createElement('a', { href: '/cancel' }, 'Cancel'), }); assert.match(html, /In response to X/); assert.match(html, /href="\/cancel"/); }); test('a chart block draws through chartkit on the server, with title and source', async () => { const { ArticleChartBlock } = await import('@bitbaum/writingkit/react/chart'); const html = renderToStaticMarkup( createElement(ArticleChartBlock, { source: 'title: Boxes sold\nsource: Our ledger\nyear,Boxes\n2024,120\n2025,340', }) ); assert.match(html, /class="wk-chart"/); assert.match(html, /ck-chart-columns/); assert.match(html, /
Boxes sold. Source: Our ledger/); assert.match(html, / { const { SuggestionCard } = await import('@bitbaum/writingkit/react'); const html = renderToStaticMarkup( createElement(SuggestionCard, { suggestion: { id: '1', field: 'body', label: 'Make it tighter', before: 'the river rose very fast that night', after: 'the river rose fast that night' }, onAccept: () => {}, onReject: () => {}, }) ); assert.match(html, /Suggestion: Make it tighter/); assert.match(html, /]*>very <\/del>/); assert.match(html, /Use this/); assert.match(html, /Keep mine/); assert.equal((html.match(/wk-btn-primary/g) ?? []).length, 0); // Publish stays the one primary const rewrite = renderToStaticMarkup( createElement(SuggestionCard, { suggestion: { id: '2', field: 'body', label: 'Draft', before: 'one two three', after: 'something else entirely new' }, onAccept: () => {}, onReject: () => {}, }) ); assert.match(rewrite, /Replaces your text/); assert.doesNotMatch(rewrite, /