sessionPreferences.test.ts 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
  2. import {
  3. moveSessionFastMode, readAgentShowThinking, readSessionFastMode, writeAgentShowThinking, writeSessionFastMode,
  4. } from '@/utils/sessionPreferences'
  5. beforeEach(() => {
  6. const values = new Map<string, string>()
  7. vi.stubGlobal('localStorage', {
  8. getItem: (key: string) => values.get(key) ?? null,
  9. setItem: (key: string, value: string) => void values.set(key, value),
  10. removeItem: (key: string) => void values.delete(key),
  11. })
  12. })
  13. afterEach(() => vi.unstubAllGlobals())
  14. describe('session and Agent display preferences', () => {
  15. it('isolates fast mode by account, Agent, and session', () => {
  16. writeSessionFastMode('u1', 'yaoer', 's1', true)
  17. expect(readSessionFastMode('u1', 'yaoer', 's1')).toBe(true)
  18. expect(readSessionFastMode('u1', 'default', 's1')).toBe(false)
  19. expect(readSessionFastMode('u2', 'yaoer', 's1')).toBe(false)
  20. expect(readSessionFastMode('u1', 'yaoer', 's2')).toBe(false)
  21. })
  22. it('moves a draft fast-mode selection to the stored session identity', () => {
  23. writeSessionFastMode('u1', 'default', 'draft-1', true)
  24. moveSessionFastMode('u1', 'default', 'draft-1', 'stored-1', true)
  25. expect(readSessionFastMode('u1', 'default', 'draft-1')).toBe(false)
  26. expect(readSessionFastMode('u1', 'default', 'stored-1')).toBe(true)
  27. })
  28. it('hides thinking by default and stores an explicit choice per account and Agent', () => {
  29. expect(readAgentShowThinking('u1', 'yaoer')).toBe(false)
  30. writeAgentShowThinking('u1', 'yaoer', false)
  31. expect(readAgentShowThinking('u1', 'yaoer')).toBe(false)
  32. expect(readAgentShowThinking('u1', 'default')).toBe(false)
  33. writeAgentShowThinking('u1', 'yaoer', true)
  34. expect(readAgentShowThinking('u1', 'yaoer')).toBe(true)
  35. })
  36. })