Skip to content

Commit fda7d5a

Browse files
committed
New Component called from App Explorer creates local component
This PR fixes #2027. To create GIT and Binary components use command from palette. Signed-off-by: Denis Golovin dgolovin@redhat.com
1 parent 9c243f2 commit fda7d5a

File tree

2 files changed

+40
-57
lines changed

2 files changed

+40
-57
lines changed

src/openshift/component.ts

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -111,21 +111,7 @@ export class Component extends OpenShiftItem {
111111
static async create(application: OpenShiftApplication): Promise<string> {
112112
if (!application) return null;
113113

114-
const componentSource = await window.showQuickPick(SourceTypeChoice.asArray(), {
115-
placeHolder: 'Select source type for Component',
116-
ignoreFocusOut: true
117-
});
118-
if (!componentSource) return null;
119-
120-
let command: Promise<string>;
121-
if (componentSource.label === SourceTypeChoice.GIT.label) {
122-
command = Component.createFromGit(application);
123-
} else if (componentSource.label === SourceTypeChoice.BINARY.label) {
124-
command = Component.createFromBinary(application);
125-
} else if (componentSource.label === SourceTypeChoice.LOCAL.label) {
126-
command = Component.createFromLocal(application);
127-
}
128-
return command.catch((err) => Promise.reject(new VsCommandError(`Failed to create Component with error '${err}'`, 'Failed to create Component with error')));
114+
return Component.createFromLocal(application).catch((err) => Promise.reject(new VsCommandError(`Failed to create Component with error '${err}'`, 'Failed to create Component with error')));
129115
}
130116

131117
@vsCommand('openshift.component.delete', true)

test/unit/openshift/component.test.ts

Lines changed: 39 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -111,9 +111,8 @@ suite('OpenShift/Component', () => {
111111

112112
setup(() => {
113113
quickPickStub = sandbox.stub(vscode.window, 'showQuickPick');
114-
quickPickStub.onFirstCall().resolves(SourceTypeChoice.LOCAL);
115-
quickPickStub.onSecondCall().resolves({label: 'file:///c:/Temp', folder: vscode.Uri.parse('file:///c:/Temp')});
116-
quickPickStub.onThirdCall().resolves(componentType);
114+
quickPickStub.onFirstCall().resolves({label: 'file:///c:/Temp', folder: vscode.Uri.parse('file:///c:/Temp')});
115+
quickPickStub.onSecondCall().resolves(componentType);
117116
inputStub = sandbox.stub(vscode.window, 'showInputBox');
118117
progressFunctionStub = sandbox.stub(Progress, 'execFunctionWithProgress').yields();
119118
sandbox.stub(vscode.workspace, 'workspaceFolders').value([wsFolder1, wsFolder2]);
@@ -127,7 +126,7 @@ suite('OpenShift/Component', () => {
127126
});
128127

129128
test('errors when a subcommand fails', async () => {
130-
quickPickStub.onSecondCall().rejects(errorMessage);
129+
quickPickStub.onFirstCall().rejects(errorMessage);
131130
let expectedError: Error;
132131
try {
133132
await Component.create(appItem);
@@ -141,7 +140,7 @@ suite('OpenShift/Component', () => {
141140

142141
setup(() => {
143142
inputStub.resolves(componentItem.getName());
144-
quickPickStub.onSecondCall().resolves({label: folder.uri.fsPath, uri: folder.uri});
143+
quickPickStub.onFirstCall().resolves({label: folder.uri.fsPath, uri: folder.uri});
145144
});
146145

147146
test('happy path works', async () => {
@@ -160,22 +159,22 @@ suite('OpenShift/Component', () => {
160159
});
161160

162161
test('returns null when no folder selected', async () => {
163-
quickPickStub.onSecondCall().resolves(undefined);
162+
quickPickStub.onFirstCall().resolves(undefined);
164163
const result = await Component.create(appItem);
165164

166165
expect(result).null;
167166
});
168167

169168
test('returns null when no new context folder selected', async () => {
170-
quickPickStub.onSecondCall().resolves(AddWorkspaceFolder);
169+
quickPickStub.onFirstCall().resolves(AddWorkspaceFolder);
171170
sandbox.stub(vscode.window, 'showOpenDialog').resolves(null);
172171
const result = await Component.create(appItem);
173172

174173
expect(result).null;
175174
});
176175

177176
test('returns null when no new context folder selected', async () => {
178-
quickPickStub.onSecondCall().resolves(AddWorkspaceFolder);
177+
quickPickStub.onFirstCall().resolves(AddWorkspaceFolder);
179178
sandbox.stub(vscode.window, 'showOpenDialog').resolves(null);
180179
const result = await Component.create(appItem);
181180

@@ -185,9 +184,8 @@ suite('OpenShift/Component', () => {
185184
test('ask again to select new context folder if selected one has odo component in it', async () => {
186185
quickPickStub.restore();
187186
quickPickStub = sandbox.stub(vscode.window, 'showQuickPick');
188-
quickPickStub.onFirstCall().resolves(SourceTypeChoice.LOCAL);
189-
quickPickStub.onSecondCall().resolves(AddWorkspaceFolder);
190-
quickPickStub.onThirdCall().resolves(AddWorkspaceFolder)
187+
quickPickStub.onFirstCall().resolves(AddWorkspaceFolder);
188+
quickPickStub.onSecondCall().resolves(AddWorkspaceFolder)
191189
const sod = sandbox.stub(vscode.window, 'showOpenDialog');
192190
sod.onFirstCall().resolves([vscode.Uri.parse('file:///c%3A/Temp')]);
193191
sandbox.stub(fs,'existsSync').returns(true);
@@ -207,7 +205,7 @@ suite('OpenShift/Component', () => {
207205
});
208206

209207
test('returns null when no component type selected', async () => {
210-
quickPickStub.onThirdCall().resolves(undefined);
208+
quickPickStub.onSecondCall().resolves(undefined);
211209
const result = await Component.create(appItem);
212210

213211
expect(result).null;
@@ -218,12 +216,11 @@ suite('OpenShift/Component', () => {
218216
const uri = 'git uri';
219217
setup(() => {
220218
sandbox.stub(OdoImpl.prototype, 'getComponentTypes').resolves(['nodejs']);
221-
quickPickStub.onFirstCall().resolves(SourceTypeChoice.GIT);
222-
quickPickStub.onSecondCall().resolves(AddWorkspaceFolder);
219+
quickPickStub.onFirstCall().resolves(AddWorkspaceFolder);
223220
inputStub.onFirstCall().resolves(uri);
224-
quickPickStub.onThirdCall().resolves('master');
225-
quickPickStub.onCall(3).resolves(componentType);
226-
quickPickStub.onCall(4).resolves(version);
221+
quickPickStub.onSecondCall().resolves('master');
222+
quickPickStub.onThirdCall().resolves(componentType);
223+
quickPickStub.onCall(3).resolves(version);
227224
inputStub.onSecondCall().resolves(componentItem.getName());
228225
sandbox.stub(vscode.window, 'showInformationMessage').resolves();
229226
sandbox.stub(vscode.window, 'showOpenDialog').resolves([vscode.Uri.parse('file:///c%3A/Temp')]);
@@ -242,36 +239,36 @@ suite('OpenShift/Component', () => {
242239
});
243240

244241
test('happy path works', async () => {
245-
const result = await Component.create(appItem);
242+
const result = await Component.createFromGit(appItem);
246243

247244
expect(result).equals(`Component '${componentItem.getName()}' successfully created. To deploy it on cluster, perform 'Push' action.`);
248245
expect(execStub).calledWith(Command.createGitComponent(projectItem.getName(), appItem.getName(), componentType.name, version, componentItem.getName(), uri, ref));
249246
});
250247

251248
test('returns null when no git repo selected', async () => {
252249
inputStub.onFirstCall().resolves();
253-
const result = await Component.create(appItem);
250+
const result = await Component.createFromGit(appItem);
254251

255252
expect(result).null;
256253
});
257254

258255
test('returns null when no component name selected', async () => {
259-
inputStub.onSecondCall().resolves();
260-
const result = await Component.create(appItem);
256+
inputStub.onFirstCall().resolves();
257+
const result = await Component.createFromGit(appItem);
261258

262259
expect(result).null;
263260
});
264261

265262
test('returns null when no git reference selected', async () => {
266-
quickPickStub.onThirdCall().resolves();
267-
const result = await Component.create(appItem);
263+
quickPickStub.onSecondCall().resolves();
264+
const result = await Component.createFromGit(appItem);
268265

269266
expect(result).null;
270267
});
271268

272269
test('returns null when no component type selected', async () => {
273-
quickPickStub.onCall(3).resolves();
274-
const result = await Component.create(appItem);
270+
quickPickStub.onCall(2).resolves();
271+
const result = await Component.createFromGit(appItem);
275272

276273
expect(result).null;
277274
});
@@ -283,7 +280,7 @@ suite('OpenShift/Component', () => {
283280
return Promise.resolve('https://github.com/redhat-developer/vscode-openshift-tools');
284281
});
285282

286-
await Component.create(appItem);
283+
await Component.createFromGit(appItem);
287284
expect(result).to.be.undefined;
288285
});
289286

@@ -295,7 +292,7 @@ suite('OpenShift/Component', () => {
295292
return Promise.resolve('https://github.com');
296293
});
297294

298-
await Component.create(appItem);
295+
await Component.createFromGit(appItem);
299296
expect(result).equals('There is no git repository at provided URL.');
300297
});
301298

@@ -306,7 +303,7 @@ suite('OpenShift/Component', () => {
306303
return Promise.resolve('github');
307304
});
308305

309-
await Component.create(appItem);
306+
await Component.createFromGit(appItem);
310307
expect(result).equals('Invalid URL provided');
311308
});
312309

@@ -317,7 +314,7 @@ suite('OpenShift/Component', () => {
317314
return Promise.resolve('');
318315
});
319316

320-
await Component.create(appItem);
317+
await Component.createFromGit(appItem);
321318
expect(result).equals('Empty Git repository URL');
322319
});
323320
});
@@ -346,47 +343,47 @@ suite('OpenShift/Component', () => {
346343
}];
347344

348345
setup(() => {
349-
quickPickStub.onFirstCall().resolves(SourceTypeChoice.BINARY);
350-
quickPickStub.onSecondCall().resolves(AddWorkspaceFolder);
351-
quickPickStub.onThirdCall().resolves({
346+
quickPickStub.onFirstCall().resolves(AddWorkspaceFolder);
347+
quickPickStub.onSecondCall().resolves({
352348
description: paths,
353349
label: '$(file-zip) sb.jar'
354350
});
355-
quickPickStub.onCall(3).resolves(componentType);
356-
quickPickStub.onCall(4).resolves(version);
351+
quickPickStub.onThirdCall().resolves(componentType);
352+
quickPickStub.onCall(3).resolves(version);
357353
sandbox.stub(vscode.window, 'showOpenDialog').resolves(files);
358354
globbyStub = sandbox.stub(globby, 'sync').returns([paths]);
359355
inputStub.resolves(componentItem.getName());
360356
});
361357

362358
test('happy path works', async () => {
363-
const result = await Component.create(appItem);
359+
const result = await Component.createFromBinary(appItem);
364360

365361
expect(result).equals(`Component '${componentItem.getName()}' successfully created. To deploy it on cluster, perform 'Push' action.`);
366362
expect(execStub).calledWith(Command.createBinaryComponent(projectItem.getName(), appItem.getName(), componentType.name, version, componentItem.getName(), paths, files[0].fsPath));
367363
});
368364

369365
test('returns null when no option is selected from quick pick', async () => {
370-
quickPickStub.onFirstCall().resolves(undefined);
366+
quickPickStub.onSecondCall().resolves(undefined);
371367
const result = await Component.createFromBinary(null);
372368
expect(result).null;
373369
});
374370

375371
test('returns information message if no binary file present in the context', async () => {
372+
quickPickStub.onFirstCall().resolves(AddWorkspaceFolder);
376373
globbyStub.onFirstCall().returns([]);
377-
const result = await Component.createFromBinary(null);
374+
const result = await Component.createFromBinary(appItem);
378375
expect(result).equals('No binary file present in the context folder selected. We currently only support .jar and .war files. If you need support for any other file, please raise an issue.');
379376
});
380377

381378
test('returns null when no work space folder selected', async () => {
382-
quickPickStub.onSecondCall().resolves(undefined);
383-
const result = await Component.create(appItem);
379+
quickPickStub.onFirstCall().resolves(undefined);
380+
const result = await Component.createFromBinary(appItem);
384381

385382
expect(result).null;
386383
});
387384

388385
test('returns null when no binary file selected', async () => {
389-
quickPickStub.onThirdCall().resolves(undefined);
386+
quickPickStub.onSecondCall().resolves(undefined);
390387
const result = await Component.create(appItem);
391388

392389
expect(result).null;
@@ -400,8 +397,8 @@ suite('OpenShift/Component', () => {
400397
});
401398

402399
test('returns null when no component type selected', async () => {
403-
quickPickStub.onCall(3).resolves();
404-
const result = await Component.create(appItem);
400+
quickPickStub.onThirdCall().resolves();
401+
const result = await Component.createFromBinary(appItem);
405402

406403
expect(result).null;
407404
});

0 commit comments

Comments
 (0)