surface.spec.ts 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. // Dynamic-key escape hatches and untouched-key behavior of the terminal core.
  2. import { describe, expect, it } from 'vitest'
  3. import type { SlotComponent } from '@deepseek-ai/dsh-client-ui-slots'
  4. import { SlotCore } from '@deepseek-ai/dsh-client-ui-slots'
  5. declare module '@deepseek-ai/dsh-client-ui-slots' {
  6. interface SlotMap {
  7. 'surface.a': { kind: 'single'; scope: 'root' }
  8. 'surface.b': { kind: 'single'; scope: 'root' }
  9. }
  10. }
  11. const Comp: SlotComponent<object> = () => null
  12. describe('dynamic-key escape hatch', () => {
  13. it('specDynamic reads wide-typed specs for string keys; undefined while undeclared', () => {
  14. const core = new SlotCore()
  15. expect(core.specDynamic('surface.a')).toBeUndefined()
  16. core.register({ name: 'root', children: { 'surface.a': { kind: 'single', scope: 'root' } } }, Comp as never)
  17. expect(core.specDynamic('surface.a')).toEqual({ kind: 'single', scope: 'root' })
  18. expect(core.specDynamic('never.declared')).toBeUndefined()
  19. })
  20. it('spec() narrows by SlotMap key', () => {
  21. const core = new SlotCore()
  22. core.register({ name: 'root', children: { 'surface.a': { kind: 'single', scope: 'root' } } }, Comp as never)
  23. expect(core.spec('surface.a')).toEqual({ kind: 'single', scope: 'root' })
  24. expect(core.spec('surface.b')).toBeUndefined()
  25. })
  26. it('entries/getVersion on an untouched key return the frozen empty array and 0', () => {
  27. const core = new SlotCore()
  28. expect(core.entries('surface.b')).toHaveLength(0)
  29. expect(core.entries('surface.b')).toBe(core.entries('surface.b'))
  30. expect(core.getVersion('surface.b')).toBe(0)
  31. })
  32. it('isLive is false for entries the core never held', () => {
  33. const core = new SlotCore()
  34. expect(core.isLive({ component: Comp, options: {} })).toBe(false)
  35. })
  36. })