Sync snapshot (2026-08-10) (#80)
- Improve DOCX rendering fidelity, pagination, image handling, and Markdown paste - Expand PDF text editing with paragraph reflow, style preservation, and more reliable text matching - Harden XLSX sheet deletion, localized date formats, multi-row autofit, charts, and system font support - Add inline AI turn rollback and sent-attachment visibility across editors - Add Office-style ScreenTips and refine ribbons, dialogs, menus, and themes - Improve Slides cropping, rotate and flip tools, printing, animations, and editing workflows - Add shell settings, configurable save locations, account credits, and update recovery guidance - Add Intel macOS and RPM download support and refresh public documentation Co-authored-by: GenOffice <merrick-2002@users.noreply.github.com>
This commit is contained in:
co-authored by
GenOffice
parent
fd33934dab
commit
7023e635bd
@@ -1,4 +1,14 @@
|
||||
import { describe, expect, it } from 'vitest'
|
||||
import { beforeEach, describe, expect, it, vi } from 'vitest'
|
||||
|
||||
const electronMock = vi.hoisted(() => ({
|
||||
getFocusedWebContents: vi.fn(),
|
||||
}))
|
||||
|
||||
vi.mock('electron', () => ({
|
||||
webContents: {
|
||||
getFocusedWebContents: electronMock.getFocusedWebContents,
|
||||
},
|
||||
}))
|
||||
|
||||
import {
|
||||
appMenuLabels,
|
||||
@@ -35,6 +45,10 @@ const en = appMenuLabels('en')
|
||||
type Item = { role?: string; type?: string; label?: string; accelerator?: string }
|
||||
const submenuOf = (tpl: { submenu?: unknown }): Item[] => tpl.submenu as Item[]
|
||||
|
||||
beforeEach(() => {
|
||||
vi.clearAllMocks()
|
||||
})
|
||||
|
||||
describe('appMenuLabels', () => {
|
||||
it('covers all 19 languages with every key non-empty', () => {
|
||||
const keys = Object.keys(en) as (keyof AppMenuLabels)[]
|
||||
@@ -108,10 +122,10 @@ 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([
|
||||
expect(submenuOf(tpl).map((i) => i.role ?? i.type ?? i.label)).toEqual([
|
||||
'reload',
|
||||
'forceReload',
|
||||
'toggleDevTools',
|
||||
'Developer Tools',
|
||||
'separator',
|
||||
'resetZoom',
|
||||
'zoomIn',
|
||||
@@ -121,4 +135,31 @@ describe('viewMenuTemplate', () => {
|
||||
])
|
||||
for (const item of submenuOf(tpl)) if (item.role) expect(item.label).toBeTruthy()
|
||||
})
|
||||
|
||||
it('opens DevTools via an explicit click item, not the docking role', () => {
|
||||
const item = submenuOf(viewMenuTemplate(en))[2] as Item & { click?: unknown }
|
||||
expect(item.role).toBeUndefined()
|
||||
expect(typeof item.click).toBe('function')
|
||||
expect(item.accelerator).toBe(process.platform === 'darwin' ? 'Alt+Command+I' : 'Ctrl+Shift+I')
|
||||
})
|
||||
|
||||
it('closes detached DevTools when they have focus', async () => {
|
||||
const target = {
|
||||
devToolsWebContents: {},
|
||||
isDestroyed: vi.fn(() => false),
|
||||
isDevToolsOpened: vi.fn().mockReturnValueOnce(false).mockReturnValueOnce(true),
|
||||
openDevTools: vi.fn(),
|
||||
closeDevTools: vi.fn(),
|
||||
}
|
||||
electronMock.getFocusedWebContents.mockReturnValueOnce(target).mockReturnValueOnce(null)
|
||||
const item = submenuOf(viewMenuTemplate(en))[2] as Item & {
|
||||
click: () => Promise<void>
|
||||
}
|
||||
|
||||
await item.click()
|
||||
await item.click()
|
||||
|
||||
expect(target.openDevTools).toHaveBeenCalledWith({ mode: 'detach' })
|
||||
expect(target.closeDevTools).toHaveBeenCalledOnce()
|
||||
})
|
||||
})
|
||||
|
||||
@@ -0,0 +1,97 @@
|
||||
import { chmodSync, existsSync, mkdirSync, mkdtempSync, rmSync, writeFileSync } from 'node:fs'
|
||||
import { tmpdir } from 'node:os'
|
||||
import { join } from 'node:path'
|
||||
|
||||
import { afterEach, beforeEach, describe, expect, it } from 'vitest'
|
||||
|
||||
import {
|
||||
configuredDefaultSaveDir,
|
||||
readDefaultSaveDirSetting,
|
||||
resolveDefaultSaveDir,
|
||||
} from '../src/index'
|
||||
|
||||
let root: string
|
||||
|
||||
beforeEach(() => {
|
||||
root = mkdtempSync(join(tmpdir(), 'genoffice-save-dir-'))
|
||||
})
|
||||
|
||||
afterEach(() => {
|
||||
rmSync(root, { recursive: true, force: true })
|
||||
})
|
||||
|
||||
describe('readDefaultSaveDirSetting', () => {
|
||||
const settingsPath = () => join(root, 'app-settings.json')
|
||||
|
||||
it('returns the configured absolute path', () => {
|
||||
writeFileSync(settingsPath(), JSON.stringify({ defaultSaveDir: '/some/where' }))
|
||||
expect(readDefaultSaveDirSetting(settingsPath())).toBe('/some/where')
|
||||
})
|
||||
|
||||
it('returns null when the file is missing, corrupt, or the key is absent', () => {
|
||||
expect(readDefaultSaveDirSetting(settingsPath())).toBeNull()
|
||||
writeFileSync(settingsPath(), 'not json')
|
||||
expect(readDefaultSaveDirSetting(settingsPath())).toBeNull()
|
||||
writeFileSync(settingsPath(), JSON.stringify({ language: 'en' }))
|
||||
expect(readDefaultSaveDirSetting(settingsPath())).toBeNull()
|
||||
})
|
||||
|
||||
it('rejects non-string and relative values', () => {
|
||||
writeFileSync(settingsPath(), JSON.stringify({ defaultSaveDir: 42 }))
|
||||
expect(readDefaultSaveDirSetting(settingsPath())).toBeNull()
|
||||
writeFileSync(settingsPath(), JSON.stringify({ defaultSaveDir: 'relative/dir' }))
|
||||
expect(readDefaultSaveDirSetting(settingsPath())).toBeNull()
|
||||
})
|
||||
})
|
||||
|
||||
describe('resolveDefaultSaveDir', () => {
|
||||
it('uses the configured folder when it is usable (creating it on demand)', () => {
|
||||
const configured = join(root, 'custom', 'nested')
|
||||
const resolved = resolveDefaultSaveDir(configured, join(root, 'fallback'))
|
||||
expect(resolved).toBe(configured)
|
||||
expect(existsSync(configured)).toBe(true)
|
||||
})
|
||||
|
||||
it('creates and returns the fallback when nothing is configured', () => {
|
||||
const fallback = join(root, 'Documents', 'GenOffice')
|
||||
expect(resolveDefaultSaveDir(null, fallback)).toBe(fallback)
|
||||
expect(existsSync(fallback)).toBe(true)
|
||||
})
|
||||
|
||||
it('degrades to the fallback when the configured folder is not writable', () => {
|
||||
const readOnly = join(root, 'read-only')
|
||||
mkdirSync(readOnly)
|
||||
chmodSync(readOnly, 0o500)
|
||||
const fallback = join(root, 'fallback')
|
||||
try {
|
||||
expect(resolveDefaultSaveDir(readOnly, fallback)).toBe(fallback)
|
||||
} finally {
|
||||
chmodSync(readOnly, 0o700)
|
||||
}
|
||||
})
|
||||
})
|
||||
|
||||
describe('configuredDefaultSaveDir', () => {
|
||||
it('reads the setting from userData/app-settings.json and honors it', () => {
|
||||
const userData = join(root, 'userData')
|
||||
const documents = join(root, 'Documents')
|
||||
mkdirSync(userData, { recursive: true })
|
||||
const custom = join(root, 'my-files')
|
||||
writeFileSync(join(userData, 'app-settings.json'), JSON.stringify({ defaultSaveDir: custom }))
|
||||
const app = {
|
||||
getPath: (name: 'userData' | 'documents') => (name === 'userData' ? userData : documents),
|
||||
}
|
||||
expect(configuredDefaultSaveDir(app)).toBe(custom)
|
||||
})
|
||||
|
||||
it('falls back to <Documents>/GenOffice without a setting', () => {
|
||||
const userData = join(root, 'userData')
|
||||
const documents = join(root, 'Documents')
|
||||
mkdirSync(userData, { recursive: true })
|
||||
const app = {
|
||||
getPath: (name: 'userData' | 'documents') => (name === 'userData' ? userData : documents),
|
||||
}
|
||||
expect(configuredDefaultSaveDir(app)).toBe(join(documents, 'GenOffice'))
|
||||
expect(existsSync(join(documents, 'GenOffice'))).toBe(true)
|
||||
})
|
||||
})
|
||||
@@ -91,4 +91,27 @@ describe('showSaveDialogWithMemory', () => {
|
||||
await showOpenDialogWithMemory(second, undefined, {})
|
||||
expect(second.showOpenDialog).toHaveBeenCalledWith({})
|
||||
})
|
||||
|
||||
it('anchors a bare file-name suggestion in the fallback dir when nothing is remembered', async () => {
|
||||
const dialog = fakeDialog()
|
||||
await showSaveDialogWithMemory(dialog, undefined, { defaultPath: 'deck.pptx' }, '/default/save')
|
||||
expect(dialog.showSaveDialog).toHaveBeenCalledWith({
|
||||
defaultPath: join('/default/save', 'deck.pptx'),
|
||||
})
|
||||
})
|
||||
|
||||
it('prefers the remembered directory over the fallback dir', async () => {
|
||||
const dialog = fakeDialog({ showSaveDialog: pickedSave(join('/work', 'deck.pptx')) })
|
||||
await showSaveDialogWithMemory(dialog, undefined, { defaultPath: 'deck.pptx' })
|
||||
await showSaveDialogWithMemory(dialog, undefined, { defaultPath: 'b.pptx' }, '/default/save')
|
||||
expect(dialog.showSaveDialog).toHaveBeenLastCalledWith({
|
||||
defaultPath: join('/work', 'b.pptx'),
|
||||
})
|
||||
})
|
||||
|
||||
it('keeps an explicit absolute defaultPath untouched even with a fallback dir', async () => {
|
||||
const dialog = fakeDialog()
|
||||
await showSaveDialogWithMemory(dialog, undefined, { defaultPath: '/docs/tab.pdf' }, '/default')
|
||||
expect(dialog.showSaveDialog).toHaveBeenCalledWith({ defaultPath: '/docs/tab.pdf' })
|
||||
})
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user