@@ -154,12 +154,22 @@ describe('LiveWatchTreeDataProvider', () => {
154154 expect ( parent . children . length ) . toBe ( 0 ) ;
155155 } ) ;
156156
157- it ( 'getTreeItem returns correct TreeItem' , ( ) => {
158- const node = makeNode ( 'expression' , { result : 'value' , variablesReference : 1 } , 1 ) ;
157+ it ( 'returns correct TreeItem for parent nodes ' , ( ) => {
158+ const node = makeNode ( 'expression' , { result : 'value' , variablesReference : 0 } , 1 ) ;
159159 const item = liveWatchTreeDataProvider . getTreeItem ( node ) ;
160160 expect ( item . label ) . toBe ( 'expression = ' ) ;
161161 expect ( item . description ) . toBe ( 'value' ) ;
162- expect ( item . contextValue ) . toBe ( 'expression' ) ;
162+ expect ( item . contextValue ) . toBe ( 'parentExpression' ) ;
163+ } ) ;
164+
165+ it ( 'returns correct TreeItem for leaf nodes' , ( ) => {
166+ // Create a child node within a parent node
167+ const parent = makeNode ( 'parentExpression' , { result : 'parentValue' , variablesReference : 1 } , 1 ) ;
168+ const child = makeNode ( 'childExpression' , { result : 'childValue' , variablesReference : 0 } , 2 , parent ) ;
169+ const item = liveWatchTreeDataProvider . getTreeItem ( child ) ;
170+ expect ( item . label ) . toBe ( 'childExpression = ' ) ;
171+ expect ( item . description ) . toBe ( 'childValue' ) ;
172+ expect ( item . contextValue ) . toBe ( 'childExpression' ) ;
163173 } ) ;
164174 } ) ;
165175
@@ -220,14 +230,18 @@ describe('LiveWatchTreeDataProvider', () => {
220230
221231 it ( 'AddFromSelection adds selected text as new live watch expression to roots' , async ( ) => {
222232 jest . spyOn ( liveWatchTreeDataProvider as any , 'evaluate' ) . mockResolvedValue ( { result : '5678' , variablesReference : 0 } ) ;
223- // Mock the active text editor with a selection whose active position returns a word range
224- const fakeRange = { start : { line : 0 , character : 0 } , end : { line : 0 , character : 10 } } ;
233+ // Mock the active text editor with fake range
234+ const fakeRange = { start : { line : 0 , character : 0 } , end : { line : 0 , character : 17 } } ;
225235 const mockEditor : any = {
226236 document : {
227- getWordRangeAtPosition : jest . fn ( ) . mockReturnValue ( fakeRange ) ,
228- getText : jest . fn ( ) . mockReturnValue ( 'selected-expression' )
237+ getText : jest . fn ( ) . mockReturnValue ( 'selected-expression' ) ,
238+ getWordRangeAtPosition : jest . fn ( ) . mockReturnValue ( fakeRange )
229239 } ,
230- selection : { active : { line : 0 , character : 5 } }
240+ selection : {
241+ active : { line : 0 , character : 5 } ,
242+ start : { line : 0 , character : 0 } ,
243+ end : { line : 0 , character : 17 }
244+ }
231245 } ;
232246 ( vscode . window as any ) . activeTextEditor = mockEditor ;
233247 await ( liveWatchTreeDataProvider as any ) . handleAddFromSelectionCommand ( ) ;
@@ -238,6 +252,25 @@ describe('LiveWatchTreeDataProvider', () => {
238252 expect ( roots [ 0 ] . expression ) . toBe ( 'selected-expression' ) ;
239253 expect ( roots [ 0 ] . value . result ) . toBe ( '5678' ) ;
240254 } ) ;
255+
256+ it ( 'AddFromSelection does nothing when selection spans multiple lines' , async ( ) => {
257+ const mockEditor : any = {
258+ document : {
259+ getText : jest . fn ( ) . mockReturnValue ( 'multi-line\nselection' ) ,
260+ getWordRangeAtPosition : jest . fn ( ) . mockReturnValue ( undefined )
261+ } ,
262+ selection : {
263+ active : { line : 0 , character : 5 } ,
264+ start : { line : 0 , character : 0 } ,
265+ end : { line : 1 , character : 9 }
266+ }
267+ } ;
268+ ( vscode . window as any ) . activeTextEditor = mockEditor ;
269+ await ( liveWatchTreeDataProvider as any ) . handleAddFromSelectionCommand ( ) ;
270+ const roots = ( liveWatchTreeDataProvider as any ) . roots ;
271+ expect ( mockEditor . document . getWordRangeAtPosition ) . toHaveBeenCalledWith ( mockEditor . selection . active ) ;
272+ expect ( roots . length ) . toBe ( 0 ) ;
273+ } ) ;
241274 } ) ;
242275
243276 describe ( 'refresh' , ( ) => {
0 commit comments