Files
genoffice/apps/docs/tests/doc-dirty.test.ts
T
merrick-2002andGenOffice fe2e17403c Sync snapshot (2026-08-19) (#110)
- Improve Docs pagination, anchored-object fidelity, password protection, recovery safety, and multilingual font fallback
- Scale Sheets editing and saves for large workbooks with safer AI bulk operations, aggregation, undo, recovery, and richer visual fidelity
- Expand Slides fidelity with 3D rendering, SmartArt and WordArt improvements, pattern and texture fills, and resource cleanup
- Add AI PDF creation, text insertion, reading-position restore, safer atomic saves, and improved comments and page workflows
- Add Markdown math rendering and protect linked assets across save, conversion, and document lifecycle operations
- Read legacy DOC and PPT attachments locally and strengthen document package resource cleanup
- Document default-on usage analytics with a persistent Settings opt-out and a dedicated, tested privacy page

Co-authored-by: GenOffice <merrick-2002@users.noreply.github.com>
2026-08-19 20:14:50 +08:00

77 lines
2.7 KiB
TypeScript

import { describe, expect, it } from 'vitest'
import { isDocDirty, type DocDirtyState } from '../src/renderer/doc-dirty'
import { openedFileStartsDirty } from '../src/renderer/doc-state'
function cleanState(): DocDirtyState {
return {
dirtyRef: { current: false },
sectionDirty: false,
sectionsDirty: [],
trailingStartType: null,
pageColorDirty: false,
headerDirty: false,
footerDirty: false,
hfVariantsDirty: [],
sectionHfEdits: {},
pgNumEdit: null,
pgNumDirtySections: [],
numberingDirty: false,
styleUpserts: {},
titlePgDirty: false,
evenOddHfDirty: false,
watermarkDirty: false,
inksDirty: false,
notesDirty: false,
sourcesDirty: false,
themeFontsDirty: false,
themeColorsDirty: false,
commentsDirty: false,
protectionDirty: false,
}
}
describe('isDocDirty', () => {
it('is false for a fully clean state', () => {
expect(isDocDirty(cleanState())).toBe(false)
})
it('is true when only the body changed', () => {
expect(isDocDirty({ ...cleanState(), dirtyRef: { current: true } })).toBe(true)
})
it('treats restored recovery content as unsaved body content', () => {
const state = cleanState()
state.dirtyRef.current = openedFileStartsDirty({ recovered: true })
expect(isDocDirty(state)).toBe(true)
expect(openedFileStartsDirty({})).toBe(false)
})
// the regression: autosave ignored comment/protection edits; the recovery push ignored everything but the body
it.each([
['commentsDirty', { commentsDirty: true }],
['protectionDirty', { protectionDirty: true }],
['sectionDirty', { sectionDirty: true }],
['headerDirty', { headerDirty: true }],
['footerDirty', { footerDirty: true }],
['pageColorDirty', { pageColorDirty: true }],
['titlePgDirty', { titlePgDirty: true }],
['evenOddHfDirty', { evenOddHfDirty: true }],
['watermarkDirty', { watermarkDirty: true }],
['inksDirty', { inksDirty: true }],
['notesDirty', { notesDirty: true }],
['sourcesDirty', { sourcesDirty: true }],
['themeFontsDirty', { themeFontsDirty: true }],
['themeColorsDirty', { themeColorsDirty: true }],
['numberingDirty', { numberingDirty: true }],
['sectionsDirty', { sectionsDirty: [1] }],
['hfVariantsDirty', { hfVariantsDirty: ['headerFirst'] }],
['pgNumDirtySections', { pgNumDirtySections: [0] }],
['sectionHfEdits', { sectionHfEdits: { '3:header': {} } }],
['styleUpserts', { styleUpserts: { Heading1: {} } }],
['pgNumEdit', { pgNumEdit: { fmt: 'decimal' } }],
['trailingStartType', { trailingStartType: 'nextPage' }],
] as const)('is true when only %s changed', (_name, patch) => {
expect(isDocDirty({ ...cleanState(), ...patch })).toBe(true)
})
})