import { expect, test } from "bun:test";
import { renderToStaticMarkup } from "react-dom/server";
import { ErrorMessage } from "./error-message";
import { ErrorText } from "./error-text";
import { Field } from "./field";
import { Notice } from "./notice";
const REFERENCE = "163bc913-264d-4d38-a0b5-2e4e955eecdb";
const UNEXPECTED = `Opengeni couldn't finish the request. Try again in a moment. Reference: ${REFERENCE}.`;
test("inline error text offers an unexpected failure's reference as Copy details", () => {
const html = renderToStaticMarkup({UNEXPECTED});
expect(html).toContain("Opengeni couldn't finish the request. Try again in a moment.");
expect(html).toContain("Copy details");
expect(html).not.toContain(REFERENCE);
});
test("inline error text shows an expected refusal without status or reference", () => {
const html = renderToStaticMarkup(
{`API 409: Name is already in use. Reference: ${REFERENCE}.`},
);
expect(html).toBe("Name is already in use.");
expect(renderToStaticMarkup(Pick a workspace first.)).toBe(
"Pick a workspace first.",
);
});
test("a field's error uses the same rendering", () => {
const html = renderToStaticMarkup(
,
);
expect(html).toContain("Copy details");
expect(html).not.toContain(`Reference: ${REFERENCE}`);
});
test("a notice's text uses the same rendering", () => {
const html = renderToStaticMarkup(
{UNEXPECTED}
,
);
expect(html).toContain("Copy details");
expect(html).not.toContain(`Reference: ${REFERENCE}`);
});
test("ErrorMessage moves a trailing reference into Technical details", () => {
const html = renderToStaticMarkup(
{UNEXPECTED}
,
);
expect(html).toContain("Technical details");
expect(html).toContain(REFERENCE);
expect(html).not.toContain(`Reference: ${REFERENCE}.`);
// An explicit reference still wins.
const explicit = renderToStaticMarkup(
{UNEXPECTED}
,
);
expect(explicit).toContain("req-1");
expect(explicit).not.toContain(REFERENCE);
});