Files
dsh-context/tests/client/viewkit.spec.ts
T
Bowen Liang f106b720ac test: rebuild the suite at source level with 100% per-file coverage gates
The old suite exercised the built lib/ bundle, so v8 remapped almost
nothing (8% src coverage) and every run needed a build first. The new
suite imports src/ directly under two vitest projects (node for
host/shared, jsdom for client), rendering real React 18 trees against
the real dictionaries and ui-primitives, with faithful in-memory
harness faces (cordis inject/effect, locale chain, slots, sessions
provide) instead of plugin mocks.

- 43 fine-grained, stateless, single-module spec files (606 tests)
  forked across workers: ~2.5s wall, no build step
- v8 thresholds at 100/100/100/100 per file over src/**
- host specs drive the real projection definitions (init/apply/view)
  plus one full cordis + SessionStore + SessionProjectionRegistry
  integration; the framework's snapshotJsonValue pins the
  projection-cache precondition on every intermediate fold state
- oxlint's src ruleset now covers tests/** as well
- typecheck covers the tests via tsconfig.tests.json
2026-08-26 00:58:39 +08:00

40 lines
1.5 KiB
TypeScript

// The view kit (src/client/viewkit.ts): the dependency bag exposes the
// translate/format helpers and the event-text delegates (full event-text
// coverage lives in the events spec — here only one delegation spot-check).
import assert from 'node:assert/strict'
import { describe, test } from 'vitest'
import { fmt, fmtTime } from '../../src/client/format'
import { DICT_EN } from '../../src/client/i18n'
import { makeViewKit } from '../../src/client/viewkit'
import type { ContextEventRecord } from '../../src/shared/types'
import { makeKit, makeTranslate } from './helpers/kit'
describe('makeViewKit', () => {
test('exposes t, fmt, and fmtTime', () => {
const t = makeTranslate()
const kit = makeViewKit(t)
assert.equal(kit.t, t)
assert.equal(kit.fmt, fmt)
assert.equal(kit.fmtTime, fmtTime)
})
test('catLabel maps through the dictionary', () => {
const kit = makeKit()
assert.equal(kit.catLabel('system'), DICT_EN['cat.system'])
assert.equal(kit.catLabel('tool'), DICT_EN['cat.tool'])
})
test('eventLabel delegates to makeEventText (compaction with a count)', () => {
const kit = makeKit()
const ev: ContextEventRecord = { seq: 1, time: 1000, kind: 'compaction', count: 3, turn: 2, step: 4 }
assert.equal(kit.eventLabel(ev), DICT_EN['ev.compaction'].replace('{n}', '3'))
})
test('eventAt is null for an event without a turn/step anchor', () => {
const kit = makeKit()
const ev: ContextEventRecord = { seq: 2, time: 1000, kind: 'inject', form: 'notice' }
assert.equal(kit.eventAt(ev), null)
})
})