Files
genoffice/apps/docs/tests/run-rtl-save.test.ts
T
merrick-2002andGenOffice 2239cce9e7 Sync snapshot (2026-08-30) (#168)
- Docs: DOCX rendering fidelity - drop caps, hidden (vanish) runs, paragraph pattern shading, floating-table anchoring and clamping, footnote sizing, justified-line spacing
- Docs: editing - page breaks split the paragraph correctly, URLs auto-linkify, Insert Hyperlink prefills from the selection, more stable table pagination
- Sheets: large streamed workbooks are splittable and formula-capable for the AI; copy_range carries live formulas; range sort up to 200k cells; 1M-cell copies over 2x faster
- Sheets: correctness - sort by raw values, shared-formula edits, typed cached strings, empty-string cells, note edits reach the save; risky structural deletes are rejected up front
- Sheets: AI chat can export sheets as standalone files; the formula bar grows to fit wrapped formulas
- Slides: right-to-left support - paragraph direction toggle, RTL tables, mirrored margins and bullets
- Slides: rendering - scaled gradients, embedded fonts, complex-script shaping, chart plot layouts and legends, theme-override colors
- Shell: open documents by dropping them onto the window; per-type document icons for OS file associations
- AI: localized busy message for overloaded providers; degenerate tool loops stopped with a unified turn budget
- Markdown: prompts to save before pasting images into untitled documents

Co-authored-by: GenOffice <merrick-2002@users.noreply.github.com>
2026-08-30 21:26:55 +08:00

55 lines
2.4 KiB
TypeScript

import { Editor } from '@tiptap/core'
import { TextSelection } from '@tiptap/pm/state'
import { parseDocx, type Run } from '@genoffice/docx-engine'
import { describe, expect, it } from 'vitest'
import { buildDocx } from '../../../packages/docx-engine/tests/helpers/build-docx'
import { blocksToPmDoc, pmDocToSavePlan, type PmNode } from '../src/renderer/editor/convert'
import { editorExtensions } from '../src/renderer/editor/extensions'
// w:rtl is a run-managed rPr group on the generate side: when a block is
// regenerated after a real edit, the flag must come back from the PM model
// or every rtl run silently turns ltr (Word then reads w:b instead of w:bCs).
const BODY =
'<w:p><w:r><w:rPr><w:rtl/><w:bCs/></w:rPr><w:t>مرحبا بالعالم</w:t></w:r>' +
'<w:r><w:t xml:space="preserve"> plain tail</w:t></w:r></w:p>'
async function openDoc() {
const source = await buildDocx({ bodyXml: BODY })
const parsed = await parseDocx(source)
const editor = new Editor({
element: document.createElement('div'),
extensions: editorExtensions,
content: blocksToPmDoc(parsed.blocks) as never,
})
return { editor, parsed }
}
describe('run-level w:rtl survives block regeneration', () => {
it('an untouched save keeps the block on the original-bytes path', async () => {
const { editor, parsed } = await openDoc()
const plan = pmDocToSavePlan(editor.state.doc.toJSON() as PmNode, parsed.blocks)
expect(plan.changedCount).toBe(0)
})
it('a real edit regenerates the paragraph with w:rtl intact', async () => {
const { editor, parsed } = await openDoc()
let at = -1
editor.state.doc.descendants((node, pos) => {
if (node.isText && node.text === ' plain tail') at = pos + node.text.length
})
expect(at).toBeGreaterThan(-1)
editor.view.dispatch(
editor.state.tr.setSelection(TextSelection.create(editor.state.doc, at)).insertText('X', at),
)
const plan = pmDocToSavePlan(editor.state.doc.toJSON() as PmNode, parsed.blocks)
expect(plan.changedCount).toBe(1)
const generated = plan.saveBlocks.find((b) => b.kind === 'generated')
expect(generated).toBeTruthy()
const runs = (generated as { block: { runs: Run[] } }).block.runs
expect(runs.map((r) => r.text).join('')).toBe('مرحبا بالعالم plain tailX')
const rtlRun = runs.find((r) => r.text.startsWith('مرحبا'))
expect(rtlRun?.rtl).toBe(true)
expect(rtlRun?.cs).toBe(true)
})
})