import { expect, test } from "bun:test"; import { createElement } from "react"; import { renderToStaticMarkup } from "react-dom/server"; import { MessageMarkdown } from "./markdown"; import { referenceRenderModel } from "./references"; import type { Chat } from "@chopin/protocol"; let PARTICIPANT_MESSAGE = [ "**Bold** and *italic* with [the docs](https://example.com).", "", "- first", "- second", "", "1. one", "2. two", "", "> quoted", "", "Use `bun test`.", "", "```ts", "let answer = 42;", "```", "", "# Ordinary message text", "", "![remote](https://example.invalid/pixel.png)", 'raw', ].join("\n"); function reference(source: string, token: string, id = "reference-one"): Chat.Reference { let start = source.indexOf(token); return { id, kind: "document", channelId: `channel-${id}`, start, end: start + token.length, label: token, href: `/documents/octo-org/score/${id}`, repositoryId: "repository-one", observedRevision: 4, observedSourceHash: "sha256:source", }; } function markdown(source: string, references?: Chat.Reference[]): string { return renderToStaticMarkup(createElement(MessageMarkdown, { source, references })); } test("Chat Markdown admits formatting without document features", () => { let markup = markdown(PARTICIPANT_MESSAGE); expect(markup).toContain("Bold"); expect(markup).toContain("italic"); expect(markup).toContain("