Files
genoffice/apps/docs/tests/color-auto-render.test.ts
T
merrick-2002andGenOffice 69b4ce0560 Sync snapshot (2026-09-06) (#243)
- Docs: Word-style dark page, phased fast open for long documents, fonts embedded in the DOCX, spellcheck toggle, hyperlink editing, and ~80 Word fidelity fixes (CJK/JP metrics, header/footer, tables, anchored pictures)
- Sheets: hold formula recalculation while file data streams in, large-workbook scroll/load performance, combo charts, duplicate/unique conditional formatting by display text, RTL frozen-pane fix, workbooks whose ZIP entries carry a leading slash
- Slides: MTX-compressed embedded font support, CJK/Latin face selection and PowerPoint script fallbacks, theme colors kept on paragraph defaults and bullets, more reliable AI edits with a layout audit after each batch
- PDF: AI page ops, text block move/align, notes and markup editing, watermark and header/footer, form check boxes, metadata; the cloud Export as Word fallback is removed, conversion is always on-device
- AI: Gemini tool schema translation, OpenCode Zen/Go providers, markdown tables and code blocks in chat, current date in the system prompt
- Shell: Office-style ribbon collapse across all editors, native Windows ARM64 installer, BUILD_DIR override for packaging

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

49 lines
2.2 KiB
TypeScript

/** Explicit w:color auto renders as the default ink, never as a `#auto` colour. */
import { Editor } from '@tiptap/core'
import { parseDocx } from '@genoffice/docx-engine'
import type { ParsedDocFull, StyleDisplay, StyleInfo } from '@genoffice/docx-engine'
import { describe, expect, it } from 'vitest'
import { buildDocx } from '../../../packages/docx-engine/tests/helpers/build-docx'
import { docStyleCss } from '../src/renderer/doc-style-css'
import { blocksToPmDoc } from '../src/renderer/editor/convert'
import { editorExtensions } from '../src/renderer/editor/extensions'
;(globalThis as { CSS?: unknown }).CSS ??= { escape: (s: string) => s }
const STYLES =
'<w:style w:type="paragraph" w:styleId="RedBody"><w:name w:val="Red Body"/>' +
'<w:rPr><w:color w:val="FF0000"/></w:rPr></w:style>'
const BODY =
'<w:p><w:pPr><w:pStyle w:val="RedBody"/></w:pPr>' +
'<w:r><w:rPr><w:color w:val="auto"/></w:rPr><w:t>automatic</w:t></w:r>' +
'<w:r><w:t xml:space="preserve"> inherited</w:t></w:r></w:p>'
function parsedWith(styleId: string, display: StyleDisplay): ParsedDocFull {
const styles = new Map<string, StyleInfo>()
styles.set(styleId, { styleId, name: styleId, type: 'paragraph', display } as StyleInfo)
return { styles, docDefaults: {}, blocks: [] } as unknown as ParsedDocFull
}
describe('w:color auto rendering', () => {
it('paints an auto run in the paper ink over the style colour', async () => {
const parsed = await parseDocx(await buildDocx({ bodyXml: BODY, extraStylesXml: STYLES }))
const editor = new Editor({
element: document.createElement('div'),
extensions: editorExtensions,
content: blocksToPmDoc(parsed.blocks) as never,
})
const spans = [...editor.view.dom.querySelectorAll('p span')] as HTMLElement[]
const auto = spans.find((s) => s.textContent === 'automatic')
expect(auto?.style.color).toBe('var(--docs-paper-ink)')
expect(auto?.getAttribute('style')).not.toContain('--dk-c')
editor.destroy()
})
it('emits the paper ink for a style whose colour is auto', () => {
const css = docStyleCss(parsedWith('ResetBody', { color: 'auto' }))
expect(css).toContain('[data-style="ResetBody"] { color:var(--docs-paper-ink) }')
expect(css).not.toContain('#auto')
})
})