@@ -13,14 +13,17 @@ it("keeps source observations across typing and releases virtualized sources", a
1313 mocks . findAnchor . mockReset ( ) ;
1414 const viewport = document . createElement ( "div" ) ;
1515 const source = document . createElement ( "p" ) ;
16- source . textContent = "hello" ;
16+ viewport . style . cssText = "position: fixed; left: 0; top: 0; width: 400px; height: 100px" ;
17+ source . style . width = "200px" ;
18+ source . textContent = "hello again" ;
1719 viewport . append ( source ) ;
1820 document . body . append ( viewport ) ;
1921 using _fixture = { [ Symbol . dispose ] : ( ) => viewport . remove ( ) } ;
2022 mocks . findAnchor . mockImplementation ( ( ) => {
2123 if ( ! viewport . contains ( source ) ) return null ;
2224 const range = document . createRange ( ) ;
23- range . selectNodeContents ( source ) ;
25+ range . setStart ( source . firstChild ! , 0 ) ;
26+ range . setEnd ( source . firstChild ! , 5 ) ;
2427 return { source, range } ;
2528 } ) ;
2629 const prompt = serializeAssistantCitation ( {
@@ -50,6 +53,9 @@ it("keeps source observations across typing and releases virtualized sources", a
5053 expect ( markers [ 0 ] ! . style . left ) . not . toBe ( "" ) ;
5154 expect ( markers [ 0 ] ! . style . left ) . not . toBe ( markers [ 1 ] ! . style . left ) ;
5255 expect ( markers [ 0 ] ! . style . top ) . toBe ( markers [ 1 ] ! . style . top ) ;
56+ expect (
57+ Number . parseFloat ( markers [ 0 ] ! . style . left ) + viewport . getBoundingClientRect ( ) . left ,
58+ ) . toBeGreaterThanOrEqual ( source . getBoundingClientRect ( ) . right ) ;
5359 } ) ;
5460 using disconnect = vi . spyOn ( MutationObserver . prototype , "disconnect" ) ;
5561 const searches = mocks . findAnchor . mock . calls . length ;
0 commit comments