8ce35a1e8e
Add chapter reorder, search replace, inspiration capture, and AI chat with context editing, settings, offline handling, and naming checks. Fix dev black screen by keeping process.env reads in the main process only. Co-authored-by: Cursor <cursoragent@cursor.com>
51 lines
2.0 KiB
TypeScript
51 lines
2.0 KiB
TypeScript
import { describe, it, expect } from 'vitest'
|
|
import { collectChaptersPlain, findLocalNamingConflicts, parseNamingJson, buildNamingPrompt } from '../../src/main/services/naming-check.service'
|
|
|
|
describe('parseNamingJson', () => {
|
|
it('parses JSON array from plain response', () => {
|
|
const raw = `[{"termA":"林远","termB":"林悦","confidence":0.92,"reason":"同姓近音","suggestedCanonical":"林远"}]`
|
|
const rows = parseNamingJson(raw)
|
|
expect(rows).toHaveLength(1)
|
|
expect(rows[0].termA).toBe('林远')
|
|
expect(rows[0].termB).toBe('林悦')
|
|
expect(rows[0].confidence).toBeCloseTo(0.92)
|
|
})
|
|
|
|
it('extracts array from markdown-wrapped response', () => {
|
|
const raw = '说明如下:\n```json\n[{"termA":"玄火掌","termB":"焰火掌","confidence":0.8,"reason":"技能名不一致"}]\n```'
|
|
const rows = parseNamingJson(raw)
|
|
expect(rows).toHaveLength(1)
|
|
expect(rows[0].termA).toBe('玄火掌')
|
|
})
|
|
|
|
it('throws when no array present', () => {
|
|
expect(() => parseNamingJson('no json here')).toThrow()
|
|
})
|
|
})
|
|
|
|
describe('findLocalNamingConflicts', () => {
|
|
it('detects 林远 vs 林悦 in chapter text', () => {
|
|
const rows = findLocalNamingConflicts(['林远'], '林悦走进院子,环顾四周。', [])
|
|
expect(rows.length).toBeGreaterThan(0)
|
|
expect(rows[0].termA).toBe('林远')
|
|
expect(rows[0].termB).toBe('林悦')
|
|
})
|
|
|
|
it('detects conflict from chapter html content', () => {
|
|
const plain = collectChaptersPlain([
|
|
{ title: '新章', content: '<p>林悦走进院子,环顾四周。</p>' }
|
|
])
|
|
const rows = findLocalNamingConflicts(['林远'], plain, [])
|
|
expect(rows.length).toBeGreaterThan(0)
|
|
})
|
|
})
|
|
|
|
describe('buildNamingPrompt', () => {
|
|
it('includes setting names and ignore words', () => {
|
|
const prompt = buildNamingPrompt(['林远'], '林悦走进院子。', ['青云宗'])
|
|
expect(prompt).toContain('林远')
|
|
expect(prompt).toContain('林悦走进院子')
|
|
expect(prompt).toContain('青云宗')
|
|
})
|
|
})
|