- 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>
98 lines
3.5 KiB
TypeScript
98 lines
3.5 KiB
TypeScript
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)
|
|
})
|
|
})
|