import { expect } from "@std/expect";
import { describe, it } from "@std/testing/bdd";
import { renderToStaticMarkup } from "react-dom/server";
import { ProcessMessage } from "./process-message";
function render(value: string) {
return renderToStaticMarkup();
}
describe("ProcessMessage", () => {
it("renders markdown formatting", () => {
const html = render("We are **investigating** `api` latency.");
expect(html).toContain("investigating");
expect(html).toContain("api");
});
it("opens links in a new tab without a referrer", () => {
const html = render("See [the docs](https://docs.openstatus.dev).");
expect(html).toMatch(
/]*href="https:\/\/docs\.openstatus\.dev"[^>]*>the docs<\/a>/,
);
expect(html).toContain('target="_blank"');
expect(html).toContain('rel="noreferrer"');
});
it("styles unordered lists and keeps their items", () => {
const html = render("- first\n- second");
expect(html).toContain("list-disc");
expect(html).toContain("first");
expect(html).toContain("second");
});
it("does not render raw HTML from the message", () => {
const html = render('
\n\n');
expect(html).not.toContain("
{
expect(render("[click](javascript:alert(1))")).not.toContain("alert(1)");
});
// the `ol` override drops its props, so ordered list items vanish
it.ignore("keeps the items of ordered lists", () => {
const html = render("1. first\n2. second");
expect(html).toContain("list-decimal");
expect(html).toContain("first");
});
});