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>
45 lines
1.6 KiB
TypeScript
45 lines
1.6 KiB
TypeScript
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.move', () => {
|
|
let db: SqliteDb
|
|
let chapters: ChapterRepository
|
|
let volId: string
|
|
|
|
beforeEach(() => {
|
|
db = new DatabaseSync(':memory:')
|
|
migrate(db)
|
|
const vols = new VolumeRepository(db)
|
|
volId = vols.create('卷一', 0).id
|
|
chapters = new ChapterRepository(db)
|
|
chapters.create(volId, 'A', 0)
|
|
chapters.create(volId, 'B', 1)
|
|
chapters.create(volId, 'C', 2)
|
|
})
|
|
|
|
afterEach(() => db.close())
|
|
|
|
it('reorders within volume', () => {
|
|
const list = chapters.listByVolume(volId)
|
|
const idA = list.find((x) => x.title === 'A')!.id
|
|
const idB = list.find((x) => x.title === 'B')!.id
|
|
const idC = list.find((x) => x.title === 'C')!.id
|
|
chapters.reorderVolume(volId, [idC, idA, idB])
|
|
const titles = chapters.listByVolume(volId).map((x) => x.title)
|
|
expect(titles).toEqual(['C', 'A', 'B'])
|
|
})
|
|
|
|
it('moves chapter to another volume at index', () => {
|
|
const vols = new VolumeRepository(db)
|
|
const vol2 = vols.create('卷二', 1).id
|
|
const idB = chapters.listByVolume(volId).find((x) => x.title === 'B')!.id
|
|
chapters.moveToVolume(idB, vol2, 0)
|
|
expect(chapters.listByVolume(volId).map((x) => x.title)).toEqual(['A', 'C'])
|
|
expect(chapters.listByVolume(vol2).map((x) => x.title)).toEqual(['B'])
|
|
})
|
|
})
|