test(session-log-export): remove unknown casts from fixtures
Type the Header and toast test fixtures with the standard Session/global props they render with, and read slot injections through a narrow object helper. Prune the four retired unknown-cast baseline entries. No product behavior changes.
This commit is contained in:
1 parent
ae22f461f3
commit
6118b51fa8
4 files changed
+34
-22
No files matched your search
@@ -28,6 +28,11 @@ function declare(slots: SlotRegistry): () => void {
|
||||
} as never, () => null)
|
||||
}
|
||||
|
||||
function injectedOf(entry: { inject?: ((...args: never[]) => object) | undefined } | undefined): object {
|
||||
if (entry?.inject === undefined) throw new Error('slot entry has no injection')
|
||||
return entry.inject()
|
||||
}
|
||||
|
||||
async function bench() {
|
||||
const ctx = new Context()
|
||||
await ctx.plugin(SlotRegistry).await()
|
||||
@@ -43,7 +48,7 @@ describe('session-log-download browser plugin', () => {
|
||||
it('follows feedback plugin availability and opens the selected Session form', async () => {
|
||||
const b = await bench()
|
||||
const entry = b.slots.entries('conversation.session.header.utilities')[0]!
|
||||
const injected = (entry.inject as unknown as () => SessionLogDownloadHeaderInjected)()
|
||||
const injected = injectedOf(entry) as SessionLogDownloadHeaderInjected
|
||||
expect(injected.hooks.feedbackAvailable.getSnapshot()).toBe(false)
|
||||
injected.openFeedback(SID)
|
||||
|
||||
@@ -69,7 +74,7 @@ describe('session-log-download browser plugin', () => {
|
||||
const entry = b.slots.entries('conversation.session.header.utilities')[0]
|
||||
expect(entry?.component).toBe(SessionLogDownloadHeaderAction)
|
||||
expect(entry?.options).toMatchObject({ id: 'session-log-download' })
|
||||
const injected = (entry?.inject as unknown as () => SessionLogDownloadHeaderInjected)()
|
||||
const injected = injectedOf(entry) as SessionLogDownloadHeaderInjected
|
||||
await injected.request(SID)
|
||||
expect(b.ctx.sessionLogDownload.store.getSnapshot().bySession[SID]?.status).toBe('error')
|
||||
injected.dismiss(SID)
|
||||
@@ -78,7 +83,7 @@ describe('session-log-download browser plugin', () => {
|
||||
const overlay = b.slots.entries('shell.overlay')[0]
|
||||
expect(overlay?.component).toBe(SessionMarkdownCopyToast)
|
||||
expect(overlay?.options).toMatchObject({ id: 'session-log-download.copy-toast' })
|
||||
const overlayInjected = (overlay?.inject as unknown as () => SessionMarkdownCopyToastInjected)()
|
||||
const overlayInjected = injectedOf(overlay) as SessionMarkdownCopyToastInjected
|
||||
await injected.copyMarkdown(SID)
|
||||
expect(injected.hooks.sessionMarkdownCopy.getSnapshot().notice?.kind).toBe('failed')
|
||||
overlayInjected.dismiss()
|
||||
|
||||
@@ -20,11 +20,12 @@ function bindSnapshot(store: ObservableSnapshot<SessionMarkdownCopyState>) {
|
||||
function bench(notice: SessionMarkdownCopyState['notice']) {
|
||||
const store = createSnapshotStore<SessionMarkdownCopyState>({ copying: false, notice })
|
||||
const dismiss = vi.fn()
|
||||
const props = {
|
||||
const dictionary: Record<string, string> = en
|
||||
const props: SessionMarkdownCopyToastProps = {
|
||||
useSessionMarkdownCopy: bindSnapshot(store),
|
||||
dismiss,
|
||||
t: (key: keyof typeof en): string => en[key],
|
||||
} as unknown as SessionMarkdownCopyToastProps
|
||||
t: key => dictionary[key] ?? key,
|
||||
}
|
||||
return { ...render(<SessionMarkdownCopyToast {...props} />), store, dismiss }
|
||||
}
|
||||
|
||||
|
||||
@@ -3,6 +3,7 @@ import { act, cleanup, fireEvent, render, waitFor } from '@testing-library/react
|
||||
import { afterEach, describe, expect, it, vi } from 'vitest'
|
||||
import { useSyncExternalStore } from 'react'
|
||||
import type { SessionId } from '@deepseek-ai/dsh-session/types'
|
||||
import type { GlobalStandardProps, SessionStandardProps } from '@deepseek-ai/dsh-client-ui-slots'
|
||||
import { createSnapshotStore, type ObservableSnapshot } from '@deepseek-ai/dsh-client-store'
|
||||
import { SessionLogDownloadController } from '../src/client/controller.ts'
|
||||
import { SessionMarkdownCopyController } from '../src/client/copy-controller.ts'
|
||||
@@ -11,6 +12,18 @@ import type { SessionLogDownloadHeaderProps } from '../src/client/HeaderAction.t
|
||||
import { en } from '../src/client/locales.ts'
|
||||
|
||||
const SID = 'session-export-header' as SessionId
|
||||
const dictionary: Record<string, string> = en
|
||||
const translate: SessionLogDownloadHeaderProps['t'] = key => dictionary[key] ?? key
|
||||
const unused = (): never => { throw new Error('This isolated component does not consume framework hooks') }
|
||||
const standard: GlobalStandardProps & SessionStandardProps = {
|
||||
sessionId: SID, useSession: unused, useProjection: unused, useAccess: () => true,
|
||||
useSessions: unused, useSessionStatus: unused, useSessionRetainInfo: unused,
|
||||
useSessionAccess: () => true, useRemoteAccess: () => true, useWorkspaceAccess: () => true,
|
||||
useConversation: unused, useInput: unused, useChat: unused, useTrajectory: unused,
|
||||
usePanelInfo: unused, useResource: unused, useWorkspaces: unused,
|
||||
inputActions: { captureInsertion: unused, insertText: unused, setDraft: unused, persistDraft: unused,
|
||||
addAttachments: unused, removeAttachment: unused, pruneAttachments: unused, submit: unused },
|
||||
}
|
||||
|
||||
function bindSnapshot<State>(store: ObservableSnapshot<State>) {
|
||||
return function useSnapshot<T>(selector: (state: State) => T): T {
|
||||
@@ -33,8 +46,8 @@ function bench(feedbackAvailable = false, copyController = new SessionMarkdownCo
|
||||
const feedback = createSnapshotStore(feedbackAvailable)
|
||||
const useSessionLogDownload = bindSnapshot(controller.store)
|
||||
const useSessionMarkdownCopy = bindSnapshot(copyController.store)
|
||||
const props = {
|
||||
sessionId: SID,
|
||||
const props: SessionLogDownloadHeaderProps = {
|
||||
...standard,
|
||||
useSessionLogDownload,
|
||||
useSessionMarkdownCopy,
|
||||
useFeedbackAvailable: bindSnapshot(feedback),
|
||||
@@ -42,8 +55,8 @@ function bench(feedbackAvailable = false, copyController = new SessionMarkdownCo
|
||||
request,
|
||||
copyMarkdown,
|
||||
dismiss,
|
||||
t: (key: keyof typeof en): string => en[key],
|
||||
} as unknown as SessionLogDownloadHeaderProps
|
||||
t: translate,
|
||||
}
|
||||
const view = render(<SessionLogDownloadHeaderAction {...props} />)
|
||||
return { controller, copyController, request, copyMarkdown, openFeedback, feedback, view }
|
||||
}
|
||||
@@ -150,8 +163,8 @@ describe('Session export Header action', () => {
|
||||
const pending = new Promise<Response>((resolve) => { release = resolve })
|
||||
const controller = new SessionLogDownloadController(() => pending, vi.fn())
|
||||
const useSessionLogDownload = bindSnapshot(controller.store)
|
||||
b.view.rerender(<SessionLogDownloadHeaderAction {...({
|
||||
sessionId: SID,
|
||||
const rerendered: SessionLogDownloadHeaderProps = {
|
||||
...standard,
|
||||
useSessionLogDownload,
|
||||
useSessionMarkdownCopy: bindSnapshot(b.copyController.store),
|
||||
useFeedbackAvailable: bindSnapshot(b.feedback),
|
||||
@@ -159,8 +172,9 @@ describe('Session export Header action', () => {
|
||||
request: (sessionId: SessionId) => controller.download(sessionId),
|
||||
copyMarkdown: b.copyMarkdown,
|
||||
dismiss: (sessionId: SessionId) => { controller.dismiss(sessionId) },
|
||||
t: (key: keyof typeof en): string => en[key],
|
||||
} as unknown as SessionLogDownloadHeaderProps)} />)
|
||||
t: translate,
|
||||
}
|
||||
b.view.rerender(<SessionLogDownloadHeaderAction {...rerendered} />)
|
||||
|
||||
const download = controller.download(SID)
|
||||
const button = b.view.getByRole('button', { name: 'More actions' })
|
||||
|
||||
@@ -1530,10 +1530,6 @@
|
||||
"cb524acd0159b942e7974d76b581b1f419b8653d1734946a3f154dda8e8f4762": 1,
|
||||
"f10c6a0a3a762be54c2de87ab5d787e37a21a89c9d468bf81d0658c2bf15d581": 1
|
||||
},
|
||||
"packages/session-query/session-log-export/tests/client-apply.client.spec.tsx": {
|
||||
"04984a2ce1486250236e638e0197da0a1a840855ed3975c59130a85358c7e5fe": 1,
|
||||
"eee35b4d8641824c6eaacfe03ed60d353d81d5257d1111132f34d46a7b13ef35": 1
|
||||
},
|
||||
"packages/session-query/session-log-export/tests/controller.client.spec.ts": {
|
||||
"746ebc5aade01a50cc9a74fc07b1023addf021aef80b62c069a437ac140c9e64": 1,
|
||||
"c920d88f6eb309ef5991608642a1ab0fd972690538b33c34d86c68d07ddd6edf": 1
|
||||
@@ -1541,10 +1537,6 @@
|
||||
"packages/session-query/session-log-export/tests/dialog.client.spec.tsx": {
|
||||
"a9b1969d76db0b05f87c862956f8ff45c52f1f4a5b32a206339de0c9fee99a77": 1
|
||||
},
|
||||
"packages/session-query/session-log-export/tests/header-action.client.spec.tsx": {
|
||||
"238a292bbe3a61acbc4f2d96fff474df5fba1577357219a88c914813786b56a7": 1,
|
||||
"47d3a14a42ef7142ea22071677b42265f02fba5a2a0cf4210f4f9c7c5a876d10": 1
|
||||
},
|
||||
"packages/session-query/session-log-export/tests/loader-composition.host.spec.ts": {
|
||||
"59c63f734e8bba862325f776e3fcbebd78a84cfb4161f8df41c216950d9bf351": 1,
|
||||
"e12d49327a6708ae3ace371e28ed0deb471dc8895c584ba94a86af344c15cec3": 1
|
||||
|
||||
Reference in new issue
Block a user