- **New app: GenOffice HTML.** Open, edit and generate .html pages: a source pane with a sandboxed live preview, click-to-select elements with a floating toolbar and style panel, device-size preview, image tools and a present mode. AI generates whole pages from a brief with style directions and offers page-wide Restyle, Theme and Summarize. Export to Word runs locally through the built-in html2docx converter (native, editable OOXML; no print-to-PDF detour). - **AI:** separate BYOK providers for web search, image generation and image/video analysis; new Codex App Server provider; Ask AI quotes the selected text and keeps it highlighted while it runs; custom AI panel text size; blocked requests retry through the Chromium network stack. - **App:** global AutoSave setting shared by every editor; AI panel text size and chat spellcheck toggles (genoffice#249); Czech (cs) UI locale (genoffice#259); Save As defaults to the document's folder; PDF export no longer aborts on CJK file paths on Windows. - **Docs:** Export as HTML; comments and replies edit in place from the comments pane; the caret can leave a trailing table (genoffice#266); spellcheck re-marks text as soon as it is re-enabled; AI edits are character-precise on partial selections; zoom keeps the scroll position; pasting a cell from Sheets takes the destination font. - **Sheets:** Find no longer freezes on wide or streamed grids; Replace searches as you type; cached values of external-workbook formulas are kept instead of #ERROR! (genoffice#235); "number stored as text" is a warning, not an error (genoffice#236); paste repeats into the target range like Excel; filter criteria survive save/reopen; saves retry when Windows locks the file; many Excel-fidelity fixes for column widths, row heights, charts, slicers, number formats and CJK fonts. - **Slides:** PDF export works for large presentations (genoffice#264); EMF/WMF picture fonts and East Asian theme fonts resolve correctly; decks with missing layouts or embedded styles still open; outline-only pie slices render. - **PDF:** highlight and underline geometry aligns with the text; Shift+arrows extend the selection instead of paging. - **Markdown:** Find and replace (Ctrl+F / Ctrl+H) (genoffice#253); mermaid code blocks render as diagrams (genoffice#263); better print quality. - Thanks to community contributors @GoodScholar, @aniruddhaadak80 and @Sun8854, and to @hanyscz, @qgzln, @zyp997, @bisslot, @krakotay and @Ben03151 for the reports. Co-authored-by: GenOffice <merrick-2002@users.noreply.github.com>
148 lines
6.8 KiB
TypeScript
148 lines
6.8 KiB
TypeScript
import { join } from 'node:path'
|
|
|
|
import { describe, expect, it, vi } from 'vitest'
|
|
|
|
import { saveAsSuggestion, showOpenDialogWithMemory, showSaveDialogWithMemory } from '../src/index'
|
|
|
|
import type { Dialog } from 'electron'
|
|
|
|
function fakeDialog(overrides: Partial<Dialog> = {}): Dialog {
|
|
return {
|
|
showOpenDialog: vi.fn().mockResolvedValue({ canceled: true, filePaths: [] }),
|
|
showSaveDialog: vi.fn().mockResolvedValue({ canceled: true, filePath: '' }),
|
|
...overrides,
|
|
} as unknown as Dialog
|
|
}
|
|
|
|
const pickedOpen = (paths: string[]) =>
|
|
vi.fn().mockResolvedValue({ canceled: false, filePaths: paths })
|
|
const pickedSave = (path: string) => vi.fn().mockResolvedValue({ canceled: false, filePath: path })
|
|
|
|
describe('showOpenDialogWithMemory', () => {
|
|
it('passes options through unchanged before any pick was made', async () => {
|
|
const dialog = fakeDialog()
|
|
await showOpenDialogWithMemory(dialog, undefined, { properties: ['openFile'] })
|
|
expect(dialog.showOpenDialog).toHaveBeenCalledWith({ properties: ['openFile'] })
|
|
})
|
|
|
|
it('remembers the picked directory and injects it as defaultPath next time', async () => {
|
|
const dialog = fakeDialog({ showOpenDialog: pickedOpen([join('/work', 'report.docx')]) })
|
|
await showOpenDialogWithMemory(dialog, undefined, {})
|
|
await showOpenDialogWithMemory(dialog, undefined, {})
|
|
expect(dialog.showOpenDialog).toHaveBeenLastCalledWith({ defaultPath: '/work' })
|
|
})
|
|
|
|
it('forwards the parent window when given', async () => {
|
|
const dialog = fakeDialog()
|
|
const parent = { id: 1 } as never
|
|
await showOpenDialogWithMemory(dialog, parent, {})
|
|
expect(dialog.showOpenDialog).toHaveBeenCalledWith(parent, {})
|
|
})
|
|
|
|
it('remembers the selected directory itself for openDirectory pickers', async () => {
|
|
const dialog = fakeDialog({ showOpenDialog: pickedOpen(['/exports/images']) })
|
|
await showOpenDialogWithMemory(dialog, undefined, { properties: ['openDirectory'] })
|
|
await showOpenDialogWithMemory(dialog, undefined, {})
|
|
expect(dialog.showOpenDialog).toHaveBeenLastCalledWith({ defaultPath: '/exports/images' })
|
|
})
|
|
|
|
it('keeps an explicit absolute defaultPath untouched', async () => {
|
|
const dialog = fakeDialog({ showOpenDialog: pickedOpen([join('/work', 'a.docx')]) })
|
|
await showOpenDialogWithMemory(dialog, undefined, {})
|
|
await showOpenDialogWithMemory(dialog, undefined, { defaultPath: '/elsewhere/b.docx' })
|
|
expect(dialog.showOpenDialog).toHaveBeenLastCalledWith({ defaultPath: '/elsewhere/b.docx' })
|
|
})
|
|
|
|
it('does not remember canceled picks', async () => {
|
|
const dialog = fakeDialog()
|
|
await showOpenDialogWithMemory(dialog, undefined, {})
|
|
await showOpenDialogWithMemory(dialog, undefined, {})
|
|
expect(dialog.showOpenDialog).toHaveBeenLastCalledWith({})
|
|
})
|
|
})
|
|
|
|
describe('showSaveDialogWithMemory', () => {
|
|
it('anchors a bare file-name suggestion in the remembered directory', async () => {
|
|
const dialog = fakeDialog({ showSaveDialog: pickedSave(join('/work', 'deck.pptx')) })
|
|
await showSaveDialogWithMemory(dialog, undefined, { defaultPath: 'deck.pptx' })
|
|
await showSaveDialogWithMemory(dialog, undefined, { defaultPath: 'deck2.pptx' })
|
|
expect(dialog.showSaveDialog).toHaveBeenLastCalledWith({
|
|
defaultPath: join('/work', 'deck2.pptx'),
|
|
})
|
|
})
|
|
|
|
it('shares the remembered directory between save and open dialogs', async () => {
|
|
const dialog = fakeDialog({ showSaveDialog: pickedSave(join('/work', 'deck.pptx')) })
|
|
await showSaveDialogWithMemory(dialog, undefined, { defaultPath: 'deck.pptx' })
|
|
await showOpenDialogWithMemory(dialog, undefined, {})
|
|
expect(dialog.showOpenDialog).toHaveBeenCalledWith({ defaultPath: '/work' })
|
|
})
|
|
|
|
it('keeps an explicit absolute defaultPath untouched', async () => {
|
|
const dialog = fakeDialog({ showSaveDialog: pickedSave(join('/work', 'a.pdf')) })
|
|
await showSaveDialogWithMemory(dialog, undefined, { defaultPath: '/docs/tab.pdf' })
|
|
expect(dialog.showSaveDialog).toHaveBeenCalledWith({ defaultPath: '/docs/tab.pdf' })
|
|
})
|
|
|
|
it('isolates memory between different dialog instances', async () => {
|
|
const first = fakeDialog({ showOpenDialog: pickedOpen([join('/work', 'a.docx')]) })
|
|
const second = fakeDialog()
|
|
await showOpenDialogWithMemory(first, undefined, {})
|
|
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' })
|
|
})
|
|
})
|
|
|
|
describe('saveAsSuggestion', () => {
|
|
it('suggests the source document folder with the new name (Word parity)', () => {
|
|
expect(saveAsSuggestion(join('/work', 'report.docx'), 'report.docx')).toBe(
|
|
join('/work', 'report.docx'),
|
|
)
|
|
expect(saveAsSuggestion(join('/work', 'report.docx'), 'copy.docx')).toBe(
|
|
join('/work', 'copy.docx'),
|
|
)
|
|
})
|
|
|
|
it('falls back to the bare name for a document that was never on disk', () => {
|
|
expect(saveAsSuggestion(null, 'Untitled.docx')).toBe('Untitled.docx')
|
|
expect(saveAsSuggestion(undefined, 'Untitled.docx')).toBe('Untitled.docx')
|
|
expect(saveAsSuggestion('', 'Untitled.pptx')).toBe('Untitled.pptx')
|
|
})
|
|
|
|
it('beats the remembered directory when threaded through the save dialog', async () => {
|
|
const dialog = fakeDialog({ showSaveDialog: pickedSave(join('/elsewhere', 'x.docx')) })
|
|
// a pick in /elsewhere seeds the remembered directory…
|
|
await showSaveDialogWithMemory(dialog, undefined, { defaultPath: 'x.docx' })
|
|
// …but Save As of a document living in /work still opens in /work
|
|
await showSaveDialogWithMemory(dialog, undefined, {
|
|
defaultPath: saveAsSuggestion(join('/work', 'report.docx'), 'report.docx'),
|
|
})
|
|
expect(dialog.showSaveDialog).toHaveBeenLastCalledWith({
|
|
defaultPath: join('/work', 'report.docx'),
|
|
})
|
|
})
|
|
})
|