feat: 实现笔临 P0/P1 Electron 桌面应用 v0.1.0

交付写作核心(TipTap、自动保存、分卷分章)、Onboarding、7 主题与双语 i18n、快捷键设置;主进程使用 node:sqlite;补全 Vitest 与 Playwright E2E;统一 design/ 目录并移除 desigin 拼写错误路径。

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
2026-07-06 10:39:20 +08:00
parent a06038035b
commit 011bd6d4ca
70 changed files with 14245 additions and 84 deletions
+39
View File
@@ -0,0 +1,39 @@
import { describe, it, expect, beforeEach, afterEach } from 'vitest'
import { existsSync, mkdtempSync, rmSync } from 'fs'
import { join } from 'path'
import { tmpdir } from 'os'
import { BookRegistryService } from '../../src/main/services/book-registry'
import { closeAllBookDbs } from '../../src/main/db/connection'
describe('BookRegistryService', () => {
let dir: string
let svc: BookRegistryService
beforeEach(() => {
dir = mkdtempSync(join(tmpdir(), 'bilin-books-'))
svc = new BookRegistryService(dir)
})
afterEach(() => {
closeAllBookDbs()
rmSync(dir, { recursive: true, force: true })
})
it('creates book with registry entry, sqlite file, and default volume', () => {
const meta = svc.create({
name: '测试书',
category: '玄幻',
createSampleChapter: true
})
expect(meta.name).toBe('测试书')
expect(svc.list()).toHaveLength(1)
expect(existsSync(join(dir, 'books', `${meta.id}.sqlite`))).toBe(true)
const opened = svc.open(meta.id)
expect(opened.volumes).toHaveLength(1)
expect(opened.volumes[0].name).toBe('第一卷')
expect(opened.chapters.length).toBeGreaterThanOrEqual(1)
expect(meta.lastChapterId).toBeTruthy()
})
})
+28
View File
@@ -0,0 +1,28 @@
import { describe, it, expect, beforeEach, afterEach } from 'vitest'
import { DatabaseSync } from 'node:sqlite'
import { migrate } from '../../src/main/db/migrate'
import { ChapterRepository } from '../../src/main/db/repositories/chapter.repo'
import { VolumeRepository } from '../../src/main/db/repositories/volume.repo'
import type { SqliteDb } from '../../src/main/db/types'
describe('ChapterRepository', () => {
let db: SqliteDb
beforeEach(() => {
db = new DatabaseSync(':memory:')
migrate(db)
})
afterEach(() => {
db.close()
})
it('creates chapter and updates word count', () => {
const volumes = new VolumeRepository(db)
const chapters = new ChapterRepository(db)
const vol = volumes.create('第一卷', 0)
const ch = chapters.create(vol.id, '测试章', 0, '林远深吸一口气')
expect(ch.wordCount).toBe(7)
const updated = chapters.update(ch.id, { content: '<p>更长的一段文字内容</p>' })
expect(updated.wordCount).toBeGreaterThan(ch.wordCount)
})
})
+32
View File
@@ -0,0 +1,32 @@
import { describe, it, expect, beforeEach, afterEach } from 'vitest'
import { mkdtempSync, rmSync } from 'fs'
import { join } from 'path'
import { tmpdir } from 'os'
import { GlobalSettingsService } from '../../src/main/services/global-settings'
let dir: string
let svc: GlobalSettingsService
beforeEach(() => {
dir = mkdtempSync(join(tmpdir(), 'bilin-settings-'))
svc = new GlobalSettingsService(dir)
})
afterEach(() => {
rmSync(dir, { recursive: true, force: true })
})
describe('GlobalSettingsService', () => {
it('returns defaults when file missing', () => {
const s = svc.get()
expect(s.onboardingCompleted).toBe(false)
expect(s.theme).toBe('default')
expect(s.language).toBe('zh-CN')
})
it('persists penName update', () => {
svc.update({ penName: '山海' })
const s2 = new GlobalSettingsService(dir)
expect(s2.get().penName).toBe('山海')
})
})
+12
View File
@@ -0,0 +1,12 @@
import { describe, it, expect } from 'vitest'
import { countWords } from '../../src/main/services/word-count'
describe('countWords', () => {
it('counts CJK characters excluding whitespace', () => {
expect(countWords('林远深吸一口气')).toBe(7)
})
it('returns 0 for empty', () => {
expect(countWords('')).toBe(0)
})
})