diff --git a/package-lock.json b/package-lock.json index b532aa542..3869b458d 100644 --- a/package-lock.json +++ b/package-lock.json @@ -5308,7 +5308,7 @@ }, "hash.js": { "version": "1.1.7", - "resolved": "http://localhost:8080/hash.js/-/hash.js-1.1.7.tgz", + "resolved": "https://registry.npmjs.org/hash.js/-/hash.js-1.1.7.tgz", "integrity": "sha512-taOaskGt4z4SOANNseOviYDvjEJinIkRgmp7LbKP2YTTmVxWBl87s/uzK9r+44BclBSp2X7K1hqeNfz9JbBeXA==", "dev": true, "requires": { @@ -5342,7 +5342,7 @@ }, "hmac-drbg": { "version": "1.0.1", - "resolved": "http://localhost:8080/hmac-drbg/-/hmac-drbg-1.0.1.tgz", + "resolved": "https://registry.npmjs.org/hmac-drbg/-/hmac-drbg-1.0.1.tgz", "integrity": "sha1-0nRXAQJabHdabFRXk+1QL8DGSaE=", "dev": true, "requires": { @@ -7160,7 +7160,7 @@ }, "minimalistic-crypto-utils": { "version": "1.0.1", - "resolved": "http://localhost:8080/minimalistic-crypto-utils/-/minimalistic-crypto-utils-1.0.1.tgz", + "resolved": "https://registry.npmjs.org/minimalistic-crypto-utils/-/minimalistic-crypto-utils-1.0.1.tgz", "integrity": "sha1-9sAMHAsIIkblxNmd+4x8CDsrWCo=", "dev": true }, diff --git a/package.json b/package.json index 9bac621f7..c54aeccb1 100644 --- a/package.json +++ b/package.json @@ -66,6 +66,7 @@ "git-transport-protocol": "^0.1.0", "globby": "^10.0.1", "js-yaml": "^3.13.1", + "minimatch": "^3.0.4", "mkdirp": "^0.5.1", "openshift-rest-client": "^4.0.0", "rxjs": "^6.5.3", diff --git a/src/oc.ts b/src/oc.ts index 9724f576c..27e474365 100644 --- a/src/oc.ts +++ b/src/oc.ts @@ -50,10 +50,7 @@ export class Oc { if (message) { window.showWarningMessage(message); } else { - const project = await OpenShiftItem.getOpenShiftCmdData( - undefined, - 'Select a Project where to create a new resource', - ); + const project = await OpenShiftItem.getOpenShiftCmdData(undefined); if (!project) return null; const result = await CliChannel.getInstance().execute( `${toolLocation} create -f ${document.fileName} --namespace ${project.getName()}`, diff --git a/src/odo.ts b/src/odo.ts index 8527d3c9f..0ae20746d 100644 --- a/src/odo.ts +++ b/src/odo.ts @@ -36,6 +36,7 @@ const {Collapsed} = TreeItemCollapsibleState; export interface OpenShiftObject extends QuickPickItem { getChildren(): ProviderResult; removeChild(item: OpenShiftObject): Promise; + addChild(item: OpenShiftObject): Promise; getParent(): OpenShiftObject; getName(): string; contextValue: ContextType; @@ -60,6 +61,21 @@ export enum ContextType { COMPONENT_ROUTE = 'componentRoute' } +function compareNodes(a: OpenShiftObject, b: OpenShiftObject): number { + if (!a.contextValue) return -1; + if (!b.contextValue) return 1; + const acontext = a.contextValue.includes('_') ? a.contextValue.substr(0, a.contextValue.indexOf('_')) : a.contextValue; + const bcontext = b.contextValue.includes('_') ? b.contextValue.substr(0, b.contextValue.indexOf('_')) : b.contextValue; + const t = acontext.localeCompare(bcontext); + return t || a.label.localeCompare(b.label); +} + +function insert(array: OpenShiftObject[], item: OpenShiftObject): OpenShiftObject { + const i = bs(array, item, compareNodes); + array.splice(Math.abs(i)-1, 0, item); + return item; +} + export abstract class OpenShiftObjectImpl implements OpenShiftObject { private explorerPath: string; @@ -129,6 +145,11 @@ export abstract class OpenShiftObjectImpl implements OpenShiftObject { array.splice(array.indexOf(item), 1); } + public async addChild(item: OpenShiftObject): Promise { + const array = await item.getChildren(); + return insert(array, item); + } + getParent(): OpenShiftObject { return this.parent; } @@ -150,13 +171,19 @@ export class OpenShiftCluster extends OpenShiftObjectImpl { } async getChildren(): Promise { - return [(await this.odo.getProjects()).find((prj:OpenShiftProject)=>prj.active)]; + const activeProject = (await this.odo.getProjects()).find((prj:OpenShiftProject)=>prj.active) + return activeProject ? [activeProject] : []; } public async removeChild(item: OpenShiftObject): Promise { const array = await this.odo.getProjects(); array.splice(array.indexOf(item), 1); } + + public async addChild(item: OpenShiftObject): Promise { + const array = await this.odo.getProjects(); + return insert(array, item); + } } export class OpenShiftProject extends OpenShiftObjectImpl { @@ -336,15 +363,6 @@ export interface Odo { readonly subject: Subject; } -function compareNodes(a: OpenShiftObject, b: OpenShiftObject): number { - if (!a.contextValue) return -1; - if (!b.contextValue) return 1; - const acontext = a.contextValue.includes('_') ? a.contextValue.substr(0, a.contextValue.indexOf('_')) : a.contextValue; - const bcontext = b.contextValue.includes('_') ? b.contextValue.substr(0, b.contextValue.indexOf('_')) : b.contextValue; - const t = acontext.localeCompare(bcontext); - return t || a.label.localeCompare(b.label); -} - class OdoModel { private parentToChildren: Map = new Map(); @@ -756,21 +774,15 @@ export class OdoImpl implements Odo { return this.odoLoginMessages.some((msg) => result.stderr.includes(msg)); } - private insert(array: OpenShiftObject[], item: OpenShiftObject): OpenShiftObject { - const i = bs(array, item, compareNodes); - array.splice(Math.abs(i)-1, 0, item); - return item; - } - private async insertAndReveal(item: OpenShiftObject): Promise { // await OpenShiftExplorer.getInstance().reveal(this.insert(await item.getParent().getChildren(), item)); - this.subject.next(new OdoEventImpl('inserted', this.insert(await item.getParent().getChildren(), item), true)); + this.subject.next(new OdoEventImpl('inserted', await item.getParent().addChild(item), true)); return item; } private async insertAndRefresh(item: OpenShiftObject): Promise { // await OpenShiftExplorer.getInstance().refresh(this.insert(await item.getParent().getChildren(), item).getParent()); - this.subject.next(new OdoEventImpl('changed', this.insert(await item.getParent().getChildren(), item).getParent())); + this.subject.next(new OdoEventImpl('changed', (await item.getParent().addChild(item)).getParent())); return item; } @@ -789,8 +801,7 @@ export class OdoImpl implements Odo { public async createProject(projectName: string): Promise { await OdoImpl.instance.execute(Command.createProject(projectName)); const clusters = await this.getClusters(); - this.subject.next(new OdoEventImpl('inserted', clusters[0], false)); - return new OpenShiftProject(clusters[0], projectName, true); + return this.insertAndReveal(new OpenShiftProject(clusters[0], projectName, true)); } public async deleteApplication(app: OpenShiftObject): Promise { diff --git a/src/openshift/application.ts b/src/openshift/application.ts index 008879752..71a1c87f6 100644 --- a/src/openshift/application.ts +++ b/src/openshift/application.ts @@ -15,7 +15,6 @@ export class Application extends OpenShiftItem { @vsCommand('openshift.app.describe', true) static async describe(treeItem: OpenShiftObject): Promise { const application = await Application.getOpenShiftCmdData(treeItem, - "From which project you want to describe Application", "Select Application you want to describe"); if (application) Application.odo.executeInTerminal(Command.describeApplication(application.getParent().getName(), application.getName()), undefined, `OpenShift: Describe '${application.getName()}' Application`); } @@ -23,7 +22,6 @@ export class Application extends OpenShiftItem { @vsCommand('openshift.app.delete', true) static async del(treeItem: OpenShiftObject): Promise { const application = await Application.getOpenShiftCmdData(treeItem, - "From which Project you want to delete Application", "Select Application to delete"); if (application) { const appName = application.getName(); diff --git a/src/openshift/component.ts b/src/openshift/component.ts index 03197fefd..0af26214c 100644 --- a/src/openshift/component.ts +++ b/src/openshift/component.ts @@ -80,14 +80,12 @@ export class Component extends OpenShiftItem { static async getOpenshiftData(context: OpenShiftObject): Promise { return Component.getOpenShiftCmdData(context, - "In which Project you want to create a Component", "In which Application you want to create a Component" ); } @vsCommand('openshift.component.create') @selectTargetApplication( - "In which Project you want to create a Component", "In which Application you want to create a Component" ) static async create(application: OpenShiftObject): Promise { @@ -125,7 +123,6 @@ export class Component extends OpenShiftItem { @vsCommand('openshift.component.delete', true) @selectTargetComponent( - "From which Project do you want to delete Component", "From which Application you want to delete Component", "Select Component to delete" ) @@ -150,7 +147,6 @@ export class Component extends OpenShiftItem { @vsCommand('openshift.component.undeploy', true) @selectTargetComponent( - "From which Project do you want to undeploy Component", "From which Application you want to undeploy Component", "Select Component to undeploy", (target) => target.contextValue === ContextType.COMPONENT_PUSHED @@ -202,7 +198,6 @@ export class Component extends OpenShiftItem { @vsCommand('openshift.component.describe', true) @selectTargetComponent( - "From which Project you want to describe Component", "From which Application you want to describe Component", "Select Component you want to describe" ) @@ -223,7 +218,6 @@ export class Component extends OpenShiftItem { @vsCommand('openshift.component.log', true) @selectTargetComponent( - "In which Project you want to see Log", "In which Application you want to see Log", "For which Component you want to see Log", (value: OpenShiftObject) => value.contextValue === ContextType.COMPONENT_PUSHED @@ -242,7 +236,6 @@ export class Component extends OpenShiftItem { @vsCommand('openshift.component.followLog', true) @selectTargetComponent( - "In which Project you want to follow Log", "In which Application you want to follow Log", "For which Component you want to follow Log", (value: OpenShiftObject) => value.contextValue === ContextType.COMPONENT_PUSHED @@ -291,7 +284,6 @@ export class Component extends OpenShiftItem { @vsCommand('openshift.component.unlinkComponent.palette') @selectTargetComponent( - 'Select a Project', 'Select an Application', 'Select a Component', (value: OpenShiftObject) => value.contextValue === ContextType.COMPONENT_PUSHED @@ -323,7 +315,6 @@ export class Component extends OpenShiftItem { @vsCommand('openshift.component.unlinkService.palette') @selectTargetComponent( - 'Select a Project', 'Select an Application', 'Select a Component', (value: OpenShiftObject) => value.contextValue === ContextType.COMPONENT_PUSHED @@ -349,7 +340,6 @@ export class Component extends OpenShiftItem { @vsCommand('openshift.component.linkComponent') @selectTargetComponent( - 'Select a Project', 'Select an Application', 'Select a Component', (value: OpenShiftObject) => value.contextValue === ContextType.COMPONENT_PUSHED @@ -391,7 +381,6 @@ export class Component extends OpenShiftItem { @vsCommand('openshift.component.linkService') @selectTargetComponent( - 'Select a Project', 'Select an Application', 'Select a Component', (value: OpenShiftObject) => value.contextValue === ContextType.COMPONENT_PUSHED @@ -419,7 +408,6 @@ export class Component extends OpenShiftItem { @vsCommand('openshift.component.push', true) @selectTargetComponent( - 'In which Project you want to push the changes', 'In which Application you want to push the changes', 'For which Component you want to push the changes', (target) => target.contextValue === ContextType.COMPONENT_PUSHED || target.contextValue === ContextType.COMPONENT @@ -454,7 +442,6 @@ export class Component extends OpenShiftItem { @vsCommand('openshift.component.watch', true) @selectTargetComponent( - 'Select a Project', 'Select an Application', 'Select a Component you want to watch', (target) => target.contextValue === ContextType.COMPONENT_PUSHED @@ -491,7 +478,6 @@ export class Component extends OpenShiftItem { @vsCommand('openshift.component.openUrl', true) @selectTargetComponent( - 'Select a Project', 'Select an Application', 'Select a Component to open in browser', (target) => target.contextValue === ContextType.COMPONENT_PUSHED @@ -533,8 +519,7 @@ export class Component extends OpenShiftItem { @vsCommand('openshift.component.createFromLocal') @selectTargetApplication( - "In which Project you want to create a Component", - "In which Application you want to create a Component" + "Select an Application where you want to create a Component" ) static async createFromLocal(application: OpenShiftObject): Promise { if (!application) return null; @@ -559,7 +544,6 @@ export class Component extends OpenShiftItem { static async createFromFolder(folder: Uri): Promise { const application = await Component.getOpenShiftCmdData(undefined, - "In which Project you want to create a Component", "In which Application you want to create a Component" ); if (!application) return null; @@ -582,7 +566,6 @@ export class Component extends OpenShiftItem { @vsCommand('openshift.component.createFromGit') @selectTargetApplication( - "In which Project you want to create a Component", "In which Application you want to create a Component" ) static async createFromGit(application: OpenShiftObject): Promise { @@ -630,7 +613,6 @@ export class Component extends OpenShiftItem { @vsCommand('openshift.component.createFromBinary') @selectTargetApplication( - "In which Project you want to create a Component", "In which Application you want to create a Component" ) static async createFromBinary(application: OpenShiftObject): Promise { @@ -670,7 +652,6 @@ export class Component extends OpenShiftItem { @vsCommand('openshift.component.debug', true) @selectTargetComponent( - 'Select a Project', 'Select an Application', 'Select a Component you want to debug (showing only Components pushed to the cluster)', (value: OpenShiftObject) => value.contextValue === ContextType.COMPONENT_PUSHED diff --git a/src/openshift/openshiftItem.ts b/src/openshift/openshiftItem.ts index ca5d957b8..53c512e94 100644 --- a/src/openshift/openshiftItem.ts +++ b/src/openshift/openshiftItem.ts @@ -5,8 +5,9 @@ import { window, QuickPickItem } from 'vscode'; import * as validator from 'validator'; -import { Odo, OdoImpl, OpenShiftObject, ContextType, OpenShiftApplication } from '../odo'; +import { Odo, OdoImpl, OpenShiftObject, ContextType, OpenShiftApplication, OpenShiftProject } from '../odo'; import { OpenShiftExplorer } from '../explorer'; +import { VsCommandError } from '../vscommand'; const errorMessage = { Project: 'You need at least one Project available. Please create new OpenShift Project and try again.', @@ -125,10 +126,15 @@ export default class OpenShiftItem { return urlList; } - static async getOpenShiftCmdData(treeItem: OpenShiftObject, projectPlaceholder: string, appPlaceholder?: string, compPlaceholder?: string, condition?: (value: OpenShiftObject) => boolean): Promise { + static async getOpenShiftCmdData(treeItem: OpenShiftObject, appPlaceholder?: string, compPlaceholder?: string, condition?: (value: OpenShiftObject) => boolean): Promise { let context: OpenShiftObject | QuickPickCommand = treeItem; let project: OpenShiftObject; - if (!context) context = await window.showQuickPick(OpenShiftItem.getProjectNames(), {placeHolder: projectPlaceholder, ignoreFocusOut: true}); + if (!context) { + context = (await this.odo.getProjects()).find((prj:OpenShiftProject)=>prj.active); + if (!context) { + throw new VsCommandError(errorMessage.Project); + } + } if (context && context.contextValue === ContextType.PROJECT && appPlaceholder ) { project = context; context = await window.showQuickPick(OpenShiftItem.getApplicationNames(project, appPlaceholder.includes('create') && compPlaceholder === undefined), {placeHolder: appPlaceholder, ignoreFocusOut: true}); @@ -165,10 +171,10 @@ function selectTargetDecoratorFactory(decorator: (...args:any[]) => Promise boolean) { - return selectTargetDecoratorFactory(async (context) => OpenShiftItem.getOpenShiftCmdData(context, prjPlaceHolder, appPlaceHolder, cmpPlaceHolder, condition)); +export function selectTargetComponent(appPlaceHolder, cmpPlaceHolder, condition?: (value: OpenShiftObject) => boolean) { + return selectTargetDecoratorFactory(async (context) => OpenShiftItem.getOpenShiftCmdData(context, appPlaceHolder, cmpPlaceHolder, condition)); } -export function selectTargetApplication(prjPlaceHolder, appPlaceHolder) { - return selectTargetDecoratorFactory(async (context) => OpenShiftItem.getOpenShiftCmdData(context, prjPlaceHolder, appPlaceHolder)); +export function selectTargetApplication(appPlaceHolder) { + return selectTargetDecoratorFactory(async (context) => OpenShiftItem.getOpenShiftCmdData(context, appPlaceHolder)); } diff --git a/src/openshift/project.ts b/src/openshift/project.ts index 96654cb2b..c97c65f94 100644 --- a/src/openshift/project.ts +++ b/src/openshift/project.ts @@ -37,9 +37,7 @@ export class Project extends OpenShiftItem { @vsCommand('openshift.project.delete', true) static async del(context: OpenShiftObject): Promise { let result: Promise = null; - const project = await Project.getOpenShiftCmdData(context, - "Select Project to delete" - ); + const project = await Project.getOpenShiftCmdData(context); if (project) { const value = await window.showWarningMessage(`Do you want to delete Project '${project.getName()}'?`, 'Yes', 'Cancel'); if (value === 'Yes') { diff --git a/src/openshift/service.ts b/src/openshift/service.ts index 153aa3d5a..6fda38a91 100644 --- a/src/openshift/service.ts +++ b/src/openshift/service.ts @@ -16,7 +16,6 @@ export class Service extends OpenShiftItem { @vsCommand('openshift.service.create') static async create(context: OpenShiftObject): Promise { const application = await Service.getOpenShiftCmdData(context, - "In which Project you want to create a Service", "In which Application you want to create a Service" ); if (!application) return null; @@ -52,7 +51,6 @@ export class Service extends OpenShiftItem { if (!service) { const application: OpenShiftObject = await Service.getOpenShiftCmdData(service, - "From which Project you want to delete Service", "From which Application you want to delete Service" ); if (application) { @@ -77,7 +75,6 @@ export class Service extends OpenShiftItem { if (!service) { const application: OpenShiftObject = await Service.getOpenShiftCmdData(context, - "From which project you want to describe Service", "From which application you want to describe Service"); if (application) { service = await window.showQuickPick(Service.getServiceNames(application), {placeHolder: "Select Service you want to describe", diff --git a/src/openshift/storage.ts b/src/openshift/storage.ts index 935b99aa2..4f685e057 100644 --- a/src/openshift/storage.ts +++ b/src/openshift/storage.ts @@ -15,7 +15,6 @@ export class Storage extends OpenShiftItem { @vsCommand('openshift.storage.create') static async create(context: OpenShiftObject): Promise { const component = await Storage.getOpenShiftCmdData(context, - "In which Project you want to create a Storage", "In which Application you want to create a Storage", "In which Component you want to create a Storage", (value: OpenShiftObject) => value.contextValue === ContextType.COMPONENT_PUSHED || value.contextValue === ContextType.COMPONENT); @@ -46,7 +45,6 @@ export class Storage extends OpenShiftItem { static async del(treeItem: OpenShiftObject): Promise { let storage = treeItem; const component = await Storage.getOpenShiftCmdData(storage, - "From which Project you want to delete Storage", "From which Application you want to delete Storage", "From which Component you want to delete Storage"); if (!storage && component) storage = await window.showQuickPick(Storage.getStorageNames(component), {placeHolder: "Select Storage to delete", ignoreFocusOut: true}); diff --git a/src/openshift/url.ts b/src/openshift/url.ts index 41e46cea2..052771be2 100644 --- a/src/openshift/url.ts +++ b/src/openshift/url.ts @@ -16,7 +16,6 @@ export class Url extends OpenShiftItem{ @vsCommand('openshift.url.create') static async create(context: OpenShiftObject): Promise { const component = await Url.getOpenShiftCmdData(context, - 'Select a Project to create a URL', 'Select an Application to create a URL', 'Select a Component you want to create a URL for'); if (component) { @@ -53,7 +52,6 @@ export class Url extends OpenShiftItem{ static async del(treeItem: OpenShiftObject): Promise { let url = treeItem; const component = await Url.getOpenShiftCmdData(url, - "From which Project you want to delete URL", "From which Application you want to delete URL", "From which Component you want to delete URL"); if (!url && component) { @@ -95,7 +93,6 @@ export class Url extends OpenShiftItem{ static async describe(treeItem: OpenShiftObject): Promise { let url = treeItem; const component = await Url.getOpenShiftCmdData(url, - "From which Project you want to describe URL", "From which Application you want to describe URL", "From which Component you want to describe URL"); if (!url && component) { diff --git a/test/unit/index.ts b/test/unit/index.ts index f6106c3be..dd7d63e82 100644 --- a/test/unit/index.ts +++ b/test/unit/index.ts @@ -17,7 +17,7 @@ const config: any = { ui: 'tdd', timeout: 60000, color: true, - // grep: 'removes watch process from Watch Sessions view when process exits' + // grep: 'calls the appropriate error message if no project found' }; if (process.env.BUILD_ID && process.env.BUILD_NUMBER) { diff --git a/test/unit/oc.test.ts b/test/unit/oc.test.ts index 52fa84d6d..71251fae7 100644 --- a/test/unit/oc.test.ts +++ b/test/unit/oc.test.ts @@ -8,11 +8,10 @@ import * as chai from 'chai'; import * as sinonChai from 'sinon-chai'; import * as sinon from 'sinon'; import { Oc } from '../../src/oc'; -import { ContextType } from '../../src/odo'; +import { ContextType, OdoImpl } from '../../src/odo'; import { ToolsConfig } from '../../src/tools'; import { TestItem } from './openshift/testOSItem'; import { CliChannel } from '../../src/cli'; -import OpenShiftItem from '../../src/openshift/openshiftItem'; const {expect} = chai; chai.use(sinonChai); @@ -48,7 +47,7 @@ suite('Oc', () => { execStub = sandbox.stub(CliChannel.prototype, 'execute'); quickPickStub = sandbox.stub(window, 'showQuickPick'); detectOrDownloadStub = sandbox.stub(ToolsConfig, 'detect').resolves('path'); - sandbox.stub(OpenShiftItem, 'getProjectNames').resolves(projectItem); + sandbox.stub(OdoImpl.prototype, 'getProjects').resolves([projectItem]); }); teardown(() => { diff --git a/test/unit/openshift/application.test.ts b/test/unit/openshift/application.test.ts index 8e277368b..ad92988d9 100644 --- a/test/unit/openshift/application.test.ts +++ b/test/unit/openshift/application.test.ts @@ -72,19 +72,18 @@ suite('OpenShift/Application', () => { }); test('asks to select a project and an application', async () => { - const projects = Promise.resolve([projectItem]); + sandbox.stub(OdoImpl.prototype, 'getProjects').resolves([projectItem]); const apps = Promise.resolve([appItem]); quickPickStub = sandbox.stub(vscode.window, 'showQuickPick'); - quickPickStub.onFirstCall().resolves(projectItem); - quickPickStub.onSecondCall().resolves(appItem); + quickPickStub.onFirstCall().resolves(appItem); await Application.describe(null); - expect(quickPickStub).calledWith(projects, { placeHolder: "From which project you want to describe Application", ignoreFocusOut: true }); expect(quickPickStub).calledWith(apps, { placeHolder: "Select Application you want to describe", ignoreFocusOut: true }); }); test('skips odo command execution if canceled by user', async () => { + sandbox.stub(OdoImpl.prototype, 'getProjects').resolves([projectItem]); quickPickStub = sandbox.stub(vscode.window, 'showQuickPick').resolves(null); await Application.describe(null); expect(termStub).not.called; @@ -97,6 +96,7 @@ suite('OpenShift/Application', () => { setup(() => { warnStub = sandbox.stub(vscode.window, 'showWarningMessage'); + sandbox.stub(OdoImpl.prototype, 'getProjects').resolves([projectItem]); sandbox.stub(OdoImpl.prototype, 'getComponents').resolves([compItem]); }); @@ -139,7 +139,6 @@ suite('OpenShift/Application', () => { test('requests for a project name and exits if not provided', async () => { const stub = sandbox.stub(vscode.window, 'showQuickPick'); stub.onFirstCall().resolves(); - warnStub.resolves('Yes'); await Application.del(undefined); expect(stub).calledOnce; expect(warnStub).is.not.called; @@ -147,12 +146,9 @@ suite('OpenShift/Application', () => { test('requests for a project and an application and exits if application is not provided', async () => { const stub = sandbox.stub(vscode.window, 'showQuickPick'); - stub.onFirstCall().resolves(projectItem); - stub.onSecondCall().resolves(); - warnStub.resolves('Yes'); - + stub.onFirstCall().resolves(); await Application.del(undefined); - expect(stub).calledTwice; + expect(stub).calledOnce; expect(warnStub).is.not.called; }); }); diff --git a/test/unit/openshift/component.test.ts b/test/unit/openshift/component.test.ts index f9c59c47d..c7173cfb8 100644 --- a/test/unit/openshift/component.test.ts +++ b/test/unit/openshift/component.test.ts @@ -40,7 +40,6 @@ suite('OpenShift/Component', () => { const componentItem = new TestItem(appItem, 'comp1', ContextType.COMPONENT_PUSHED, [], comp1Uri, 'https://host/proj/app/comp1'); const serviceItem = new TestItem(appItem, 'service', ContextType.SERVICE); const errorMessage = 'FATAL ERROR'; - let getProjects: sinon.SinonStub; let getApps: sinon.SinonStub; let Component: any; let fetchTag: sinon.SinonStub; @@ -56,11 +55,11 @@ suite('OpenShift/Component', () => { execStub = sandbox.stub(OdoImpl.prototype, 'execute').resolves({ stdout: "" }); spawnStub = sandbox.stub(OdoImpl.prototype, 'spawn'); sandbox.stub(OdoImpl.prototype, 'getServices'); - sandbox.stub(OdoImpl.prototype, 'getProjects').resolves([]); + sandbox.stub(OdoImpl.prototype, 'getProjects').resolves([projectItem]); sandbox.stub(OdoImpl.prototype, 'getApplications').resolves([]); getComponentsStub = sandbox.stub(OdoImpl.prototype, 'getComponents').resolves([]); sandbox.stub(Util, 'wait').resolves(); - getProjects = sandbox.stub(OpenShiftItem, 'getProjectNames').resolves([projectItem]); + sandbox.stub(OpenShiftItem, 'getProjectNames').resolves([projectItem]); getApps = sandbox.stub(OpenShiftItem, 'getApplicationNames').resolves([appItem]); sandbox.stub(OpenShiftItem, 'getComponentNames').resolves([componentItem]); sandbox.stub(OpenShiftItem, 'getServiceNames').resolves([serviceItem]); @@ -76,14 +75,12 @@ suite('OpenShift/Component', () => { setup(() => { quickPickStub = sandbox.stub(vscode.window, 'showQuickPick'); - quickPickStub.onFirstCall().resolves(projectItem); - quickPickStub.onSecondCall().resolves(undefined); + quickPickStub.onFirstCall().resolves(undefined); }); test('asks for context and exits if not provided', async () => { const result = await Component.create(null); expect(result).null; - expect(getProjects).calledOnce; expect(getApps).calledOnce; }); }); @@ -402,8 +399,7 @@ suite('OpenShift/Component', () => { setup(() => { quickPickStub = sandbox.stub(vscode.window, 'showQuickPick'); - quickPickStub.onFirstCall().resolves(projectItem); - quickPickStub.onSecondCall().resolves(appItem); + quickPickStub.onFirstCall().resolves(appItem); inputStub = sandbox.stub(vscode.window, 'showInputBox'); }); @@ -686,9 +682,8 @@ suite('OpenShift/Component', () => { setup(() => { sandbox.stub(Component, 'unlinkAllComponents'); quickPickStub = sandbox.stub(vscode.window, 'showQuickPick'); - quickPickStub.onFirstCall().resolves(projectItem); - quickPickStub.onSecondCall().resolves(appItem); - quickPickStub.onThirdCall().resolves(componentItem); + quickPickStub.onFirstCall().resolves(appItem); + quickPickStub.onSecondCall().resolves(componentItem); sandbox.stub(vscode.window, 'showWarningMessage').resolves('Yes'); execStub.resolves({ error: undefined, stdout: '', stderr: '' }); sandbox.stub(vscode.workspace, 'workspaceFolders').value([wsFolder1, wsFolder2]); @@ -722,22 +717,15 @@ suite('OpenShift/Component', () => { } }); - test('returns null when no project is selected', async () => { - quickPickStub.onFirstCall().resolves(); - const result = await Component.del(null); - - expect(result).null; - }); - test('returns null when no application is selected', async () => { - quickPickStub.onSecondCall().resolves(); + quickPickStub.onFirstCall().resolves(); const result = await Component.del(null); expect(result).null; }); test('returns null when no component is selected', async () => { - quickPickStub.onThirdCall().resolves(); + quickPickStub.onSecondCall().resolves(); const result = await Component.del(null); expect(result).null; @@ -748,9 +736,8 @@ suite('OpenShift/Component', () => { setup(() => { sandbox.stub(Component, 'unlinkAllComponents'); quickPickStub = sandbox.stub(vscode.window, 'showQuickPick'); - quickPickStub.onFirstCall().resolves(projectItem); - quickPickStub.onSecondCall().resolves(appItem); - quickPickStub.onThirdCall().resolves(componentItem); + quickPickStub.onFirstCall().resolves(appItem); + quickPickStub.onSecondCall().resolves(componentItem); sandbox.stub(vscode.window, 'showWarningMessage').resolves('Yes'); execStub.resolves({ error: undefined, stdout: '', stderr: '' }); sandbox.stub(vscode.workspace, 'workspaceFolders').value([wsFolder1, wsFolder2]); @@ -782,22 +769,16 @@ suite('OpenShift/Component', () => { } }); - test('returns null when no project is selected', async () => { - quickPickStub.onFirstCall().resolves(); - const result = await Component.undeploy(null); - - expect(result).null; - }); test('returns null when no application is selected', async () => { - quickPickStub.onSecondCall().resolves(); + quickPickStub.onFirstCall().resolves(); const result = await Component.undeploy(null); expect(result).null; }); test('returns null when no component is selected', async () => { - quickPickStub.onThirdCall().resolves(); + quickPickStub.onSecondCall().resolves(); const result = await Component.undeploy(null); expect(result).null; @@ -879,15 +860,14 @@ suite('OpenShift/Component', () => { suite('linkComponent with no context', () => { setup(() => { quickPickStub = sandbox.stub(vscode.window, 'showQuickPick'); - quickPickStub.onFirstCall().resolves(projectItem); - quickPickStub.onSecondCall().resolves(appItem); - quickPickStub.onThirdCall().resolves(undefined); + quickPickStub.onFirstCall().resolves(appItem); + quickPickStub.onSecondCall().resolves(undefined); }); test('asks for context and exits if not provided', async () => { const result = await Component.linkComponent(null); expect(result).null; - expect(quickPickStub).calledThrice; + expect(quickPickStub).calledTwice; }); }); @@ -937,9 +917,8 @@ suite('OpenShift/Component', () => { setup(() => { quickPickStub = sandbox.stub(vscode.window, 'showQuickPick'); - quickPickStub.onFirstCall().resolves(projectItem); - quickPickStub.onSecondCall().resolves(appItem); - quickPickStub.onThirdCall().resolves(componentItem); + quickPickStub.onFirstCall().resolves(appItem); + quickPickStub.onSecondCall().resolves(componentItem); }); test('works from context menu', async () => { @@ -974,9 +953,8 @@ suite('OpenShift/Component', () => { suite('describe', () => { setup(() => { quickPickStub = sandbox.stub(vscode.window, 'showQuickPick'); - quickPickStub.onFirstCall().resolves(projectItem); - quickPickStub.onSecondCall().resolves(appItem); - quickPickStub.onThirdCall().resolves(componentItem); + quickPickStub.onFirstCall().resolves(appItem); + quickPickStub.onSecondCall().resolves(componentItem); }); test('returns null when cancelled', async () => { @@ -999,9 +977,8 @@ suite('OpenShift/Component', () => { suite('log', () => { setup(() => { quickPickStub = sandbox.stub(vscode.window, 'showQuickPick'); - quickPickStub.onFirstCall().resolves(projectItem); - quickPickStub.onSecondCall().resolves(appItem); - quickPickStub.onThirdCall().resolves(componentItem); + quickPickStub.onFirstCall().resolves(appItem); + quickPickStub.onSecondCall().resolves(componentItem); }); test('log calls the correct odo command', async () => { @@ -1018,9 +995,8 @@ suite('OpenShift/Component', () => { suite('followLog', () => { setup(() => { quickPickStub = sandbox.stub(vscode.window, 'showQuickPick'); - quickPickStub.onFirstCall().resolves(projectItem); - quickPickStub.onSecondCall().resolves(appItem); - quickPickStub.onThirdCall().resolves(componentItem); + quickPickStub.onFirstCall().resolves(appItem); + quickPickStub.onSecondCall().resolves(componentItem); }); test('returns null when cancelled', async () => { @@ -1046,9 +1022,8 @@ suite('OpenShift/Component', () => { setup(() => { quickPickStub = sandbox.stub(vscode.window, 'showQuickPick'); - quickPickStub.onFirstCall().resolves(projectItem); - quickPickStub.onSecondCall().resolves(appItem); - quickPickStub.onThirdCall().resolves(componentItem); + quickPickStub.onFirstCall().resolves(appItem); + quickPickStub.onSecondCall().resolves(componentItem); sandbox.stub(vscode.window, 'showWarningMessage'); getpushStub = sandbox.stub(Component, 'getPushCmd').resolves(undefined); sandbox.stub(Component, 'setPushCmd'); @@ -1085,9 +1060,8 @@ suite('OpenShift/Component', () => { setup(() => { quickPickStub = sandbox.stub(vscode.window, 'showQuickPick'); - quickPickStub.onFirstCall().resolves(projectItem); - quickPickStub.onSecondCall().resolves(appItem); - quickPickStub.onThirdCall().resolves(componentItem); + quickPickStub.onFirstCall().resolves(appItem); + quickPickStub.onSecondCall().resolves(componentItem); }); test('returns null when cancelled', async () => { @@ -1137,15 +1111,14 @@ suite('OpenShift/Component', () => { suite('openUrl', () => { setup(() => { quickPickStub = sandbox.stub(vscode.window, 'showQuickPick'); - quickPickStub.onFirstCall().resolves(projectItem); - quickPickStub.onSecondCall().resolves(appItem); - quickPickStub.onThirdCall().resolves(componentItem); + quickPickStub.onFirstCall().resolves(appItem); + quickPickStub.onSecondCall().resolves(componentItem); }); test('ask for context when called from command bar and exits with null if canceled', async () => { - quickPickStub.onThirdCall().resolves(undefined); + quickPickStub.onSecondCall().resolves(undefined); const result = await Component.openUrl(null); - expect(quickPickStub).calledThrice; + expect(quickPickStub).calledTwice; expect(result).is.null; }); @@ -1169,7 +1142,7 @@ suite('OpenShift/Component', () => { }); test('gets URLs for the component and if there is more than one asks which one to open it in browser and opens selected', async () => { - quickPickStub.onCall(3).resolves({label: 'https://url1'}); + quickPickStub.onThirdCall().resolves({label: 'https://url1'}); execStub.onCall(0).resolves({error: undefined, stdout: JSON.stringify({ items: [ { diff --git a/test/unit/openshift/project.test.ts b/test/unit/openshift/project.test.ts index 325d82db8..5705290b6 100644 --- a/test/unit/openshift/project.test.ts +++ b/test/unit/openshift/project.test.ts @@ -19,7 +19,6 @@ chai.use(sinonChai); suite('OpenShift/Project', () => { let sandbox: sinon.SinonSandbox; let execStub: sinon.SinonStub; - let getProjectsStub: sinon.SinonStub; const cluster = new TestItem(null, 'cluster', ContextType.CLUSTER); const projectItem = new TestItem(cluster, 'project', ContextType.PROJECT); @@ -29,7 +28,7 @@ suite('OpenShift/Project', () => { setup(() => { sandbox = sinon.createSandbox(); sandbox.stub(OdoImpl.prototype, 'getClusters').resolves([cluster]); - getProjectsStub = sandbox.stub(OdoImpl.prototype, 'getProjects').resolves([projectItem]); + sandbox.stub(OdoImpl.prototype, 'getProjects').resolves([projectItem]); execStub = sandbox.stub(OdoImpl.prototype, 'execute').resolves({error: undefined, stdout: '', stderr: ''}); sandbox.stub(OpenShiftItem, 'getProjectNames').resolves([projectItem]); sandbox.stub(OpenShiftItem, 'getApplicationNames').resolves([appItem]); @@ -132,12 +131,11 @@ suite('OpenShift/Project', () => { }); suite('del', () => { - let warnStub: sinon.SinonStub; let quickPickStub: sinon.SinonStub; + let warnStub: sinon.SinonStub; setup(() => { warnStub = sandbox.stub(vscode.window, 'showWarningMessage').resolves('Yes'); - quickPickStub = sandbox.stub(vscode.window, 'showQuickPick').resolves(projectItem); - getProjectsStub.resolves([]); + sandbox.stub(vscode.window, 'showQuickPick').resolves(projectItem); }); test('works with context', async () => { @@ -154,13 +152,6 @@ suite('OpenShift/Project', () => { expect(execStub.getCall(0).args[0]).equals(Command.deleteProject(projectItem.getName())); }); - test('returns null with no project selected', async () => { - quickPickStub.resolves(); - const result = await Project.del(null); - - expect(result).null; - }); - test('returns null when cancelled', async () => { warnStub.resolves('Cancel'); const result = await Project.del(null); diff --git a/test/unit/openshift/service.test.ts b/test/unit/openshift/service.test.ts index 9439a109f..ec0e0c0be 100644 --- a/test/unit/openshift/service.test.ts +++ b/test/unit/openshift/service.test.ts @@ -21,7 +21,6 @@ suite('OpenShift/Service', () => { let termStub: sinon.SinonStub; let sandbox: sinon.SinonSandbox; let quickPickStub: sinon.SinonStub; - let getProjectNamesStub: sinon.SinonStub; let getServicesStub: sinon.SinonStub; let getProjectsStub: sinon.SinonStub; let getApplicationsStub: sinon.SinonStub; @@ -40,7 +39,7 @@ suite('OpenShift/Service', () => { getServicesStub = sandbox.stub(OdoImpl.prototype, 'getServices').resolves([serviceItem]); termStub = sandbox.stub(OdoImpl.prototype, 'executeInTerminal'); quickPickStub = sandbox.stub(vscode.window, 'showQuickPick'); - getProjectNamesStub = sandbox.stub(OpenShiftItem, 'getProjectNames').resolves([projectItem]); + sandbox.stub(OpenShiftItem, 'getProjectNames').resolves([projectItem]); sandbox.stub(OpenShiftItem, 'getApplicationNames').resolves([appItem]); sandbox.stub(OpenShiftItem, 'getServiceNames').resolves([serviceItem]); execStub = sandbox.stub(OdoImpl.prototype, 'execute').resolves({ stdout: "" }); @@ -55,25 +54,23 @@ suite('OpenShift/Service', () => { let progressStub: sinon.SinonStub; setup(() => { + getProjectsStub.resolves([projectItem]); sandbox.stub(OdoImpl.prototype, 'getServiceTemplates').resolves([]); sandbox.stub(OdoImpl.prototype, 'getServiceTemplatePlans').resolves(['default', 'free', 'paid']); quickPickStub.onFirstCall().resolves(appItem); - quickPickStub.onSecondCall().resolves(appItem); - quickPickStub.onThirdCall().resolves(templatePlan); - quickPickStub.onCall(3).resolves('default'); + quickPickStub.onSecondCall().resolves(templatePlan); + quickPickStub.onThirdCall().resolves('default'); inputStub = sandbox.stub(vscode.window, 'showInputBox').resolves(serviceItem.getName()); progressStub = sandbox.stub(Progress, 'execFunctionWithProgress').resolves(); }); test('works with correct inputs', async () => { - getProjectsStub.resolves([projectItem]); getApplicationsStub.resolves([appItem]); const result = await Service.create(null); expect(result).equals(`Service '${serviceItem.getName()}' successfully created`); }); test('validation returns null for correct service name', async () => { - getProjectsStub.resolves([projectItem]); getApplicationsStub.resolves([appItem]); let result: string | Thenable; inputStub.callsFake((options?: vscode.InputBoxOptions): Thenable => { @@ -86,7 +83,6 @@ suite('OpenShift/Service', () => { }); test('validation returns message for long service name', async () => { - getProjectsStub.resolves([projectItem]); getApplicationsStub.resolves([appItem]); let result: string | Thenable; inputStub.callsFake((options?: vscode.InputBoxOptions): Thenable => { @@ -113,8 +109,6 @@ suite('OpenShift/Service', () => { }); test('calls the appropriate error message if no project found', async () => { - quickPickStub.restore(); - getProjectNamesStub.restore(); getProjectsStub.resolves([]); sandbox.stub(vscode.window, 'showErrorMessage'); try { @@ -282,12 +276,11 @@ suite('OpenShift/Service', () => { let warnStub: sinon.SinonStub; setup(() => { - getProjectsStub.resolves([]); + getProjectsStub.resolves([projectItem]); getApplicationsStub.resolves([]); getServicesStub.resolves([]); - quickPickStub.onFirstCall().resolves(projectItem); - quickPickStub.onSecondCall().resolves(appItem); - quickPickStub.onThirdCall().resolves(serviceItem); + quickPickStub.onFirstCall().resolves(appItem); + quickPickStub.onSecondCall().resolves(serviceItem); warnStub = sandbox.stub(vscode.window, 'showWarningMessage').resolves('Yes'); sandbox.stub(Progress, 'execFunctionWithProgress').yields(); }); @@ -310,14 +303,13 @@ suite('OpenShift/Service', () => { test('returns null with no application selected', async () => { quickPickStub.onFirstCall().resolves(); - quickPickStub.onSecondCall().resolves(); const result = await Service.del(null); expect(result).null; }); test('returns null with no service selected', async () => { - quickPickStub.onThirdCall().resolves(); + quickPickStub.onSecondCall().resolves(); const result = await Service.del(null); expect(result).null; @@ -342,9 +334,9 @@ suite('OpenShift/Service', () => { suite('describe', () => { setup(() => { - quickPickStub.onFirstCall().resolves(projectItem); - quickPickStub.onSecondCall().resolves(appItem); - quickPickStub.onThirdCall().resolves(serviceItem); + getProjectsStub.resolves([projectItem]); + quickPickStub.onFirstCall().resolves(appItem); + quickPickStub.onSecondCall().resolves(serviceItem); execStub.resolves({error: undefined, stdout: 'template_name', stderr: ''}); }); diff --git a/test/unit/openshift/storage.test.ts b/test/unit/openshift/storage.test.ts index d86a578da..4e90149bb 100644 --- a/test/unit/openshift/storage.test.ts +++ b/test/unit/openshift/storage.test.ts @@ -22,6 +22,7 @@ suite('OpenShift/Storage', () => { let quickPickStub: sinon.SinonStub; let inputStub: sinon.SinonStub; let getProjectNamesStub: sinon.SinonStub; + let getProjectsStub: sinon.SinonStub; let getStorageNamesStub: sinon.SinonStub; const projectItem = new TestItem(null, 'project', ContextType.PROJECT); const appItem = new TestItem(projectItem, 'app', ContextType.APPLICATION); @@ -45,9 +46,9 @@ suite('OpenShift/Storage', () => { suite('create Storage with no context', () => { setup(() => { - quickPickStub.onFirstCall().resolves(projectItem); - quickPickStub.onSecondCall().resolves(appItem); - quickPickStub.onThirdCall().resolves(componentItem); + getProjectsStub = sandbox.stub(OdoImpl.prototype, 'getProjects').resolves([projectItem]); + quickPickStub.onFirstCall().resolves(appItem); + quickPickStub.onSecondCall().resolves(componentItem); getProjectNamesStub = sandbox.stub(OpenShiftItem, 'getProjectNames').resolves([projectItem]); sandbox.stub(OpenShiftItem, 'getApplicationNames').resolves([appItem]); sandbox.stub(OpenShiftItem, 'getComponentNames').resolves([componentItem]); @@ -64,6 +65,7 @@ suite('OpenShift/Storage', () => { test('calls the appropriate error message if no project found', async () => { quickPickStub.restore(); getProjectNamesStub.restore(); + getProjectsStub.restore(); sandbox.stub(OdoImpl.prototype, 'getProjects').resolves([]); sandbox.stub(vscode.window, 'showErrorMessage'); try { @@ -76,7 +78,6 @@ suite('OpenShift/Storage', () => { }); test('calls the appropriate error message if no application found', async () => { - sandbox.stub(OdoImpl.prototype, 'getProjects').resolves([projectItem]); sandbox.stub(OdoImpl.prototype, 'getApplications').resolves([appItem]); sandbox.stub(OdoImpl.prototype, 'getComponents').resolves([]); sandbox.stub(vscode.window, 'showErrorMessage'); @@ -95,7 +96,6 @@ suite('OpenShift/Storage', () => { }); test('works with valid inputs', async () => { - sandbox.stub(OdoImpl.prototype, 'getProjects').resolves([projectItem]); sandbox.stub(OdoImpl.prototype, 'getApplications').resolves([appItem]); sandbox.stub(OdoImpl.prototype, 'getComponents').resolves([componentItem]); const result = await Storage.create(null); @@ -290,14 +290,13 @@ suite('OpenShift/Storage', () => { sandbox.stub(OpenShiftItem, 'getApplicationNames').resolves([appItem]); sandbox.stub(OpenShiftItem, 'getComponentNames').resolves([componentItem]); sandbox.stub(OpenShiftItem, 'getStorageNames').resolves([storageItem]); - sandbox.stub(OdoImpl.prototype, 'getProjects').resolves([]); + sandbox.stub(OdoImpl.prototype, 'getProjects').resolves([projectItem]); sandbox.stub(OdoImpl.prototype, 'getApplications').resolves([]); sandbox.stub(OdoImpl.prototype, 'getComponents').resolves([]); getStorageNamesStub.resolves([]); - quickPickStub.onFirstCall().resolves(projectItem); - quickPickStub.onSecondCall().resolves(appItem); - quickPickStub.onThirdCall().resolves(componentItem); - quickPickStub.onCall(3).resolves(storageItem); + quickPickStub.onFirstCall().resolves(appItem); + quickPickStub.onSecondCall().resolves(componentItem); + quickPickStub.onThirdCall().resolves(storageItem); warnStub = sandbox.stub(vscode.window, 'showWarningMessage').resolves('Yes'); }); @@ -320,7 +319,7 @@ suite('OpenShift/Storage', () => { }); test('returns null with no storage selected', async () => { - quickPickStub.onCall(3).resolves(); + quickPickStub.onCall(2).resolves(); const result = await Storage.del(null); expect(result).null; diff --git a/test/unit/openshift/testOSItem.ts b/test/unit/openshift/testOSItem.ts index da7d4ed04..679984648 100644 --- a/test/unit/openshift/testOSItem.ts +++ b/test/unit/openshift/testOSItem.ts @@ -10,7 +10,7 @@ import { BuilderImage } from "../../../src/odo/builderImage"; export class TestItem implements OpenShiftObject { public treeItem = null; - + public active = true; // eslint-disable-next-line no-useless-constructor constructor( private parent: OpenShiftObject, @@ -45,6 +45,10 @@ export class TestItem implements OpenShiftObject { return; } + addChild(item: OpenShiftObject): Promise { + return; + } + getParent(): OpenShiftObject { return this.parent; } @@ -52,5 +56,4 @@ export class TestItem implements OpenShiftObject { get label(): string { return this.name; } - ge } diff --git a/test/unit/openshift/url.test.ts b/test/unit/openshift/url.test.ts index a1e846482..e0085c94d 100644 --- a/test/unit/openshift/url.test.ts +++ b/test/unit/openshift/url.test.ts @@ -204,18 +204,19 @@ suite('OpenShift/URL', () => { }); suite('create Url with no context', () => { - + let getProjectsStub; setup(() => { const urlName = 'customName'; - quickPickStub.onFirstCall().resolves(projectItem); - quickPickStub.onSecondCall().resolves(appItem); - quickPickStub.onThirdCall().resolves(componentItem); + getProjectsStub = sandbox.stub(OdoImpl.prototype, 'getProjects').resolves([projectItem]); + quickPickStub.onFirstCall().resolves(appItem); + quickPickStub.onSecondCall().resolves(componentItem); inputStub.onFirstCall().resolves(urlName); }); test('calls the appropriate error message if no project found', async () => { quickPickStub.restore(); getProjectsNameStub.restore(); + getProjectsStub.restore(); sandbox.stub(OdoImpl.prototype, 'getProjects').resolves([]); sandbox.stub(vscode.window, 'showErrorMessage'); try { @@ -228,7 +229,6 @@ suite('OpenShift/URL', () => { }); test('asks to select port if more that one exposed and returns message', async () => { - sandbox.stub(OdoImpl.prototype, 'getProjects').resolves([projectItem]); sandbox.stub(OdoImpl.prototype, 'getApplications').resolves([appItem]); sandbox.stub(OdoImpl.prototype, 'getComponents').resolves([componentItem]); inputStub.onFirstCall().resolves('urlName'); @@ -324,14 +324,13 @@ suite('OpenShift/URL', () => { let warnStub: sinon.SinonStub; setup(() => { - sandbox.stub(OdoImpl.prototype, 'getProjects').resolves([]); + sandbox.stub(OdoImpl.prototype, 'getProjects').resolves([projectItem]); sandbox.stub(OdoImpl.prototype, 'getApplications').resolves([]); sandbox.stub(OdoImpl.prototype, 'getComponents').resolves([]); getRouteNameStub.resolves([]); - quickPickStub.onFirstCall().resolves(projectItem); - quickPickStub.onSecondCall().resolves(appItem); - quickPickStub.onThirdCall().resolves(componentItem); - quickPickStub.onCall(3).resolves(routeItem); + quickPickStub.onFirstCall().resolves(appItem); + quickPickStub.onSecondCall().resolves(componentItem); + quickPickStub.onThirdCall().resolves(routeItem); warnStub = sandbox.stub(vscode.window, 'showWarningMessage').resolves('Yes'); }); @@ -350,7 +349,7 @@ suite('OpenShift/URL', () => { }); test('returns null with no URL selected', async () => { - quickPickStub.onCall(3).resolves(); + quickPickStub.onCall(2).resolves(); const result = await Url.del(null); expect(result).null; @@ -436,14 +435,13 @@ suite('OpenShift/URL', () => { suite('describe', () => { setup(() => { - sandbox.stub(OdoImpl.prototype, 'getProjects').resolves([]); + sandbox.stub(OdoImpl.prototype, 'getProjects').resolves([projectItem]); sandbox.stub(OdoImpl.prototype, 'getApplications').resolves([]); sandbox.stub(OdoImpl.prototype, 'getComponents').resolves([]); getRouteNameStub.resolves([]); - quickPickStub.onFirstCall().resolves(projectItem); - quickPickStub.onSecondCall().resolves(appItem); - quickPickStub.onThirdCall().resolves(componentItem); - quickPickStub.onCall(3).resolves(routeItem); + quickPickStub.onFirstCall().resolves(appItem); + quickPickStub.onSecondCall().resolves(componentItem); + quickPickStub.onThirdCall().resolves(routeItem); }); test('calls the correct odo command w/ context', async () => {