OutlineReader.test.js 1.1 KB

123456789101112131415161718192021222324252627282930
  1. import { test } from 'node:test'
  2. import assert from 'node:assert/strict'
  3. import path from 'node:path'
  4. import { fileURLToPath } from 'node:url'
  5. import { OutlineReader } from '../../../src/storage/adapters/OutlineReader.js'
  6. const __dirname = path.dirname(fileURLToPath(import.meta.url))
  7. const fixtureRoot = path.join(__dirname, '../../fixtures/sample-book')
  8. test('OutlineReader.readOutlineSection 读总纲指定小节', async () => {
  9. const r = await new OutlineReader(fixtureRoot).readOutlineSection('结局')
  10. assert.equal(r.ok, true)
  11. assert.ok(r.content.includes('血仇得报'))
  12. })
  13. test('OutlineReader.readVolumeOutline 读卷纲全文', async () => {
  14. const r = await new OutlineReader(fixtureRoot).readVolumeOutline(1)
  15. assert.equal(r.ok, true)
  16. assert.ok(r.content.includes('卷定位'))
  17. })
  18. test('OutlineReader.readVolumeOutline 不存在的卷 → ok=false', async () => {
  19. const r = await new OutlineReader(fixtureRoot).readVolumeOutline(99)
  20. assert.equal(r.ok, false)
  21. })
  22. test('OutlineReader.listVolumes 列出卷号', async () => {
  23. const vols = await new OutlineReader(fixtureRoot).listVolumes()
  24. assert.deepEqual(vols, [1])
  25. })