Files
deepseek-harness/packages/client/web/tests/app.spec.tsx
imccyu a3f9a4d3ee test(client): migrate the ui-conversation and web benches onto SlotTestRuntime
The five ui-conversation machinery specs (apply-inject, chat-apply,
chat-toolview-slot, service-orchestration, selection-survival — now .tsx)
and the web app/app-shell specs assemble through the runtime instead of
hand-built Context + SlotsService + fake-session scaffolding per suite.
Session behavior mocks are typed against ISession, so incomplete fakes
fail at compile time.
2026-07-28 23:54:14 +08:00

66 lines
2.5 KiB
TypeScript

// @vitest-environment jsdom
/**
* buildRenderApp on SlotTestRuntime: the fail-loud sessions precondition, the
* one ctx-level renderSlot('root') call, and the document-title projection
* arms over the real slot stack.
*/
import { afterEach, describe, expect, it } from 'vitest'
import { cleanup, render } from '@testing-library/react'
import { Context } from 'cordis'
import { SlotTestRuntime } from '@deepseek-ai/dsh-client-test-runtime'
import type { SessionId } from '@deepseek-ai/dsh-client-runtime/client'
import { buildRenderApp } from '@deepseek-ai/dsh-client-web/src/app.tsx'
let runtime: SlotTestRuntime | undefined
afterEach(async () => {
cleanup()
await runtime?.dispose()
runtime = undefined
document.title = ''
})
async function bench() {
runtime = await SlotTestRuntime.create()
await runtime.root.declare({}, () => <div data-testid="frame" />)
return { runtime, renderApp: buildRenderApp({ ctx: runtime.ctx }) }
}
describe('buildRenderApp', () => {
it('fails loud when the sessions service is unavailable', () => {
expect(() => buildRenderApp({ ctx: new Context() })).toThrow('sessions service unavailable')
})
it('renders the root slot tree through the one ctx-level renderSlot call', async () => {
const b = await bench()
const view = render(<>{b.renderApp()}</>)
expect(view.getByTestId('frame')).toBeTruthy()
})
it('projects the current session durable title and falls back to the product title', async () => {
document.title = 'Product'
const b = await bench()
render(<>{b.renderApp()}</>)
// No current session: the product title stands.
expect(document.title).toBe('Product')
await b.runtime.sessions.add({ id: 's1', summary: { title: 'First' } })
expect(document.title).toBe('First — Product')
await b.runtime.sessions.setCurrent(undefined)
expect(document.title).toBe('Product')
// A session without a durable title keeps the product title.
await b.runtime.sessions.add({ id: 's2' })
expect(document.title).toBe('Product')
})
it('a current id without a list row falls back (selection/list arbitration transient)', async () => {
document.title = 'Product'
const b = await bench()
await b.runtime.sessions.add({ id: 's1', summary: { title: 'First' } })
render(<>{b.renderApp()}</>)
expect(document.title).toBe('First — Product')
b.runtime.sessions.list.update((draft) => { draft.current = 'ghost' as SessionId })
await b.runtime.flush()
expect(document.title).toBe('Product')
})
})