import assert from 'node:assert/strict'; import test from 'node:test'; import { convertGenericPageHtmlToWechatArticle, convertPageHtmlToWechatArticle, mindspaceWechatPageDraftInternals, } from './mindspace-wechat-page-draft.mjs'; const SAMPLE_HTML = ` 测试页面

标题

正文内容

`; test('convertGenericPageHtmlToWechatArticle extracts title and body', () => { const article = convertGenericPageHtmlToWechatArticle(SAMPLE_HTML, { publicUrl: 'https://m.tkmind.cn/u/demo/pages/test.html', pageTitle: '测试页面', pageSummary: '页面摘要', }); assert.equal(article.title, '测试页面'); assert.equal(article.digest, '页面摘要'); assert.match(article.content, /正文内容/); assert.match(article.content, /阅读原文/); }); test('convertPageHtmlToWechatArticle falls back to generic converter', () => { const article = convertPageHtmlToWechatArticle(SAMPLE_HTML, { publicUrl: 'https://example.com/page.html', pageTitle: '测试页面', pageSummary: '页面摘要', }); assert.equal(article.title, '测试页面'); assert.match(article.content, /正文内容/); }); test('convertGenericPageHtmlToWechatArticle truncates long content', () => { const longBody = `

${'很长'.repeat(12000)}

`; const article = mindspaceWechatPageDraftInternals.convertGenericPageHtmlToWechatArticle( `${longBody}`, { pageTitle: '长文' }, ); assert.ok(article.content.length <= 20000); });