Sync snapshot (2026-08-04) (#19)
- Docs: paragraph writing direction (LTR/RTL) toggle with auto-detection - Docs: hardened file lifecycle, docx fidelity, and editor performance - PDF: Export as Word via cloud conversion, non-destructive Save As, and an in-progress export dialog - Slides: treat full-page background shapes as the page background - Sheets: faster recalculation with a session-resident engine; better xlsx compatibility (builtin number formats, auto-fit row heights, sheet-name resolution) - AI: surface stream and gateway errors instead of finishing empty turns; parse non-SSE JSON gateway replies; stall watchdogs - Fixes from alpha feedback batches 3 and 4 (TOC levels, Windows menus, honest AI applies, login flow diagnostics, credits-exhausted notice) - CI: sheets save round-trip E2E and xlsx compatibility corpus gate - Start the 0.5 release train (v0.5.0/v0.5.1) Co-authored-by: GenOffice <merrick-2002@users.noreply.github.com>
This commit is contained in:
co-authored by
GenOffice
parent
4da673d4df
commit
8f523289d6
@@ -0,0 +1,95 @@
|
||||
import { describe, expect, it } from 'vitest'
|
||||
|
||||
import { buildContextMenuItems, contextMenuLabels } from '../src/index'
|
||||
|
||||
const labels = contextMenuLabels('en')
|
||||
|
||||
const flags = (
|
||||
overrides: Partial<{ canCut: boolean; canCopy: boolean; canPaste: boolean }> = {},
|
||||
) => ({
|
||||
canUndo: false,
|
||||
canRedo: false,
|
||||
canCut: true,
|
||||
canCopy: true,
|
||||
canPaste: true,
|
||||
canDelete: false,
|
||||
canSelectAll: true,
|
||||
canEditRichly: false,
|
||||
...overrides,
|
||||
})
|
||||
|
||||
const base = {
|
||||
isEditable: false,
|
||||
selectionText: '',
|
||||
misspelledWord: '',
|
||||
dictionarySuggestions: [] as string[],
|
||||
editFlags: flags(),
|
||||
}
|
||||
|
||||
describe('buildContextMenuItems', () => {
|
||||
it('builds the full edit set for editable targets', () => {
|
||||
const items = buildContextMenuItems({ ...base, isEditable: true }, labels)
|
||||
expect(items).toEqual([
|
||||
{ action: 'cut', label: 'Cut', enabled: true },
|
||||
{ action: 'copy', label: 'Copy', enabled: true },
|
||||
{ action: 'paste', label: 'Paste', enabled: true },
|
||||
{ type: 'separator' },
|
||||
{ action: 'selectAll', label: 'Select All', enabled: true },
|
||||
])
|
||||
})
|
||||
|
||||
it('disables items per editFlags', () => {
|
||||
const items = buildContextMenuItems(
|
||||
{ ...base, isEditable: true, editFlags: flags({ canCut: false, canPaste: false }) },
|
||||
labels,
|
||||
)
|
||||
expect(items).toContainEqual({ action: 'cut', label: 'Cut', enabled: false })
|
||||
expect(items).toContainEqual({ action: 'paste', label: 'Paste', enabled: false })
|
||||
})
|
||||
|
||||
it('prepends spelling suggestions when a word is misspelled', () => {
|
||||
const items = buildContextMenuItems(
|
||||
{
|
||||
...base,
|
||||
isEditable: true,
|
||||
misspelledWord: 'helo',
|
||||
dictionarySuggestions: ['hello', 'halo'],
|
||||
},
|
||||
labels,
|
||||
)
|
||||
expect(items.slice(0, 3)).toEqual([
|
||||
{ action: 'replaceMisspelling', label: 'hello' },
|
||||
{ action: 'replaceMisspelling', label: 'halo' },
|
||||
{ type: 'separator' },
|
||||
])
|
||||
})
|
||||
|
||||
it('skips the suggestion block when there are no suggestions', () => {
|
||||
const items = buildContextMenuItems(
|
||||
{ ...base, isEditable: true, misspelledWord: 'zqx' },
|
||||
labels,
|
||||
)
|
||||
expect(items[0]).toEqual({ action: 'cut', label: 'Cut', enabled: true })
|
||||
})
|
||||
|
||||
it('offers copy/select-all for non-editable selections', () => {
|
||||
const items = buildContextMenuItems({ ...base, selectionText: 'some text' }, labels)
|
||||
expect(items).toEqual([
|
||||
{ action: 'copy', label: 'Copy', enabled: true },
|
||||
{ action: 'selectAll', label: 'Select All', enabled: true },
|
||||
])
|
||||
})
|
||||
|
||||
it('returns nothing for non-editable targets without selection', () => {
|
||||
expect(buildContextMenuItems(base, labels)).toEqual([])
|
||||
expect(buildContextMenuItems({ ...base, selectionText: ' ' }, labels)).toEqual([])
|
||||
})
|
||||
})
|
||||
|
||||
describe('contextMenuLabels', () => {
|
||||
it('covers every language and falls back to English', () => {
|
||||
expect(contextMenuLabels('zh').copy).toBe('复制')
|
||||
expect(contextMenuLabels('zh-TW').paste).toBe('貼上')
|
||||
expect(contextMenuLabels('xx')).toEqual(contextMenuLabels('en'))
|
||||
})
|
||||
})
|
||||
Reference in New Issue
Block a user