// Behavioral browser checks for the accepted publication surface. const { chromium } = require('playwright'); const { readFileSync } = require('fs'); const assert = require('node:assert/strict'); (async () => { const origin = process.env.ODYSSEUS_TEST_STATIC_ORIGIN; const browser = await chromium.launch({ headless: true }); try { const page = await browser.newPage(); const mediaRequests = []; const errors = []; page.on('request', req => { if (/\.(webm|mp4)(?:$|\?)/.test(req.url())) mediaRequests.push(req.url()); }); page.on('pageerror', e => errors.push(e.message)); await page.goto(origin + '/website/index.html'); assert.equal(await page.locator('video, .preview-panel, .sec-bg-tint').count(), 0); assert.equal(await page.locator('.feature-description').count(), 8); for (const description of await page.locator('.feature-description .desc').allTextContents()) assert(description.trim()); for (const width of [1280, 390]) { await page.setViewportSize({ width, height: 900 }); assert(await page.locator('.feature-description').first().isVisible()); assert(await page.evaluate(() => document.documentElement.scrollWidth <= innerWidth)); } assert.deepEqual(mediaRequests, []); assert.deepEqual(errors, []); const manifest = await (await page.request.get(origin + '/static/manifest.json')).json(); assert.equal(manifest.display, 'standalone'); assert(!manifest.icons); for (const filename of ['index.html', 'login.html']) { const html = await (await page.request.get(origin + '/static/' + filename)).text(); assert(!/]+rel=["']apple-touch-icon/.test(html)); } // A small host DOM runs the actual export function and markdown renderer. await page.route('**/publication-harness', route => route.fulfill({ contentType: 'text/html', body: '
' })); await page.route('**/api/**', route => route.fulfill({ contentType: 'application/json', body: JSON.stringify({ fonts: {}, value: null }) })); await page.goto(origin + '/publication-harness'); const source = readFileSync('static/js/document.js', 'utf8'); const fn = source.match(/\n async function exportAsPdf\(\) \{(.*?)\n \}\n/s)[0]; const result = await page.evaluate(async ({ origin, fn }) => { const module = await import(origin + '/static/js/markdown.js'); const markdownModule = module.default || module; const _isRichTextLang = lang => lang === 'html'; const _isDocxLang = () => false; const _richTextExportCss = () => 'p { color: black; }'; const _getExportBaseName = () => 'Print test'; const activeDocId = 'test'; const errors = []; const uiModule = { showError: message => errors.push(message) }; const originalRender = markdownModule.renderMath; const prints = []; markdownModule.renderMath = async container => { await originalRender(container); const frame = document.getElementById('doc-browser-print-frame'); frame.contentWindow.print = () => { prints.push({ body: frame.contentDocument.body.innerHTML, title: frame.contentDocument.title, links: [...frame.contentDocument.querySelectorAll('link')].map(l => l.href) }); frame.contentWindow.dispatchEvent(new Event('afterprint')); }; }; const run = eval('(' + fn.trim() + ')'); const textarea = document.getElementById('doc-editor-textarea'); textarea.value = 'Formula $E = mc^2$ here.'; await run(); document.getElementById('doc-language-select').value = 'text'; textarea.value = '& literal'; await run(); document.getElementById('doc-language-select').value = 'html'; textarea.value = 'Rich content