import test from 'node:test';
import assert from 'node:assert/strict';
import { parseMindspaceCoverMeta, upsertMindspaceCoverMeta } from './mindspace-cover-meta.mjs';
test('upsertMindspaceCoverMeta replaces existing meta tag', () => {
const html = `
Demo`;
const next = upsertMindspaceCoverMeta(html, { tag: 'ๆ
่ก', emoji: 'โ๏ธ', accent: '#eeb04e' });
const parsed = parseMindspaceCoverMeta(next);
assert.equal(parsed.tag, 'ๆ
่ก');
assert.equal(parsed.emoji, 'โ๏ธ');
assert.equal(parsed.accent, '#eeb04e');
});
test('upsertMindspaceCoverMeta inserts meta into head when missing', () => {
const html = 'Demo';
const next = upsertMindspaceCoverMeta(html, { tag: '็พ้ฃ', emoji: '๐' });
assert.match(next, /name="mindspace-cover"/);
assert.equal(parseMindspaceCoverMeta(next).tag, '็พ้ฃ');
});
test('upsertMindspaceCoverMeta wraps fragments without duplicating doctype', () => {
const html = 'Guarded release';
const next = upsertMindspaceCoverMeta(html, { tag: '็ฒพ้้กต้ข', subtitle: 'Guarded release' });
assert.match(next, /^/i);
assert.doesNotMatch(next, /\s*/i);
assert.match(next, /Guarded release<\/title>/);
});