import { test } from "node:test";
import assert from "node:assert/strict";
import { isPlainCmsText } from "@/features/cms/cmsText";

test("an admin's plain text with line breaks and bullets is recognised as plain", () => {
  assert.equal(isPlainCmsText("We respect your privacy.\r\n\r\n1. Data we collect\r\n- Account data"), true);
  assert.equal(isPlainCmsText("نحترم خصوصيتك.\r\n- بيانات الحساب"), true);
  assert.equal(isPlainCmsText("A < B and C > D"), true, "a bare comparison is not a tag");
});

test("rich text with block markup is left alone", () => {
  for (const html of ["<p>Hello</p>", "Line<br>two", "<ul><li>a</li></ul>", "<h2>Title</h2>text", "<div>x</div>", "<P>Upper</P>"]) {
    assert.equal(isPlainCmsText(html), false, html);
  }
});

test("empty or missing bodies are not plain text", () => {
  assert.equal(isPlainCmsText(""), false);
  assert.equal(isPlainCmsText("   "), false);
  assert.equal(isPlainCmsText(null), false);
  assert.equal(isPlainCmsText(undefined), false);
});
