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,124 @@
|
||||
import { describe, expect, it } from 'vitest'
|
||||
|
||||
import {
|
||||
appMenuLabels,
|
||||
editMenuTemplate,
|
||||
viewMenuTemplate,
|
||||
windowMenuTemplate,
|
||||
type AppMenuLabels,
|
||||
} from '../src/index'
|
||||
|
||||
const LANGS = [
|
||||
'zh',
|
||||
'en',
|
||||
'ja',
|
||||
'ko',
|
||||
'fr',
|
||||
'de',
|
||||
'es',
|
||||
'th',
|
||||
'id',
|
||||
'ru',
|
||||
'ar',
|
||||
'pt',
|
||||
'it',
|
||||
'pl',
|
||||
'nl',
|
||||
'ms',
|
||||
'he',
|
||||
'hi',
|
||||
'zh-TW',
|
||||
] as const
|
||||
|
||||
const en = appMenuLabels('en')
|
||||
|
||||
type Item = { role?: string; type?: string; label?: string; accelerator?: string }
|
||||
const submenuOf = (tpl: { submenu?: unknown }): Item[] => tpl.submenu as Item[]
|
||||
|
||||
describe('appMenuLabels', () => {
|
||||
it('covers all 19 languages with every key non-empty', () => {
|
||||
const keys = Object.keys(en) as (keyof AppMenuLabels)[]
|
||||
for (const lang of LANGS) {
|
||||
const labels = appMenuLabels(lang)
|
||||
for (const key of keys) expect(labels[key], `${lang}.${key}`).toBeTruthy()
|
||||
}
|
||||
})
|
||||
|
||||
it('falls back to English for unknown languages', () => {
|
||||
expect(appMenuLabels('xx')).toEqual(en)
|
||||
})
|
||||
|
||||
it('merges the context-menu clipboard labels', () => {
|
||||
const zh = appMenuLabels('zh')
|
||||
expect(zh.copy).toBe('复制')
|
||||
expect(zh.selectAll).toBe('全选')
|
||||
})
|
||||
})
|
||||
|
||||
describe('windowMenuTemplate', () => {
|
||||
it('keeps the native role on macOS', () => {
|
||||
expect(windowMenuTemplate('darwin', en)).toEqual({ role: 'windowMenu', label: 'Window' })
|
||||
})
|
||||
|
||||
it.each(['win32', 'linux'] as const)('builds Minimize/Close only on %s', (platform) => {
|
||||
const tpl = windowMenuTemplate(platform, en)
|
||||
expect(tpl.role).toBeUndefined()
|
||||
expect(tpl.label).toBe('Window')
|
||||
const items = submenuOf(tpl)
|
||||
expect(items.map((i) => i.label ?? i.type)).toEqual(['Minimize', 'separator', 'Close Window'])
|
||||
// no mac-only entries, no roles, no Ctrl+M
|
||||
for (const item of items) {
|
||||
expect(item.role).toBeUndefined()
|
||||
expect(item.accelerator).toBeUndefined()
|
||||
expect(item.label ?? '').not.toMatch(/zoom|front/i)
|
||||
}
|
||||
})
|
||||
|
||||
it('localizes the Windows submenu', () => {
|
||||
const items = submenuOf(windowMenuTemplate('win32', appMenuLabels('zh')))
|
||||
expect(items[0]!.label).toBe('最小化')
|
||||
expect(items[2]!.label).toBe('关闭窗口')
|
||||
})
|
||||
})
|
||||
|
||||
describe('editMenuTemplate', () => {
|
||||
it('keeps the native role on macOS', () => {
|
||||
expect(editMenuTemplate('darwin', en)).toEqual({ role: 'editMenu', label: 'Edit' })
|
||||
})
|
||||
|
||||
it('mirrors the non-mac role expansion with labeled roles on Windows', () => {
|
||||
const tpl = editMenuTemplate('win32', en)
|
||||
expect(tpl.label).toBe('Edit')
|
||||
expect(submenuOf(tpl).map((i) => i.role ?? i.type)).toEqual([
|
||||
'undo',
|
||||
'redo',
|
||||
'separator',
|
||||
'cut',
|
||||
'copy',
|
||||
'paste',
|
||||
'delete',
|
||||
'separator',
|
||||
'selectAll',
|
||||
])
|
||||
for (const item of submenuOf(tpl)) if (item.role) expect(item.label).toBeTruthy()
|
||||
})
|
||||
})
|
||||
|
||||
describe('viewMenuTemplate', () => {
|
||||
it('mirrors the viewMenu role expansion with labeled roles', () => {
|
||||
const tpl = viewMenuTemplate(en)
|
||||
expect(tpl.label).toBe('View')
|
||||
expect(submenuOf(tpl).map((i) => i.role ?? i.type)).toEqual([
|
||||
'reload',
|
||||
'forceReload',
|
||||
'toggleDevTools',
|
||||
'separator',
|
||||
'resetZoom',
|
||||
'zoomIn',
|
||||
'zoomOut',
|
||||
'separator',
|
||||
'togglefullscreen',
|
||||
])
|
||||
for (const item of submenuOf(tpl)) if (item.role) expect(item.label).toBeTruthy()
|
||||
})
|
||||
})
|
||||
@@ -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