b33d2e7b34
Deliver P5 writer workflow: writing cockpit, manual knowledge CRUD with review, chapter bridge with optional AI, publish status, and stock buffer reminders. Co-authored-by: Cursor <cursoragent@cursor.com>
36 lines
1.5 KiB
TypeScript
36 lines
1.5 KiB
TypeScript
import { describe, it, expect, 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 { CockpitService } from '../../src/main/services/cockpit.service'
|
|
import { GlobalSettingsService } from '../../src/main/services/global-settings'
|
|
import type { SqliteDb } from '../../src/main/db/types'
|
|
import { mkdtempSync, rmSync } from 'fs'
|
|
import { join } from 'path'
|
|
import { tmpdir } from 'os'
|
|
|
|
describe('CockpitService', () => {
|
|
let db: SqliteDb
|
|
let settingsDir: string
|
|
afterEach(() => {
|
|
db?.close()
|
|
if (settingsDir) rmSync(settingsDir, { recursive: true, force: true })
|
|
})
|
|
|
|
it('UT-COCK-01: getSummary counts words and ready stock', () => {
|
|
db = new DatabaseSync(':memory:')
|
|
migrate(db)
|
|
settingsDir = mkdtempSync(join(tmpdir(), 'bilin-cockpit-'))
|
|
const settings = new GlobalSettingsService(settingsDir)
|
|
const volId = new VolumeRepository(db).create('卷一', 0).id
|
|
const chapterRepo = new ChapterRepository(db)
|
|
const ch = chapterRepo.create(volId, 'A', 0, '<p>hello world</p>')
|
|
chapterRepo.setPublishStatus(ch.id, 'ready')
|
|
const service = new CockpitService(db, settings)
|
|
const summary = service.getSummary(volId)
|
|
expect(summary.totalWords).toBeGreaterThan(0)
|
|
expect(summary.stockReadyCount).toBe(1)
|
|
})
|
|
})
|