'use strict' ; import * as vscode from 'vscode' ; import * as sinon from 'sinon' ; import * as path from 'path' ; import * as chai from 'chai' ; import * as sinonChai from 'sinon-chai' ; import * as chaiAsPromised from 'chai-as-promised' ; import { UserInputUtil } from '../../extension/commands/UserInputUtil' ; import { UserInputUtilHelper } from './userInputUtilHelper' ; import { SmartContractHelper } from './smartContractHelper' ; import { SampleView } from '../../extension/webview/SampleView' ; import { FileConfigurations } from 'ibm-blockchain-platform-common' ; chai . use ( sinonChai ) ; chai . use ( chaiAsPromised ) ; export enum LanguageType { CHAINCODE = 'chaincode' , CONTRACT = 'contract' } export class SampleHelper { mySandBox : sinon . SinonSandbox ; userInputUtilHelper : UserInputUtilHelper ; smartContractHelper : SmartContractHelper ; constructor ( sandbox , userInputUtilHelper , smartContractHelper ) { this . mySandBox = sandbox ; this . userInputUtilHelper = userInputUtilHelper ; this . smartContractHelper = smartContractHelper ; } public async cloneSample ( repositoryName , sampleName ) { const repositoryPath = path . join ( this . userInputUtilHelper . cucumberDir , 'tmp' , FileConfigurations . REPOSITORIES , repositoryName ) ; this . userInputUtilHelper . showSaveDialogStub . withArgs ( { defaultUri : sinon . match . any , saveLabel : 'Clone Repository' } ) . resolves ( vscode . Uri . file ( repositoryPath ) ) ; const sampleView = new SampleView ( null , repositoryName , sampleName ) ; await sampleView [ 'cloneRepository' ] ( false ) ; return sampleView ; } public async openContract ( sampleView , sampleName , language , contractName ) { this . userInputUtilHelper . showFolderOptionsStub . withArgs ( 'Choose how to open the sample files' ) . resolves ( UserInputUtil . ADD_TO_WORKSPACE ) ; await sampleView [ 'cloneAndOpenRepository' ] ( `chaincode/${ sampleName }/${ language }` , 'main' , contractName , [ ] ) ; } }