@@ -140,15 +140,23 @@ describe('ChatNavigationLink', () => {
140140
141141 it ( 'prefetches before direct mouse clicks and completed touch taps' , ( ) => {
142142 const link = renderLink ( )
143+ linkPrefetch . mockClear ( )
143144
144- act ( ( ) => link . dispatchEvent ( pointerEvent ( 'pointerdown' , 'mouse' , { button : 0 } ) ) )
145+ act ( ( ) => {
146+ link . dispatchEvent ( pointerEvent ( 'pointerdown' , 'mouse' , { button : 0 } ) )
147+ link . dispatchEvent ( new MouseEvent ( 'click' , { bubbles : true , cancelable : true } ) )
148+ } )
145149
146150 expect ( linkPrefetch ) . toHaveBeenLastCalledWith ( true )
147151 expect ( prefetchQuery ) . toHaveBeenCalledTimes ( 1 )
148152
149153 act ( ( ) => link . dispatchEvent ( new FocusEvent ( 'focusout' , { bubbles : true } ) ) )
154+ linkPrefetch . mockClear ( )
150155 prefetchQuery . mockClear ( )
151- act ( ( ) => link . dispatchEvent ( pointerEvent ( 'pointerup' , 'touch' , { button : 0 } ) ) )
156+ act ( ( ) => {
157+ link . dispatchEvent ( pointerEvent ( 'pointerup' , 'touch' , { button : 0 } ) )
158+ link . dispatchEvent ( new MouseEvent ( 'click' , { bubbles : true , cancelable : true } ) )
159+ } )
152160
153161 expect ( linkPrefetch ) . toHaveBeenLastCalledWith ( true )
154162 expect ( prefetchQuery ) . toHaveBeenCalledTimes ( 1 )
@@ -200,6 +208,45 @@ describe('ChatNavigationLink', () => {
200208 expect ( prefetchQuery ) . not . toHaveBeenCalled ( )
201209 } )
202210
211+ it ( 'clears prior intent when a persistent row changes route roles' , ( ) => {
212+ const renderRouteRole = ( isCurrentRoute : boolean ) => {
213+ act ( ( ) => {
214+ root . render (
215+ < QueryClientProvider client = { queryClient } >
216+ < ChatNavigationLink
217+ chatId = 'chat-1'
218+ href = '/workspace/ws-1/chat/chat-1'
219+ isCurrentRoute = { isCurrentRoute }
220+ >
221+ Open chat
222+ </ ChatNavigationLink >
223+ </ QueryClientProvider >
224+ )
225+ } )
226+ }
227+
228+ renderRouteRole ( false )
229+ const link = container . querySelector ( 'a' )
230+ if ( ! link ) throw new Error ( 'chat link not rendered' )
231+ act ( ( ) => {
232+ link . dispatchEvent ( pointerEvent ( 'pointerdown' , 'mouse' , { button : 0 } ) )
233+ link . dispatchEvent ( new MouseEvent ( 'click' , { bubbles : true , cancelable : true } ) )
234+ } )
235+ expect ( linkPrefetch ) . toHaveBeenLastCalledWith ( true )
236+
237+ renderRouteRole ( true )
238+ renderRouteRole ( false )
239+
240+ expect ( linkPrefetch ) . toHaveBeenLastCalledWith ( false )
241+ prefetchQuery . mockClear ( )
242+ const destinationLink = container . querySelector ( 'a' )
243+ if ( ! destinationLink ) throw new Error ( 'destination link not rendered' )
244+ act ( ( ) => {
245+ destinationLink . dispatchEvent ( new MouseEvent ( 'click' , { bubbles : true , cancelable : true } ) )
246+ } )
247+ expect ( prefetchQuery ) . toHaveBeenCalledTimes ( 1 )
248+ } )
249+
203250 it ( 'does not prefetch when the click is canceled or opens another browsing context' , ( ) => {
204251 const canceledLink = renderLink ( )
205252
0 commit comments