transcript-view-row.client.spec.tsx 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. // @vitest-environment jsdom
  2. import { afterEach, describe, expect, it, vi } from 'vitest'
  3. import { cleanup, fireEvent, render, screen } from '@testing-library/react'
  4. import type { SessionListState } from '@deepseek-ai/dsh-api-session-controller/client'
  5. import type { WorkspaceSnapshot } from '@deepseek-ai/dsh-api-workspace-controller/client'
  6. import type { SessionPendingInteractionSnapshot } from '@deepseek-ai/dsh-client-ui-session/client'
  7. import type { GlobalStandardProps } from '@deepseek-ai/dsh-client-ui-slots'
  8. import { createSnapshotStore } from '@deepseek-ai/dsh-client-store'
  9. import { bindSnapshotSelector, makeTranslate } from '@deepseek-ai/dsh-client-test-runtime'
  10. import { TranscriptViewRow, type TranscriptViewRowProps } from '../src/client/settings/TranscriptViewRow.tsx'
  11. import { en } from '../src/client/locale.ts'
  12. afterEach(cleanup)
  13. function emptySessions() {
  14. return bindSnapshotSelector(createSnapshotStore<SessionListState>({
  15. ids: [], byId: {}, current: undefined, phase: 'ready', subagentsByParent: {}, jobsBySession: {}, currentAddress: undefined,
  16. }))
  17. }
  18. function emptyWorkspaces() {
  19. return bindSnapshotSelector(createSnapshotStore<WorkspaceSnapshot>({
  20. items: [], archivedSessionIds: [], state: 'idle', phase: 'ready', error: null,
  21. }))
  22. }
  23. function noPendingInteraction() {
  24. return bindSnapshotSelector(createSnapshotStore<SessionPendingInteractionSnapshot>(new Map()))
  25. }
  26. // The resource hook the resources plugin merges into GlobalStandardProps; this row reads no address.
  27. const useResource = (() => ({ status: 'none' as const, value: undefined, failure: undefined, reload: () => {} })) as GlobalStandardProps['useResource']
  28. function mount(mode: 'normal' | 'compact' = 'compact') {
  29. const source = createSnapshotStore(mode)
  30. const setTranscriptView = vi.fn((next: 'normal' | 'compact') => { source.set(next) })
  31. const props: TranscriptViewRowProps = {
  32. useSessions: emptySessions(),
  33. useSessionPendingInteraction: noPendingInteraction(),
  34. useWorkspaces: emptyWorkspaces(),
  35. useResource,
  36. useTranscriptView: bindSnapshotSelector(source),
  37. setTranscriptView,
  38. t: makeTranslate(en),
  39. }
  40. render(<TranscriptViewRow {...props} />)
  41. return { setTranscriptView }
  42. }
  43. describe('TranscriptViewRow', () => {
  44. it('explains the preference and shows Compact by default', () => {
  45. mount()
  46. expect(screen.getByText('Conversation display')).toBeDefined()
  47. expect(screen.getByText('Controls process content in completed turns')).toBeDefined()
  48. expect(screen.getByRole('button', { name: /Compact/ }).getAttribute('aria-expanded')).toBe('false')
  49. })
  50. it('selects Normal and follows the mirrored value', () => {
  51. const b = mount()
  52. fireEvent.click(screen.getByRole('button', { name: /Compact/ }))
  53. fireEvent.click(screen.getByRole('menuitem', { name: 'Normal' }))
  54. expect(b.setTranscriptView).toHaveBeenCalledWith('normal')
  55. const trigger = screen.getByRole('button', { name: /Normal/ })
  56. fireEvent.click(trigger)
  57. expect(screen.getByRole('menuitem', { name: 'Compact' })).toBeDefined()
  58. fireEvent.pointerDown(document.body)
  59. expect(screen.queryByRole('menuitem', { name: 'Compact' })).toBeNull()
  60. })
  61. })