const test = require('node:test'); const assert = require('node:assert/strict'); const fs = require('fs'); const path = require('path'); const { injectPageMeta, injectSeoHead, documentTitleEn, absoluteUrl, softwareApplicationLd, } = require('./injectPageMetaIntoHtml.js'); const DOC = JSON.parse( fs.readFileSync(path.join(__dirname, '../assets/content/page-meta.json'), 'utf8') ); test('documentTitleEn joins tagline with a single space', () => { assert.equal( documentTitleEn(DOC.pages.infoHighlight), "Info Highlight - highlight the 'informative' parts" ); }); test('absoluteUrl builds extensionless origin URLs', () => { assert.equal(absoluteUrl(DOC, '/'), 'https://info-lens.app/'); assert.equal(absoluteUrl(DOC, '/analysis'), 'https://info-lens.app/analysis'); }); test('injectPageMeta fills h1, description, canonical, and SoftwareApplication JSON-LD', () => { const src = `

`; const html = injectPageMeta(src, 'infoHighlight', DOC); assert.match(html, /Info Highlight - highlight the 'informative' parts<\/title>/); assert.match(html, /data-page-title data-i18n>Info Highlight<\/span>/); assert.match(html, /<meta name="description" content="Info Highlight heatmaps per-token surprisal/); assert.match(html, /data-i18n="content"/); assert.match(html, /<link rel="canonical" href="https:\/\/info-lens.app\/analysis">/); assert.match(html, /application\/ld\+json/); const ld = JSON.parse(html.match(/<script type="application\/ld\+json">([^<]+)<\/script>/)[1]); assert.equal(ld['@type'], 'SoftwareApplication'); assert.equal(ld.name, 'Info Highlight'); assert.equal(ld.applicationCategory, 'BrowserApplication'); assert.equal(ld.operatingSystem, 'Chrome'); assert.equal(ld.url, 'https://info-lens.app/analysis'); assert.equal(ld.installUrl, DOC.chromeWebStoreUrl); assert.deepEqual(ld.sameAs, [DOC.chromeWebStoreUrl]); assert.equal(ld.offers.price, '0'); }); test('injectPageMeta home gets WebSite JSON-LD and keeps homepage description', () => { const src = `<!DOCTYPE html> <html><head><meta charset="UTF-8"><title>

`; const html = injectPageMeta(src, 'home', DOC); assert.match(html, //); const ld = JSON.parse(html.match(/ `; const html = injectSeoHead(src, DOC.staticPages['info-highlight.html'], DOC); const canonIdx = html.search(//); const scriptIdx = html.indexOf('/* lang bootstrap */'); assert.ok(canonIdx >= 0, 'canonical tag missing'); assert.ok(scriptIdx > canonIdx, 'canonical must precede the lang script'); }); test('softwareApplicationLd points at the Chrome Web Store listing', () => { const ld = softwareApplicationLd(DOC, 'https://info-lens.app/analysis', 'desc'); assert.equal( ld.installUrl, 'https://chromewebstore.google.com/detail/info-highlight/gemajnklkebeikmfphiddpjfimahacdk' ); });