1+ import { scopeThreadRef } from "@t3tools/client-runtime/environment" ;
12import { EnvironmentId , MessageId , ThreadId } from "@t3tools/contracts" ;
23import {
34 serializeAssistantCitation ,
45 withAssistantCitationComment ,
56} from "@t3tools/shared/assistantCitations" ;
6- import { createRef , useState } from "react" ;
7+ import { createRef , use , useState } from "react" ;
78import { expect , it , vi } from "vite-plus/test" ;
89
910import { page , userEvent } from "vite-plus/test/browser" ;
@@ -18,6 +19,7 @@ vi.mock(import("@tanstack/react-router"), async (importOriginal) => ({
1819 useParams : ( ( ) => navigation . params ) as typeof import ( "@tanstack/react-router" ) . useParams ,
1920} ) ) ;
2021
22+ import { ComposerContextActionsContext } from "./composerContextActions" ;
2123import { findAssistantCitationSourceAnchor } from "~/lib/assistantTextSelection" ;
2224import { act , render } from "../../test/render" ;
2325import {
@@ -296,3 +298,27 @@ it.each(["blocked", "refusedLater"] as const)(
296298 . toHaveAttribute ( "data-prompt" , `See ${ serializeAssistantCitation ( citation ) } x ` ) ;
297299 } ,
298300) ;
301+
302+ it ( "reveals a side-chat citation using the composer scope on its parent route" , async ( ) => {
303+ navigation . navigate . mockClear ( ) ;
304+ navigation . params = { environmentId : "environment" , threadId : "parent-thread" } ;
305+ const editorRef = createRef < ComposerPromptEditorHandle > ( ) ;
306+ function SideChatComposer ( ) {
307+ const actions = use ( ComposerContextActionsContext ) ;
308+ return (
309+ < ComposerContextActionsContext
310+ value = { { ...actions , threadRef : scopeThreadRef ( citation . environmentId , citation . threadId ) } }
311+ >
312+ < Composer question = { false } editorRef = { editorRef } sourceVisible = { false } />
313+ </ ComposerContextActionsContext >
314+ ) ;
315+ }
316+ try {
317+ await using screen = await render ( < SideChatComposer /> ) ;
318+ await screen . getByRole ( "link" , { name : "View cited assistant text: hello" } ) . click ( ) ;
319+ await expect . element ( page . getByLabelText ( "Comment on selected text" ) ) . toBeVisible ( ) ;
320+ expect ( navigation . navigate ) . toHaveBeenCalledOnce ( ) ;
321+ } finally {
322+ navigation . params = { environmentId : "environment" , threadId : "thread" } ;
323+ }
324+ } ) ;
0 commit comments