Files
CatoandClaude Opus 5.5 0f3f481a3b feat: charts in articles and suggestions the writer accepts or rejects (0.3.0) (#14)
* feat: charts in articles and suggestions the writer accepts or rejects (0.3.0)

- ```chart blocks (JSON or CSV spec): parseChartBlock, splitChartBlocks,
  table fallbacks for RSS/share cards (chartsToTables), chartValuesNotInText
  so a proposed chart draws only the writer's own numbers
- @bitbaum/writingkit/react/chart: ArticleChart / ArticleChartBlock drawn by
  @bitbaum/chartkit (new optional peer)
- Suggestion, applySuggestion (refuses stale text), wordDiff, SuggestionCard
- suggestMedia: a chart beside the paragraph with figures, else an illustration
- ArticleComposer: renderChart in Preview; draft-from-brief is a suggestion

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_019MDtmvT2nQyPBK4EfWf3Rn

* feat(chart): read bip-kit's series-line format too

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_019MDtmvT2nQyPBK4EfWf3Rn

* fix(suggestions): show a rewrite whole; keep Publish the one primary action

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_019MDtmvT2nQyPBK4EfWf3Rn

---------

Co-authored-by: Claude <noreply@anthropic.com>
2026-11-15 02:26:30 +01:00

92 lines
3.8 KiB
JavaScript

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, /<label[^>]*>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</);
});
test('a signed-out writer is shown the way to sign in, not a dead end', () => {
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</);
assert.match(render({ photos: () => null }), />Photo</);
});
test('extra actions and context are slotted, not rebuilt', () => {
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, /<figcaption class="ck-chart-caption">Boxes sold. Source: Our ledger/);
assert.match(html, /<table class="ck-chart-table"/);
assert.equal((html.match(/Boxes sold/g) ?? []).length, 2); // caption + table caption, once each
assert.equal(renderToStaticMarkup(createElement(ArticleChartBlock, { source: 'nope' })), '');
assert.match(
renderToStaticMarkup(createElement(ArticleChartBlock, { source: 'nope', showProblem: true })),
/cannot be drawn yet/
);
});
test('a suggestion is shown as what changes, with Use this and Keep mine', async () => {
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, /<del[^>]*>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, /<del/);
});