Files
writingkit/test/render.test.js
T
CatoandClaude Sonnet 5.5 99fe5ae1c0 feat(react): ArticleComposer — the shared place to write (#1)
* feat(react): ArticleComposer — the shared place to write; assist, drafts and text-edit move into the core

Owner, 2026-11-06: the experience belongs to the package. The composer built in
BiasLens (title, text, Speak/Photo/Chart, preview, drafts, publish bar) becomes
@bitbaum/writingkit/react on chatkit's DictationField, so every product gets a
microphone and writing help in the title and the text without building them.

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

* build: rebuild dist against published chatkit 0.23.0; lockfile

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

---------

Co-authored-by: Claude <noreply@anthropic.com>
2026-11-06 09:29:50 +01:00

48 lines
1.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"/);
});