@@ -8,6 +8,16 @@ import { expect, it, vi } from "vite-plus/test";
88
99import { page , userEvent } from "vite-plus/test/browser" ;
1010
11+ const navigation = vi . hoisted ( ( ) => ( {
12+ navigate : vi . fn ( ) ,
13+ params : { environmentId : "environment" , threadId : "thread" } ,
14+ } ) ) ;
15+ vi . mock ( import ( "@tanstack/react-router" ) , async ( importOriginal ) => ( {
16+ ...( await importOriginal ( ) ) ,
17+ useNavigate : ( ) => navigation . navigate ,
18+ useParams : ( ( ) => navigation . params ) as typeof import ( "@tanstack/react-router" ) . useParams ,
19+ } ) ) ;
20+
1121import { findAssistantCitationSourceAnchor } from "~/lib/assistantTextSelection" ;
1222import { act , render } from "../../test/render" ;
1323import {
@@ -179,3 +189,35 @@ it("reanchors the comment when the cited source mounts after activation", async
179189 expect ( highlight && [ ...highlight ] [ 0 ] ?. startContainer . parentElement ) . toBe ( source ) ;
180190 } ) ;
181191} ) ;
192+
193+ it . each ( [
194+ [ "environment" , "other-thread" , "click" ] ,
195+ [ "environment" , "other-thread" , "Enter" ] ,
196+ [ "environment" , "other-thread" , " " ] ,
197+ [ "other-environment" , "thread" , "click" ] ,
198+ [ "other-environment" , "thread" , "Enter" ] ,
199+ [ "other-environment" , "thread" , " " ] ,
200+ ] ) (
201+ "edits a citation from draft %s/%s with %s without navigating" ,
202+ async ( environmentId , threadId , activation ) => {
203+ navigation . navigate . mockClear ( ) ;
204+ navigation . params = { environmentId, threadId } ;
205+ try {
206+ const editorRef = createRef < ComposerPromptEditorHandle > ( ) ;
207+ await using screen = await render (
208+ < Composer question = { false } editorRef = { editorRef } sourceVisible = { false } /> ,
209+ ) ;
210+ const chip = screen . getByRole ( "link" , { name : "View cited assistant text: hello" } ) ;
211+ if ( activation === "click" ) {
212+ await chip . click ( ) ;
213+ } else {
214+ chip . element ( ) . focus ( ) ;
215+ await userEvent . keyboard ( activation === "Enter" ? "{Enter}" : " " ) ;
216+ }
217+ await expect . element ( page . getByLabelText ( "Comment on selected text" ) ) . toBeVisible ( ) ;
218+ expect ( navigation . navigate ) . not . toHaveBeenCalled ( ) ;
219+ } finally {
220+ navigation . params = { environmentId : "environment" , threadId : "thread" } ;
221+ }
222+ } ,
223+ ) ;
0 commit comments