// html-text.test.js — a remote Note's HTML → the plain text an observation carries (hyper-social #82, I1 S2).
//
// ⛔ PLAIN TEXT, NEVER MARKUP. The text lands in a favela record body that the surface renders; a remote
// server's HTML must not become markup on our side. Paragraphs and line breaks survive as newlines,
// entities are decoded once, every tag is dropped.
import test from 'brittle'
import { htmlToText } from '../lib/html-text.js'
test('paragraphs and breaks become newlines; tags are dropped', (t) => {
t.is(htmlToText('<p>hello <a href="https://x/@a" class="u-url mention">@<span>a</span></a></p><p>second<br>line</p>'), 'hello @a\n\nsecond\nline')
})
test('entities are decoded once', (t) => {
t.is(htmlToText('<p>a & b <3 "q" 's' &amp;</p>'), 'a & b <3 "q" \'s\' &')
})
test('script and style content is not text', (t) => {
t.is(htmlToText('<p>ok</p><script>alert(1)</script><style>p{}</style>'), 'ok')
})
test('bounded and tolerant of junk', (t) => {
t.is(htmlToText(null), '')
t.is(htmlToText(42), '')
t.is(htmlToText('<p>' + 'x'.repeat(5000) + '</p>', { max: 100 }).length, 100)
})