// @vitest-environment jsdom // CostDock presentation: renders the running session cost from the // openRouterCost projection, and nothing at all until a step was priced. import { act, cleanup, render, screen } from '@testing-library/react' import { afterEach, describe, expect, it, vi } from 'vitest' import { makeTranslate } from '@deepseek-ai/dsh-client-test-runtime' import { zh as commonZh } from '@deepseek-ai/dsh-client-locale/src/locales/zh.ts' import { CostDock } from '../src/client/CostDock.tsx' import { zh } from '../src/client/locales.ts' afterEach(cleanup) const t = makeTranslate(zh, commonZh) function makeProps(over: Partial[0]> = {}) { return { useProjection: vi.fn(() => undefined), t, ...over, } as unknown as Parameters[0] } describe('CostDock', () => { it('renders nothing while the projection is absent or priced zero steps', () => { for (const value of [undefined, { totalUsd: 0, pricedSteps: 0, unknownModelSteps: 0, currency: 'USD' }]) { const { container } = render( value })} />) expect(container.firstChild).toBeNull() cleanup() } }) it('renders the priced session cost as a USD figure', () => { render( ({ totalUsd: 1.2345, pricedSteps: 2, unknownModelSteps: 0, currency: 'USD' }), })} />) expect(screen.getByText('会话费用 $1.23')).toBeTruthy() }) it('surfaces the unknown-pricing step count in a tooltip when present', () => { render( ({ totalUsd: 0.5, pricedSteps: 1, unknownModelSteps: 3, currency: 'USD' }), })} />) expect(screen.getByText('会话费用 $0.50').getAttribute('title')).toBe('包含 3 个未知定价步骤') }) it('omits the tooltip when every step priced', () => { render( ({ totalUsd: 0.5, pricedSteps: 1, unknownModelSteps: 0, currency: 'USD' }), })} />) expect(screen.getByText('会话费用 $0.50').getAttribute('title')).toBeNull() }) it('reads the projection through the openRouterCost key', () => { const useProjection = vi.fn(() => undefined) render() act(() => {}) expect(useProjection).toHaveBeenCalledWith('openRouterCost') }) })