import * as vscode from 'vscode' ; import * as chai from 'chai' ; import * as sinon from 'sinon' ; import * as path from 'path' ; import { ExtensionCommands } from '../../ExtensionCommands' ; import { LogType } from 'ibm-blockchain-platform-common' ; import { VSCodeBlockchainOutputAdapter } from '../../extension/logging/VSCodeBlockchainOutputAdapter' ; import { ExtensionUtil } from '../../extension/util/ExtensionUtil' ; import { TestUtil } from '../TestUtil' ; chai . should ( ) ; describe ( 'openReleaseNotes' , ( ) => { let mySandbox ; let logSpy ; before ( async ( ) => { mySandbox = sinon . createSandbox ( ) ; await TestUtil . setupTests ( mySandbox ) ; } ) ; beforeEach ( async ( ) => { logSpy = mySandbox . spy ( VSCodeBlockchainOutputAdapter . instance ( ) , 'log' ) ; } ) ; afterEach ( async ( ) => { mySandbox . restore ( ) ; } ) ; it ( 'should open release notes markdown file' , async ( ) => { await vscode . commands . executeCommand ( ExtensionCommands . OPEN_RELEASE_NOTES ) ; logSpy . should . have . been . calledWithExactly ( LogType . INFO , undefined , `openReleaseNotes` ) ; } ) ; it ( `should report that the release notes can't be opened` , async ( ) => { const releaseNotesPath = path . join ( ExtensionUtil . getExtensionPath ( ) , 'RELEASE-NOTES.md' ) ; const releaseNotesUri = vscode . Uri . file ( releaseNotesPath ) ; const executeCommandStub = mySandbox . stub ( vscode . commands , 'executeCommand' ) ; executeCommandStub . callThrough ( ) ; const error = new Error ( 'unable to preview markdown' ) ; executeCommandStub . withArgs ( 'markdown.showPreview' , releaseNotesUri ) . throws ( error ) ; await vscode . commands . executeCommand ( ExtensionCommands . OPEN_RELEASE_NOTES ) ; logSpy . should . have . been . calledWithExactly ( LogType . INFO , undefined , `openReleaseNotes` ) ; logSpy . should . have . been . calledWithExactly ( LogType . ERROR , `Unable to open release notes: ${ error . toString ( ) }` ) ; executeCommandStub . should . have . been . calledWith ( 'markdown.showPreview' , releaseNotesUri ) ; } ) ; } ) ;