# Conflicts: # apps/web/tests/expected/agent-preset-selection/header.expected.md # docs/architecture.i18n.yaml # docs/config-catalog.i18n.yaml # docs/config-catalog.md # docs/event-producer-consumer.i18n.yaml # docs/event-producer-consumer.md # docs/event-producer-consumer.zh.md # docs/module-graph.i18n.yaml # docs/module-graph.md # docs/module-graph.zh.md # docs/persistence-catalog.i18n.yaml # docs/persistence-catalog.md # docs/persistence-catalog.zh.md # docs/persistence-schema.json # docs/subsystems/web-client.i18n.yaml # packages/api/README.i18n.yaml # packages/api/README.md # packages/api/README.zh.md # packages/api/session-controller/README.i18n.yaml # packages/api/session-controller/README.md # packages/api/session-controller/README.zh.md # packages/api/session-controller/src/client/sessions/manager.ts # packages/api/session-controller/src/client/sessions/service.ts # packages/api/session-controller/tests/manager.client.spec.ts # packages/client/locale/tests/language-row.client.spec.tsx # packages/client/ui-chat/tests/chat-view.client.spec.tsx # packages/client/ui-chat/tests/transcript-view-row.client.spec.tsx # packages/client/ui-conversation/tests/conversation-registry.client.spec.ts # packages/client/ui-conversation/tests/enter-behavior-row.client.spec.tsx # packages/client/ui-conversation/tests/input-bar.client.spec.tsx # packages/client/ui-conversation/tests/input-matrix.client.spec.tsx # packages/client/ui-conversation/tests/input-scenarios.client.spec.tsx # packages/client/ui-conversation/tests/skeleton.client.spec.tsx # packages/client/ui-deliverables/tests/deliverables.client.spec.tsx # packages/client/ui-jobs/tests/job-list-action.client.spec.tsx # packages/client/ui-layout/tests/app-frame.client.spec.tsx # packages/client/ui-layout/tests/document-title.client.spec.tsx # packages/client/ui-open-in-app/tests/open-in-app-action.client.spec.tsx # packages/client/ui-primitives/README.i18n.yaml # packages/client/ui-session/tests/ui-session.client.spec.ts # packages/client/ui-settings-general/tests/settings-root.client.spec.tsx # packages/client/ui-settings-unarchive-sessions/tests/components.client.spec.tsx # packages/client/ui-subagent/README.i18n.yaml # packages/client/ui-subagent/README.md # packages/client/ui-subagent/README.zh.md # packages/client/ui-subagent/src/client/SubagentHeaderLineage.tsx # packages/client/ui-subagent/tests/conversation-ui.client.spec.tsx # packages/client/ui-theme/tests/appearance-row.client.spec.tsx # packages/client/ui-theme/tests/font-size-row.client.spec.tsx # packages/client/ui-tool/tests/coverage-tails.client.spec.tsx # packages/client/ui-tool/tests/diff-card.client.spec.tsx # packages/client/ui-tool/tests/image-card.client.spec.tsx # packages/client/ui-tool/tests/read-card.client.spec.tsx # packages/client/ui-tool/tests/terminal-card.client.spec.tsx # packages/client/ui-trajectory/tests/views.client.spec.tsx # packages/client/ui-user-questions/tests/plan-review-panel.client.spec.tsx # packages/client/ui-user-questions/tests/user-questions-composer.client.spec.tsx # packages/client/ui-workflow-run/tests/workflow-run.client.spec.tsx # packages/client/ui-workspace/tests/apply.client.spec.ts # packages/client/ui-workspace/tests/tree.client.spec.ts # packages/client/ui-workspace/tests/workspace-browser.client.spec.tsx # packages/client/ui-workspace/tests/workspace-picker.client.spec.tsx # packages/client/ui-workspace/tests/workspaces-service.client.spec.ts # packages/extensions/cordis-client-runner/src/client/slot-catalog.ts # packages/jobs/tool-jobs/src/index.ts # packages/shell/tool-bash/README.i18n.yaml # packages/test-support/client-runtime/src/sessions.ts
155 lines
7.2 KiB
TypeScript
155 lines
7.2 KiB
TypeScript
// @vitest-environment jsdom
|
|
import { afterEach, describe, expect, it, vi } from 'vitest'
|
|
import { act, cleanup, fireEvent, render, screen } from '@testing-library/react'
|
|
import type { SessionListState } from '@deepseek-ai/dsh-api-session-controller/client'
|
|
import type { WorkspaceSnapshot } from '@deepseek-ai/dsh-api-workspace-controller/client'
|
|
import type { SessionStatusSnapshot } from '@deepseek-ai/dsh-client-ui-session/client'
|
|
import type { GlobalStandardProps } from '@deepseek-ai/dsh-client-ui-slots'
|
|
import { createSnapshotStore } from '@deepseek-ai/dsh-client-store'
|
|
import { bindSnapshotSelector, makeTranslate } from '@deepseek-ai/dsh-client-test-runtime'
|
|
import { TranscriptViewRow, type TranscriptViewRowProps } from '../src/client/settings/TranscriptViewRow.tsx'
|
|
import { PerformanceUsageRow } from '../src/client/settings/PerformanceUsageRow.tsx'
|
|
import type { LinkOpening, PerformanceUsageMode, TranscriptViewMode } from '../src/chat-settings.ts'
|
|
import { LinkOpeningRow } from '../src/client/settings/LinkOpeningRow.tsx'
|
|
import { en, zh } from '../src/client/locale.ts'
|
|
|
|
afterEach(cleanup)
|
|
|
|
function emptySessions() {
|
|
return bindSnapshotSelector(createSnapshotStore<SessionListState>({
|
|
ids: [], byId: {}, phase: 'ready', projectionsBySession: {},
|
|
}))
|
|
}
|
|
|
|
function emptyWorkspaces() {
|
|
return bindSnapshotSelector(createSnapshotStore<WorkspaceSnapshot>({
|
|
items: [], archivedSessionIds: [], pinnedSessionIds: [], state: 'idle', phase: 'ready', error: null,
|
|
}))
|
|
}
|
|
|
|
function noPendingInteraction() {
|
|
return bindSnapshotSelector(createSnapshotStore<SessionStatusSnapshot>(new Map()))
|
|
}
|
|
|
|
// The resource hook the resources plugin merges into GlobalStandardProps; this row reads no address.
|
|
const useResource = (() => ({ status: 'none' as const, value: undefined, failure: undefined })) as GlobalStandardProps['useResource']
|
|
|
|
function mount(mode: TranscriptViewMode = 'compact', dictionary: typeof en | typeof zh = en) {
|
|
const source = createSnapshotStore<TranscriptViewMode>(mode)
|
|
const setTranscriptView = vi.fn((next: TranscriptViewMode) => { source.set(next) })
|
|
const props: TranscriptViewRowProps = {
|
|
usePanelInfo: selector => selector({ activePanelId: null }),
|
|
useSessions: emptySessions(),
|
|
useSessionStatus: noPendingInteraction(),
|
|
useWorkspaces: emptyWorkspaces(),
|
|
useSessionRetainInfo: () => undefined,
|
|
useResource,
|
|
useTranscriptView: bindSnapshotSelector(source),
|
|
setTranscriptView,
|
|
t: makeTranslate(dictionary),
|
|
}
|
|
render(<TranscriptViewRow {...props} />)
|
|
return { setTranscriptView, props }
|
|
}
|
|
|
|
describe('TranscriptViewRow', () => {
|
|
it('explains the preference and shows Compact by default', () => {
|
|
mount()
|
|
expect(screen.getByText('Work details')).toBeDefined()
|
|
expect(screen.getByText('Controls how turns and steps expand by default')).toBeDefined()
|
|
expect(screen.getByRole('button', { name: /Compact/ }).getAttribute('aria-expanded')).toBe('false')
|
|
})
|
|
|
|
it.each([
|
|
['detailed', 'Detailed'],
|
|
['expanded', 'Expanded'],
|
|
] as const)('selects %s and follows the mirrored value', (mode, label) => {
|
|
const b = mount()
|
|
fireEvent.click(screen.getByRole('button', { name: /Compact/ }))
|
|
expect(screen.queryByRole('menuitem', { name: 'Normal' })).toBeNull()
|
|
fireEvent.click(screen.getByRole('menuitem', { name: label }))
|
|
expect(b.setTranscriptView).toHaveBeenCalledWith(mode)
|
|
const trigger = screen.getByRole('button', { name: label })
|
|
fireEvent.click(trigger)
|
|
expect(screen.getByRole('menuitem', { name: 'Compact' })).toBeDefined()
|
|
fireEvent.pointerDown(document.body)
|
|
expect(screen.queryByRole('menuitem', { name: 'Compact' })).toBeNull()
|
|
})
|
|
|
|
it('shows all three work-detail values in Chinese', () => {
|
|
const b = mount('compact', zh)
|
|
expect(screen.getByText('工作过程展示')).toBeDefined()
|
|
fireEvent.click(screen.getByRole('button', { name: '简洁' }))
|
|
fireEvent.click(screen.getByRole('menuitem', { name: '详细' }))
|
|
expect(b.setTranscriptView).toHaveBeenLastCalledWith('detailed')
|
|
fireEvent.click(screen.getByRole('button', { name: '详细' }))
|
|
fireEvent.click(screen.getByRole('menuitem', { name: '完全展开' }))
|
|
expect(b.setTranscriptView).toHaveBeenLastCalledWith('expanded')
|
|
expect(screen.getByRole('button', { name: '完全展开' })).toBeDefined()
|
|
})
|
|
})
|
|
|
|
|
|
describe('LinkOpeningRow', () => {
|
|
it('follows browser availability without clearing the saved destination', () => {
|
|
const b = mount()
|
|
const browserAvailable = createSnapshotStore(false)
|
|
const source = createSnapshotStore<LinkOpening>('new-tab')
|
|
render(<LinkOpeningRow
|
|
{...b.props}
|
|
useLinkOpening={bindSnapshotSelector(source)}
|
|
useBrowserAvailable={bindSnapshotSelector(browserAvailable)}
|
|
setLinkOpening={vi.fn()}
|
|
/>)
|
|
expect(screen.queryByText('Open chat links in')).toBeNull()
|
|
act(() => { browserAvailable.set(true) })
|
|
expect(screen.getByRole('button', { name: 'New browser tab' })).toBeDefined()
|
|
act(() => { browserAvailable.set(false) })
|
|
expect(screen.queryByText('Open chat links in')).toBeNull()
|
|
expect(source.getSnapshot()).toBe('new-tab')
|
|
})
|
|
|
|
it.each([
|
|
[en, 'Open chat links in', 'Built-in browser', 'New browser tab'],
|
|
[zh, '聊天链接打开方式', '内置浏览器', '浏览器新标签页'],
|
|
] as const)('selects either destination using localized labels (%s)', (dictionary, title, sidebar, newTab) => {
|
|
const b = mount('compact', dictionary)
|
|
const source = createSnapshotStore<LinkOpening>('sidebar')
|
|
const setLinkOpening = vi.fn((destination: LinkOpening) => { source.set(destination) })
|
|
render(<LinkOpeningRow
|
|
{...b.props}
|
|
useLinkOpening={bindSnapshotSelector(source)}
|
|
useBrowserAvailable={bindSnapshotSelector(createSnapshotStore(true))}
|
|
setLinkOpening={setLinkOpening}
|
|
/>)
|
|
expect(screen.getByText(title)).toBeDefined()
|
|
fireEvent.click(screen.getByRole('button', { name: sidebar }))
|
|
fireEvent.click(screen.getByRole('menuitem', { name: newTab }))
|
|
expect(setLinkOpening).toHaveBeenLastCalledWith('new-tab')
|
|
fireEvent.click(screen.getByRole('button', { name: newTab }))
|
|
fireEvent.click(screen.getByRole('menuitem', { name: sidebar }))
|
|
expect(setLinkOpening).toHaveBeenLastCalledWith('sidebar')
|
|
expect(screen.getByRole('button', { name: sidebar }).getAttribute('aria-expanded')).toBe('false')
|
|
expect(b.setTranscriptView).not.toHaveBeenCalled()
|
|
})
|
|
})
|
|
|
|
describe('PerformanceUsageRow', () => {
|
|
it('selects compact statistics independently of conversation display', () => {
|
|
const b = mount()
|
|
const source = createSnapshotStore<PerformanceUsageMode>('detailed')
|
|
const setPerformanceUsage = vi.fn((mode: PerformanceUsageMode) => { source.set(mode) })
|
|
render(<PerformanceUsageRow
|
|
{...b.props}
|
|
usePerformanceUsage={bindSnapshotSelector(source)}
|
|
setPerformanceUsage={setPerformanceUsage}
|
|
/>)
|
|
expect(screen.getByText('Performance & usage')).toBeDefined()
|
|
fireEvent.click(screen.getByRole('button', { name: 'Detailed' }))
|
|
fireEvent.click(screen.getByRole('menuitem', { name: 'Compact' }))
|
|
expect(setPerformanceUsage).toHaveBeenCalledWith('compact')
|
|
expect(screen.getAllByRole('button', { name: 'Compact' })).toHaveLength(2)
|
|
expect(b.setTranscriptView).not.toHaveBeenCalled()
|
|
})
|
|
})
|