Files
genoffice/apps/docs/tests/html-export.test.ts
T
merrick-2002andGenOffice d24c964a3e Sync snapshot (2026-09-09) (#271)
- **New app: GenOffice HTML.** Open, edit and generate .html pages: a source pane with a sandboxed live preview, click-to-select elements with a floating toolbar and style panel, device-size preview, image tools and a present mode. AI generates whole pages from a brief with style directions and offers page-wide Restyle, Theme and Summarize. Export to Word runs locally through the built-in html2docx converter (native, editable OOXML; no print-to-PDF detour).
- **AI:** separate BYOK providers for web search, image generation and image/video analysis; new Codex App Server provider; Ask AI quotes the selected text and keeps it highlighted while it runs; custom AI panel text size; blocked requests retry through the Chromium network stack.
- **App:** global AutoSave setting shared by every editor; AI panel text size and chat spellcheck toggles (genoffice#249); Czech (cs) UI locale (genoffice#259); Save As defaults to the document's folder; PDF export no longer aborts on CJK file paths on Windows.
- **Docs:** Export as HTML; comments and replies edit in place from the comments pane; the caret can leave a trailing table (genoffice#266); spellcheck re-marks text as soon as it is re-enabled; AI edits are character-precise on partial selections; zoom keeps the scroll position; pasting a cell from Sheets takes the destination font.
- **Sheets:** Find no longer freezes on wide or streamed grids; Replace searches as you type; cached values of external-workbook formulas are kept instead of #ERROR! (genoffice#235); "number stored as text" is a warning, not an error (genoffice#236); paste repeats into the target range like Excel; filter criteria survive save/reopen; saves retry when Windows locks the file; many Excel-fidelity fixes for column widths, row heights, charts, slicers, number formats and CJK fonts.
- **Slides:** PDF export works for large presentations (genoffice#264); EMF/WMF picture fonts and East Asian theme fonts resolve correctly; decks with missing layouts or embedded styles still open; outline-only pie slices render.
- **PDF:** highlight and underline geometry aligns with the text; Shift+arrows extend the selection instead of paging.
- **Markdown:** Find and replace (Ctrl+F / Ctrl+H) (genoffice#253); mermaid code blocks render as diagrams (genoffice#263); better print quality.
- Thanks to community contributors @GoodScholar, @aniruddhaadak80 and @Sun8854, and to @hanyscz, @qgzln, @zyp997, @bisslot, @krakotay and @Ben03151 for the reports.

Co-authored-by: GenOffice <merrick-2002@users.noreply.github.com>
2026-09-09 18:19:13 +08:00

78 lines
3.2 KiB
TypeScript
Raw Blame History

This file contains invisible Unicode characters
This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
/**
* Standalone HTML export: editing chrome is dropped, review wrappers are
* flattened to their accepted text, authored attributes survive, and the
* output carries no app class names (jsdom resolves inline styles only, so
* the cascade itself is exercised on the real app).
*/
import { describe, expect, it } from 'vitest'
import { buildStandaloneHtml, resolveContent } from '../src/renderer/html-export'
function mount(html: string): HTMLElement {
const root = document.createElement('div')
root.className = 'doc-page ProseMirror'
root.innerHTML = html
document.body.appendChild(root)
return root
}
describe('buildStandaloneHtml', () => {
it('drops widgets and tracked deletions, unwraps comments and insertions', () => {
const root = mount(
'<p class="doc-p">Hello <span class="doc-comment">noted</span> ' +
'<span class="doc-ins">added</span><span class="doc-del">gone</span>' +
'<span class="ProseMirror-widget">⚑</span></p>' +
'<div class="page-gap">page 2</div>',
)
const out = buildStandaloneHtml(root, { title: 'T' })
expect(out).toContain('<p>Hello noted added</p>')
expect(out).not.toContain('gone')
expect(out).not.toContain('⚑')
expect(out).not.toContain('page 2')
expect(out).not.toMatch(/class="doc-/)
})
it('keeps links, images, table spans and inline widths', () => {
const root = mount(
'<p><a href="https://x.test" class="doc-link">x</a>' +
'<img src="data:image/png;base64,AAAA" alt="pic" style="width:120px;height:40px"></p>' +
'<table class="doc-table"><tbody><tr><td colspan="2" style="width:200px">c</td></tr></tbody></table>',
)
const out = buildStandaloneHtml(root, { title: 'T', textWidthPx: 600 })
expect(out).toMatch(/<a href="https:\/\/x.test"[^>]*>x<\/a>/)
expect(out).toMatch(/<img src="data:image\/png;base64,AAAA" alt="pic" width="120" height="40"/)
expect(out).toMatch(/<td colspan="2" style="[^"]*width:200px/)
expect(out).toContain('max-width:600px')
expect(out).toMatch(/^<!DOCTYPE html>/)
})
it('escapes text and restores lifted screen-only classes', () => {
const wrap = document.createElement('div')
wrap.className = 'workspace page-dark'
document.body.appendChild(wrap)
const root = document.createElement('div')
root.innerHTML = '<p>a &lt; b &amp; "c"</p>'
wrap.appendChild(root)
const out = buildStandaloneHtml(root, { title: 'A & B' })
expect(out).toContain('<p>a &lt; b &amp; "c"</p>')
expect(out).toContain('<title>A &amp; B</title>')
expect(wrap.classList.contains('page-dark')).toBe(true)
})
})
describe('resolveContent', () => {
it('resolves strings, escapes, attr() and the ordered counter', () => {
const el = document.createElement('p')
el.setAttribute('data-marker', '(a)')
expect(resolveContent('attr(data-marker) "\\00a0"', el)).toBe('(a) ')
expect(resolveContent('"•"', el)).toBe('•')
expect(resolveContent('none', el)).toBe('')
const list = document.createElement('div')
for (let i = 0; i < 3; i++) {
const li = document.createElement('p')
li.className = 'doc-li doc-li-ordered'
list.appendChild(li)
}
expect(resolveContent('counter(doc-ol) "."', list.children[2])).toBe('3.')
})
})