transcript-view-policy.client.spec.ts 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. // @vitest-environment jsdom
  2. import { describe, expect, it } from 'vitest'
  3. import { stubSettingsScope } from '@deepseek-ai/dsh-client-test-runtime'
  4. import type { ChatSettings } from '../src/chat-settings.ts'
  5. import { TranscriptViewPolicy } from '../src/client/transcript-view.ts'
  6. describe('TranscriptViewPolicy', () => {
  7. it('defaults to Compact and publishes explicit choices before persistence settles', () => {
  8. const host = stubSettingsScope<ChatSettings>()
  9. const observed: string[] = []
  10. let current = (): string => 'unconstructed'
  11. const scope: typeof host.scope = {
  12. ...host.scope,
  13. set: (field, value) => {
  14. observed.push(`${field}=${String(value)}:${current()}`)
  15. return host.scope.set(field, value)
  16. },
  17. }
  18. const policy = new TranscriptViewPolicy(scope)
  19. current = () => policy.mode.getSnapshot()
  20. expect(policy.mode.getSnapshot()).toBe('compact')
  21. policy.setMode('normal')
  22. expect(policy.mode.getSnapshot()).toBe('normal')
  23. expect(observed).toEqual(['transcriptView=normal:normal'])
  24. expect(host.set).toHaveBeenCalledWith('transcriptView', 'normal')
  25. })
  26. it('adopts Host state and ignores identical writes', () => {
  27. const host = stubSettingsScope<ChatSettings>()
  28. const policy = new TranscriptViewPolicy(host.scope)
  29. host.publish({ status: 'ready', value: { transcriptView: 'normal' }, revision: 1, writable: true })
  30. expect(policy.mode.getSnapshot()).toBe('normal')
  31. policy.setMode('normal')
  32. expect(host.set).not.toHaveBeenCalled()
  33. host.publish({ value: { transcriptView: 'compact' }, revision: 2 })
  34. expect(policy.mode.getSnapshot()).toBe('compact')
  35. })
  36. it('adopts an accepted section standing at construction', () => {
  37. const host = stubSettingsScope<ChatSettings>()
  38. host.publish({ status: 'ready', value: { transcriptView: 'normal' }, revision: 1, writable: true })
  39. expect(new TranscriptViewPolicy(host.scope).mode.getSnapshot()).toBe('normal')
  40. })
  41. })