1919 * Unit test for ComponentViewerTreeDataProvider.
2020 */
2121
22+ import * as vscode from 'vscode' ;
2223import { ComponentViewerTreeDataProvider } from '../../component-viewer-tree-view' ;
2324import type { ScvdGuiInterface } from '../../model/scvd-gui-interface' ;
2425
@@ -30,10 +31,20 @@ jest.mock('vscode', () => {
3031 public event = jest . fn ( ) ;
3132 }
3233
34+ class MarkdownString {
35+ public value : string ;
36+ public supportHtml = false ;
37+
38+ constructor ( value : string ) {
39+ this . value = value ;
40+ }
41+ }
42+
3343 class TreeItem {
3444 public label : string ;
3545 public collapsibleState : number | undefined ;
3646 public description : string | undefined ;
47+ public tooltip : string | MarkdownString | undefined ;
3748 public id : string | undefined ;
3849 public contextValue : string | undefined ;
3950
@@ -44,6 +55,7 @@ jest.mock('vscode', () => {
4455
4556 return {
4657 EventEmitter,
58+ MarkdownString,
4759 TreeItem,
4860 TreeItemCollapsibleState : {
4961 Collapsed : 1 ,
@@ -104,12 +116,38 @@ describe('ComponentViewerTreeDataProvider', () => {
104116 expect ( treeItemWithChildren . collapsibleState ) . toBe ( 1 ) ;
105117 expect ( treeItemWithChildren . description ) . toBe ( 'Value' ) ;
106118 expect ( treeItemWithChildren . id ) . toBe ( 'id-1' ) ;
119+ const resolvedWith = provider . resolveTreeItem ( treeItemWithChildren , withChildren ) as vscode . TreeItem ;
120+ expect ( resolvedWith . tooltip ) . toBeInstanceOf ( vscode . MarkdownString ) ;
121+ const tooltipWith = resolvedWith . tooltip as { value : string ; supportHtml : boolean } ;
122+ expect ( tooltipWith . value ) . toBe ( '**Node** \nValue' ) ;
123+ expect ( tooltipWith . supportHtml ) . toBe ( true ) ;
107124
108125 const treeItemWithout = provider . getTreeItem ( withoutChildren ) ;
109126 expect ( treeItemWithout . label ) . toBe ( 'UNKNOWN' ) ;
110127 expect ( treeItemWithout . collapsibleState ) . toBe ( 0 ) ;
111128 expect ( treeItemWithout . description ) . toBe ( '' ) ;
112129 expect ( treeItemWithout . id ) . toBeUndefined ( ) ;
130+ const resolvedWithout = provider . resolveTreeItem ( treeItemWithout , withoutChildren ) as vscode . TreeItem ;
131+ expect ( resolvedWithout . tooltip ) . toBeUndefined ( ) ;
132+ } ) ;
133+
134+ it ( 'formats tooltip for name-only, value-only, and empty values' , ( ) => {
135+ const provider = new ComponentViewerTreeDataProvider ( ) ;
136+ const nameOnly = makeGui ( { getGuiValue : ( ) => undefined } ) ;
137+ const valueOnly = makeGui ( { getGuiName : ( ) => undefined } ) ;
138+ const emptyBoth = makeGui ( { getGuiName : ( ) => undefined , getGuiValue : ( ) => undefined } ) ;
139+
140+ const nameItem = provider . resolveTreeItem ( new vscode . TreeItem ( 'Label' ) , nameOnly ) as vscode . TreeItem ;
141+ expect ( nameItem . tooltip ) . toBeInstanceOf ( vscode . MarkdownString ) ;
142+ const nameTooltip = nameItem . tooltip as { value : string ; supportHtml : boolean } ;
143+ expect ( nameTooltip . value ) . toBe ( '**Node**' ) ;
144+ expect ( nameTooltip . supportHtml ) . toBe ( false ) ;
145+
146+ const valueItem = provider . resolveTreeItem ( new vscode . TreeItem ( 'Label' ) , valueOnly ) as vscode . TreeItem ;
147+ expect ( valueItem . tooltip ) . toBe ( 'Value' ) ;
148+
149+ const emptyItem = provider . resolveTreeItem ( new vscode . TreeItem ( 'Label' ) , emptyBoth ) as vscode . TreeItem ;
150+ expect ( emptyItem . tooltip ) . toBeUndefined ( ) ;
113151 } ) ;
114152
115153 it ( 'assigns locked context values for root and child nodes' , ( ) => {
0 commit comments