Files
deepseek-harness/packages/client/ui-trajectory/tests/toolbar.client.spec.tsx
T
Chinesezjc b462d5fd69 Merge remote-tracking branch 'origin/master' into feat/web-message-feedback-ui
Adapt to two contract changes master introduced:

- The generated Remote face now wraps every business result in
  RemoteResult, folding carrier failures into an ok:false branch instead
  of rejecting. The controller reads that envelope at its three call
  sites and maps a carrier failure onto the same settled shape the
  controls already render; three specs cover the new branch.
- Client packages split their tsconfig into host and client halves, and
  the host aggregate now compiles any test not named *.client.spec.*.
  Rename this package's specs to the client convention and drop the
  ../connection project reference, which pointed at a solution file that
  no longer carries the client sources.

Keep master's mount loop with its rollback-on-failure in api-remotes and
add messageFeedbackRemote to it.
2026-08-12 10:43:23 +08:00

62 lines
2.3 KiB
TypeScript

// @vitest-environment jsdom
/** Trajectory toolbar export button: click dispatch, in-flight disable, and error surfacing. */
import { afterEach, describe, expect, it, vi } from 'vitest'
import { cleanup, fireEvent, render, screen } from '@testing-library/react'
import type { LocaleKeysOf } from '@deepseek-ai/dsh-client-ui-slots'
import { TrajectoryToolbar, type TrajectoryToolbarProps } from '../src/client/TrajectoryToolbar.tsx'
import { zh, type TrajectoryKey } from '../src/client/locales.ts'
/** Test translator pinned to the Simplified Chinese dictionary. */
const zhT = (key: LocaleKeysOf<'trajectory'>): string => zh[key as TrajectoryKey] ?? key
afterEach(() => {
cleanup()
vi.restoreAllMocks()
})
function baseProps(overrides: Partial<TrajectoryToolbarProps> = {}): TrajectoryToolbarProps {
return {
actualDuration: false,
onActualDurationChange: vi.fn(),
actualTime: false,
onActualTimeChange: vi.fn(),
allTurnsCollapsed: false,
onToggleAllTurns: vi.fn(),
allAssistantsCollapsed: false,
onToggleAllAssistants: vi.fn(),
searchQuery: '',
onSearchQueryChange: vi.fn(),
exporting: false,
onExport: vi.fn(),
exportError: null,
t: zhT,
...overrides,
}
}
describe('TrajectoryToolbar export', () => {
it('renders the export button and dispatches the export callback on click', () => {
const onExport = vi.fn()
render(<TrajectoryToolbar {...baseProps({ onExport })} />)
const button = screen.getByRole('button', { name: 'Export session log' })
fireEvent.click(button)
expect(onExport).toHaveBeenCalledTimes(1)
})
it('disables the button while an export is in flight and blocks dispatch', () => {
const onExport = vi.fn()
render(<TrajectoryToolbar {...baseProps({ exporting: true, onExport })} />)
const button = screen.getByRole('button', { name: 'Export session log' }) as HTMLButtonElement
expect(button.disabled).toBe(true)
fireEvent.click(button)
expect(onExport).not.toHaveBeenCalled()
})
it('surfaces an export failure as the button title', () => {
render(<TrajectoryToolbar {...baseProps({ exportError: 'Export failed: internal boom' })} />)
const button = screen.getByRole('button', { name: 'Export session log' })
expect(button.title).toBe('Export failed: internal boom')
})
})