1717jest . mock ( 'vscode' , ( ) => ( {
1818 window : {
1919 showErrorMessage : jest . fn ( ) ,
20+ showInformationMessage : jest . fn ( ) ,
2021 showWarningMessage : jest . fn ( ) ,
2122 }
2223} ) ) ;
@@ -32,7 +33,6 @@ jest.mock('path', () => {
3233} ) ;
3334
3435import { TestDataHandler } from '../../../__test__/test-data' ;
35- import * as vscode from 'vscode' ;
3636import { extensionContextFactory } from '../../../vscode-api/extension-context.factories' ;
3737import { commandsProviderFactory , MockCommandsProvider } from '../../../vscode-api/commands-provider.factories' ;
3838import { MergeCommand } from './merge-command' ;
@@ -42,6 +42,7 @@ import * as os from 'os';
4242import * as path from 'path' ;
4343import * as fsUtils from '../../../utils/fs-utils' ;
4444import { MergeSessionCoordinator } from './merge-session-coordinator' ;
45+ import { messageProviderFactory , MockMessageProvider } from '../../../vscode-api/message-provider.factories' ;
4546
4647jest . mock ( 'child_process' ) ;
4748jest . mock ( 'os' ) ;
@@ -50,6 +51,7 @@ describe('MergeCommand', () => {
5051 let commandsProvider : MockCommandsProvider ;
5152 let command : MergeCommand ;
5253 let mergeSessionCoordinator : jest . Mocked < MergeSessionCoordinator > ;
54+ let messageProvider : MockMessageProvider ;
5355 const testDataHandler = new TestDataHandler ( ) ;
5456 let tmpDir : string ;
5557
@@ -82,11 +84,13 @@ describe('MergeCommand', () => {
8284 commandsProvider = commandsProviderFactory ( ) ;
8385 mergeSessionCoordinator = {
8486 activate : jest . fn ( ) . mockResolvedValue ( ) ,
87+ onMergeApplied : jest . fn ( ) . mockReturnValue ( { dispose : jest . fn ( ) } ) ,
8588 startSession : jest . fn ( ) ,
8689 cancelSession : jest . fn ( ) ,
87- onMergeProcessExit : jest . fn ( ) . mockResolvedValue ( ) ,
90+ onMergeProcessExit : jest . fn ( ) . mockResolvedValue ( { applied : false } ) ,
8891 } ;
89- command = new MergeCommand ( commandsProvider , mergeSessionCoordinator ) ;
92+ messageProvider = messageProviderFactory ( ) ;
93+ command = new MergeCommand ( commandsProvider , mergeSessionCoordinator , messageProvider ) ;
9094
9195 componentNode = new COutlineItem ( 'component' ) ;
9296 componentNode . setTag ( 'component' ) ;
@@ -106,10 +110,23 @@ describe('MergeCommand', () => {
106110 await command . activate ( extensionContextFactory ( ) ) ;
107111
108112 expect ( mergeSessionCoordinator . activate ) . toHaveBeenCalledTimes ( 1 ) ;
113+ expect ( mergeSessionCoordinator . onMergeApplied ) . toHaveBeenCalledTimes ( 1 ) ;
109114 expect ( commandsProvider . registerCommand ) . toHaveBeenCalledTimes ( 1 ) ;
110115 expect ( commandsProvider . registerCommand ) . toHaveBeenCalledWith ( MergeCommand . mergeFile , expect . any ( Function ) , expect . anything ( ) ) ;
111116 } ) ;
112117
118+ it ( 'shows success info when coordinator emits merge-applied event' , async ( ) => {
119+ await command . activate ( extensionContextFactory ( ) ) ;
120+
121+ const listener = mergeSessionCoordinator . onMergeApplied . mock . calls [ 0 ] ?. [ 0 ] as ( ( ) => void ) | undefined ;
122+ expect ( listener ) . toBeDefined ( ) ;
123+ listener ?.( ) ;
124+
125+ expect ( messageProvider . showInformationMessage ) . toHaveBeenCalledWith (
126+ 'Merge applied successfully. Merge View can be closed.' ,
127+ ) ;
128+ } ) ;
129+
113130 it ( 'forwards string command argument to the merge handler' , async ( ) => {
114131 const runVSCodeMergeFromPathSpy = jest . spyOn (
115132 command as unknown as { runVSCodeMergeFromPath : ( localPath : string ) => Promise < void > } ,
@@ -136,22 +153,18 @@ describe('MergeCommand', () => {
136153 } ) ;
137154
138155 it ( 'shows error for unsupported command argument type' , async ( ) => {
139- const showErrorMessageSpy = jest . spyOn ( vscode . window , 'showErrorMessage' ) ;
140-
141156 await command . activate ( extensionContextFactory ( ) ) ;
142157 await commandsProvider . mockRunRegistered ( MergeCommand . mergeFile , undefined ) ;
143158
144- expect ( showErrorMessageSpy ) . toHaveBeenCalledWith ( 'Cannot open merge view: unsupported command argument.' ) ;
159+ expect ( messageProvider . showErrorMessage ) . toHaveBeenCalledWith ( 'Cannot open merge view: unsupported command argument.' ) ;
145160 } ) ;
146161 } ) ;
147162
148163 describe ( 'merge file discovery' , ( ) => {
149164 it ( 'shows error if merge path is missing when invoked from path' , async ( ) => {
150- const showErrorMessageSpy = jest . spyOn ( vscode . window , 'showErrorMessage' ) ;
151-
152165 await command [ 'runVSCodeMergeFromPath' ] ( '' ) ;
153166
154- expect ( showErrorMessageSpy ) . toHaveBeenCalledWith ( 'Cannot open merge view: merge file path is missing.' ) ;
167+ expect ( messageProvider . showErrorMessage ) . toHaveBeenCalledWith ( 'Cannot open merge view: merge file path is missing.' ) ;
155168 } ) ;
156169
157170 it ( 'normalizes the merge path before opening merge view from path' , async ( ) => {
@@ -167,17 +180,15 @@ describe('MergeCommand', () => {
167180 } ) ;
168181
169182 it ( 'shows error if node is not passed' , async ( ) => {
170- const showErrorMessageSpy = jest . spyOn ( vscode . window , 'showErrorMessage' ) ;
171183 // @ts -expect-error - testing behavior when `runVSCodeMerge` receives null
172184 await command [ 'runVSCodeMerge' ] ( null ) ;
173- expect ( showErrorMessageSpy ) . toHaveBeenCalledWith ( 'File data is not available for merge operation.' ) ;
185+ expect ( messageProvider . showErrorMessage ) . toHaveBeenCalledWith ( 'File data is not available for merge operation.' ) ;
174186 } ) ;
175187
176188 it ( 'shows error if required local file is missing' , async ( ) => {
177- const showErrorMessageSpy = jest . spyOn ( vscode . window , 'showErrorMessage' ) ;
178189 const node = new COutlineItem ( 'file' ) ;
179190 await command [ 'runVSCodeMerge' ] ( node ) ;
180- expect ( showErrorMessageSpy ) . toHaveBeenCalledWith ( 'Required local file is missing to perform merge.' ) ;
191+ expect ( messageProvider . showErrorMessage ) . toHaveBeenCalledWith ( 'Required local file is missing to perform merge.' ) ;
181192 } ) ;
182193
183194 it ( 'finds update and base files using the highest matching semver sibling' , ( ) => {
@@ -338,9 +349,8 @@ describe('MergeCommand', () => {
338349 throw new Error ( 'not found' ) ;
339350 } ) ;
340351
341- const showErrorMessageSpy = jest . spyOn ( vscode . window , 'showErrorMessage' ) ;
342352 await command [ 'runVSCodeMerge' ] ( fileNode ) ;
343- expect ( showErrorMessageSpy ) . toHaveBeenCalledWith ( 'Visual Studio Code executable not found. Please ensure it is installed and available in your PATH.' ) ;
353+ expect ( messageProvider . showErrorMessage ) . toHaveBeenCalledWith ( 'Visual Studio Code executable not found. Please ensure it is installed and available in your PATH.' ) ;
344354 } ) ;
345355 } ) ;
346356
@@ -375,10 +385,9 @@ describe('MergeCommand', () => {
375385 mockedExec . mockImplementation ( ( _cmd , _cb ) => { throw new Error ( 'unexpected' ) ; } ) ;
376386
377387 const errorSpy = jest . spyOn ( console , 'error' ) . mockImplementation ( ( ) => { } ) ;
378- const showErrorMessageSpy = jest . spyOn ( vscode . window , 'showErrorMessage' ) ;
379388 await command [ 'runVSCodeMerge' ] ( fileNode ) ;
380389 expect ( errorSpy ) . toHaveBeenCalledWith ( 'Merge operations failed:' , expect . any ( Error ) ) ;
381- expect ( showErrorMessageSpy ) . toHaveBeenCalledWith ( 'Merge operation failed: unexpected' ) ;
390+ expect ( messageProvider . showErrorMessage ) . toHaveBeenCalledWith ( 'Merge operation failed: unexpected' ) ;
382391 expect ( mergeSessionCoordinator . cancelSession ) . toHaveBeenCalledTimes ( 1 ) ;
383392 } ) ;
384393
@@ -400,11 +409,9 @@ describe('MergeCommand', () => {
400409 jest . spyOn ( fsUtils , 'copyFile' ) . mockImplementation ( ( ) => { } ) ;
401410 jest . spyOn ( fsUtils , 'getFileModificationTime' ) . mockReturnValue ( 1000 ) ;
402411
403- const showErrorMessageSpy = jest . spyOn ( vscode . window , 'showErrorMessage' ) ;
404-
405412 await command [ 'runVSCodeMerge' ] ( node ) ;
406413
407- expect ( showErrorMessageSpy ) . toHaveBeenCalledWith ( 'Merge operation failed: Invalid update file: contains unsupported shell-sensitive characters.' ) ;
414+ expect ( messageProvider . showErrorMessage ) . toHaveBeenCalledWith ( 'Merge operation failed: Invalid update file: contains unsupported shell-sensitive characters.' ) ;
408415 expect ( mergeSessionCoordinator . cancelSession ) . toHaveBeenCalledTimes ( 1 ) ;
409416 } ) ;
410417
@@ -441,5 +448,6 @@ describe('MergeCommand', () => {
441448 expect ( mergeSessionCoordinator . onMergeProcessExit ) . toHaveBeenCalledWith ( 0 ) ;
442449 expect ( mergeSessionCoordinator . cancelSession ) . not . toHaveBeenCalled ( ) ;
443450 } ) ;
451+
444452 } ) ;
445453} ) ;
0 commit comments