22 IApplicationService ,
33 IClipboardService ,
44 IContextKeyService ,
5- OS ,
5+ OperatingSystem ,
66 PreferenceService ,
77 QuickOpenService ,
88} from '@opensumi/ide-core-browser' ;
@@ -15,6 +15,7 @@ import { EXPLORER_CONTAINER_ID } from '@opensumi/ide-explorer/lib/browser/explor
1515import { IFileServiceClient } from '@opensumi/ide-file-service' ;
1616import { IFileTreeAPI , IFileTreeService } from '@opensumi/ide-file-tree-next' ;
1717import { FileTreeContribution } from '@opensumi/ide-file-tree-next/lib/browser/file-tree-contribution' ;
18+ import { FileTreeModelService } from '@opensumi/ide-file-tree-next/lib/browser/services/file-tree-model.service' ;
1819import { IMainLayoutService , IViewsRegistry } from '@opensumi/ide-main-layout' ;
1920import { ViewsRegistry } from '@opensumi/ide-main-layout/lib/browser/views-registry' ;
2021import { IDialogService , IMessageService , IWindowDialogService } from '@opensumi/ide-overlay' ;
@@ -26,6 +27,8 @@ import { MockQuickOpenService } from '../../../quick-open/src/common/mocks/quick
2627
2728describe ( 'FileTreeContribution' , ( ) => {
2829 let mockInjector : MockInjector ;
30+ let mockClipboardService ;
31+ let mockFileTreeModelService ;
2932 const tabbarHandlerMap = new Map ( ) ;
3033
3134 const mockMainLayoutService = {
@@ -38,6 +41,7 @@ describe('FileTreeContribution', () => {
3841 updateViewTitle : jest . fn ( ) ,
3942 onActivate : jest . fn ( ) ,
4043 onInActivate : jest . fn ( ) ,
44+ isActivated : jest . fn ( ( ) => true ) ,
4145 } ;
4246 tabbarHandlerMap . set ( name , handler ) ;
4347 return handler ;
@@ -72,6 +76,22 @@ describe('FileTreeContribution', () => {
7276
7377 beforeEach ( ( ) => {
7478 mockInjector = createBrowserInjector ( [ ] ) ;
79+ mockClipboardService = {
80+ writeText : jest . fn ( ) ,
81+ } ;
82+ mockFileTreeModelService = {
83+ selectedFiles : [ ] ,
84+ focusedFile : undefined ,
85+ contextMenuFile : undefined ,
86+ whenReady : Promise . resolve ( ) ,
87+ contextKey : {
88+ explorerViewletVisibleContext : {
89+ set : jest . fn ( ) ,
90+ } ,
91+ } ,
92+ performLocationOnHandleShow : jest . fn ( ) ,
93+ handleTreeBlur : jest . fn ( ) ,
94+ } ;
7595
7696 mockInjector . overrideProviders (
7797 {
@@ -112,7 +132,11 @@ describe('FileTreeContribution', () => {
112132 } ,
113133 {
114134 token : IClipboardService ,
115- useValue : { } ,
135+ useValue : mockClipboardService ,
136+ } ,
137+ {
138+ token : FileTreeModelService ,
139+ useValue : mockFileTreeModelService ,
116140 } ,
117141 {
118142 token : IDialogService ,
@@ -137,7 +161,8 @@ describe('FileTreeContribution', () => {
137161 {
138162 token : IApplicationService ,
139163 useValue : {
140- getBackendOS : ( ) => Promise . resolve ( OS . type ( ) ) ,
164+ backendOS : Promise . resolve ( OperatingSystem . Linux ) ,
165+ getBackendOS : ( ) => Promise . resolve ( OperatingSystem . Linux ) ,
141166 } ,
142167 } ,
143168 ) ;
@@ -205,4 +230,42 @@ describe('FileTreeContribution', () => {
205230 expect ( register ) . toHaveBeenCalled ( ) ;
206231 } ) ;
207232 } ) ;
233+
234+ describe ( 'copy path commands' , ( ) => {
235+ const registerCommands = ( ) => {
236+ const contribution = mockInjector . get ( FileTreeContribution ) ;
237+ const commands = new Map < string , any > ( ) ;
238+ contribution . registerCommands ( {
239+ registerCommand : jest . fn ( ( command , handler ) => {
240+ commands . set ( command . id , { command, ...handler } ) ;
241+ } ) ,
242+ } as any ) ;
243+ return commands ;
244+ } ;
245+
246+ it ( 'uses the selected explorer file when copy path is triggered from a shortcut' , async ( ) => {
247+ mockFileTreeModelService . selectedFiles = [ { uri : URI . file ( '/userhome/test.ts' ) } ] ;
248+ const commands = registerCommands ( ) ;
249+
250+ await commands . get ( 'filetree.copy.path' ) . execute ( ) ;
251+
252+ expect ( mockClipboardService . writeText ) . toHaveBeenCalledWith ( '/userhome/test.ts' ) ;
253+ } ) ;
254+
255+ it ( 'uses the selected explorer file when copy relative path is triggered from a shortcut' , async ( ) => {
256+ mockFileTreeModelService . selectedFiles = [ { uri : URI . file ( '/userhome/test.ts' ) } ] ;
257+ const commands = registerCommands ( ) ;
258+
259+ await commands . get ( 'filetree.copy.relativepath' ) . execute ( ) ;
260+
261+ expect ( mockClipboardService . writeText ) . toHaveBeenCalledWith ( 'test.ts' ) ;
262+ } ) ;
263+
264+ it ( 'exposes labels for copy path commands so users can configure shortcuts' , ( ) => {
265+ const commands = registerCommands ( ) ;
266+
267+ expect ( commands . get ( 'filetree.copy.path' ) . command . label ) . toBe ( '%file.copy.path%' ) ;
268+ expect ( commands . get ( 'filetree.copy.relativepath' ) . command . label ) . toBe ( '%file.copy.relativepath%' ) ;
269+ } ) ;
270+ } ) ;
208271} ) ;
0 commit comments