TimelineWriter.test.js 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. import { test } from 'node:test'
  2. import assert from 'node:assert/strict'
  3. import { TimelineWriter } from '../../../src/storage/adapters/TimelineWriter.js'
  4. import { makeRepo, cleanup, read } from '../_tmprepo.js'
  5. test('appendRow 向已有卷时间线追加一行', async () => {
  6. const root = await makeRepo({
  7. '定稿/设定/时间线/第05卷.md':
  8. '| 章 | 书内时间 | 一句话事件 | 在场 |\n|---|---|---|---|\n| 151 | 冬月初二 | 旧事 | 林晚 |\n',
  9. })
  10. try {
  11. const r = await new TimelineWriter(root).appendRow(5, {
  12. 章: 152,
  13. 书内时间: '冬月初三',
  14. 一句话事件: '北境得血书',
  15. 在场: '林晚',
  16. })
  17. assert.equal(r.ok, true)
  18. const c = await read(root, '定稿/设定/时间线/第05卷.md')
  19. assert.match(c, /\| 151 \|/)
  20. assert.match(c, /\| 152 \| 冬月初三 \| 北境得血书 \| 林晚 \|/)
  21. } finally {
  22. await cleanup(root)
  23. }
  24. })
  25. test('appendRow 文件不存在时新建表头', async () => {
  26. const root = await makeRepo({})
  27. try {
  28. const r = await new TimelineWriter(root).appendRow(1, {
  29. 章: 1,
  30. 书内时间: '春月初一',
  31. 一句话事件: '入宗门',
  32. 在场: '林晚',
  33. })
  34. assert.equal(r.ok, true)
  35. const c = await read(root, '定稿/设定/时间线/第01卷.md')
  36. assert.match(c, /\| 章 \| 书内时间 \| 一句话事件 \| 在场 \|/)
  37. assert.match(c, /\| 1 \| 春月初一 \| 入宗门 \| 林晚 \|/)
  38. } finally {
  39. await cleanup(root)
  40. }
  41. })