fe421ffc55
Co-authored-by: Cursor <cursoragent@cursor.com>
34 lines
1.2 KiB
TypeScript
34 lines
1.2 KiB
TypeScript
import { describe, it, expect, beforeEach, afterEach } from 'vitest'
|
|
import { DatabaseSync } from 'node:sqlite'
|
|
import { migrate } from '../../src/main/db/migrate'
|
|
import { UndoStackService } from '../../src/main/services/undo-stack.service'
|
|
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('UndoStackService', () => {
|
|
let db: SqliteDb
|
|
let svc: UndoStackService
|
|
let chapterId: string
|
|
|
|
beforeEach(() => {
|
|
db = new DatabaseSync(':memory:')
|
|
migrate(db)
|
|
svc = new UndoStackService(db)
|
|
const vol = new VolumeRepository(db).create('卷一', 0)
|
|
chapterId = new ChapterRepository(db).create(vol.id, '第一章', 0).id
|
|
})
|
|
|
|
afterEach(() => {
|
|
db.close()
|
|
})
|
|
|
|
it('UT-UNDO-01: push and list undo entries', () => {
|
|
svc.push(chapterId, { type: 'doc', content: '<p>旧内容</p>' })
|
|
svc.push(chapterId, { type: 'doc', content: '<p>新内容</p>' })
|
|
const list = svc.list(chapterId)
|
|
expect(list).toHaveLength(2)
|
|
expect(list[0]?.operation.content).toContain('新内容')
|
|
})
|
|
})
|