feat: deliver P2 v0.2.0 with unified editor, search, and snapshots
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>
This commit is contained in:
@@ -0,0 +1,41 @@
|
||||
import { describe, it, expect, beforeEach, afterEach } from 'vitest'
|
||||
import { DatabaseSync } from 'node:sqlite'
|
||||
import { migrate } from '../../src/main/db/migrate'
|
||||
import { VolumeRepository } from '../../src/main/db/repositories/volume.repo'
|
||||
import { ChapterRepository } from '../../src/main/db/repositories/chapter.repo'
|
||||
import { wordFreqService } from '../../src/main/services/wordfreq.service'
|
||||
import type { SqliteDb } from '../../src/main/db/types'
|
||||
|
||||
describe('WordFreqService', () => {
|
||||
let db: SqliteDb
|
||||
|
||||
beforeEach(() => {
|
||||
db = new DatabaseSync(':memory:')
|
||||
migrate(db)
|
||||
const vol = new VolumeRepository(db).create('卷一', 0)
|
||||
new ChapterRepository(db).create(
|
||||
vol.id,
|
||||
'第一章',
|
||||
0,
|
||||
'<p>林远走进青云山。The hero walked slowly.</p>'
|
||||
)
|
||||
})
|
||||
|
||||
afterEach(() => {
|
||||
db.close()
|
||||
})
|
||||
|
||||
it('counts CJK characters and latin words', () => {
|
||||
const result = wordFreqService.analyze(db, { kind: 'book' })
|
||||
expect(result.words.length).toBeGreaterThan(0)
|
||||
const tokens = result.words.map((w) => w.token)
|
||||
expect(tokens).toContain('林')
|
||||
expect(tokens).toContain('the')
|
||||
})
|
||||
|
||||
it('analyzes single chapter scope', () => {
|
||||
const ch = (db.prepare('SELECT id FROM chapters LIMIT 1').get() as { id: string }).id
|
||||
const result = wordFreqService.analyze(db, { kind: 'chapter', chapterId: ch })
|
||||
expect(result.words.length).toBeGreaterThan(0)
|
||||
})
|
||||
})
|
||||
Reference in New Issue
Block a user