aac51bf183
Implement schema v2 migration, outline/setting/inspiration CRUD, unified TipTap editing, reference panel with mentions, FTS global search, chapter version history, writing landmarks, word frequency analysis, light theme contrast fixes, and full unit/E2E test coverage. Co-authored-by: Cursor <cursoragent@cursor.com>
46 lines
1.5 KiB
TypeScript
46 lines
1.5 KiB
TypeScript
import { describe, it, expect, beforeEach, afterEach } from 'vitest'
|
|
import { DatabaseSync } from 'node:sqlite'
|
|
import { migrate } from '../../src/main/db/migrate'
|
|
import { SnapshotRepository } from '../../src/main/db/repositories/snapshot.repo'
|
|
import { VolumeRepository } from '../../src/main/db/repositories/volume.repo'
|
|
import { ChapterRepository } from '../../src/main/db/repositories/chapter.repo'
|
|
import type { SqliteDb } from '../../src/main/db/types'
|
|
|
|
describe('SnapshotRepository', () => {
|
|
let db: SqliteDb
|
|
let repo: SnapshotRepository
|
|
let chapterId: string
|
|
|
|
beforeEach(() => {
|
|
db = new DatabaseSync(':memory:')
|
|
migrate(db)
|
|
repo = new SnapshotRepository(db)
|
|
const vol = new VolumeRepository(db).create('卷一', 0)
|
|
chapterId = new ChapterRepository(db).create(vol.id, '第一章', 0, '初始内容').id
|
|
})
|
|
|
|
afterEach(() => {
|
|
db.close()
|
|
})
|
|
|
|
it('creates and lists snapshots', () => {
|
|
repo.create(chapterId, 'manual', '版本一', '手动保存')
|
|
expect(repo.list(chapterId)).toHaveLength(1)
|
|
expect(repo.list(chapterId)[0].name).toBe('手动保存')
|
|
})
|
|
|
|
it('prunes oldest auto snapshots', () => {
|
|
for (let i = 0; i < 5; i++) {
|
|
repo.create(chapterId, 'auto', `content-${i}`)
|
|
}
|
|
repo.pruneAuto(chapterId, 3)
|
|
const autos = repo.list(chapterId).filter((s) => s.type === 'auto')
|
|
expect(autos).toHaveLength(3)
|
|
})
|
|
|
|
it('restores snapshot content', () => {
|
|
const snap = repo.create(chapterId, 'manual', '可恢复内容')
|
|
expect(repo.restore(snap.id)).toBe('可恢复内容')
|
|
})
|
|
})
|