Skip to content

Commit

Permalink
Ensure picker returns array only if multi-select is enabled (#20772)
Browse files Browse the repository at this point in the history
Fixes #20768
  • Loading branch information
karthiknadig authored Mar 1, 2023
1 parent c5e6378 commit a5005f6
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/client/common/vscodeApis/windowApis.ts
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,12 @@ export async function showQuickPickWithBack<T extends QuickPickItem>(
}),
quickPick.onDidAccept(() => {
if (!deferred.completed) {
deferred.resolve(quickPick.selectedItems.map((item) => item));
if (quickPick.canSelectMany) {
deferred.resolve(quickPick.selectedItems.map((item) => item));
} else {
deferred.resolve(quickPick.selectedItems[0]);
}

quickPick.hide();
}
}),
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

import { assert } from 'chai';
import * as sinon from 'sinon';
import { CancellationTokenSource } from 'vscode';
import * as windowApis from '../../../../client/common/vscodeApis/windowApis';
import { pickPythonVersion } from '../../../../client/pythonEnvironments/creation/provider/condaUtils';

suite('Conda Utils test', () => {
let showQuickPickWithBackStub: sinon.SinonStub;

setup(() => {
showQuickPickWithBackStub = sinon.stub(windowApis, 'showQuickPickWithBack');
});

teardown(() => {
sinon.restore();
});

test('No version selected or user pressed escape', async () => {
showQuickPickWithBackStub.resolves(undefined);

const actual = await pickPythonVersion();
assert.isUndefined(actual);
});

test('User selected a version', async () => {
showQuickPickWithBackStub.resolves({ label: 'Python', description: '3.10' });

const actual = await pickPythonVersion();
assert.equal(actual, '3.10');
});

test('With cancellation', async () => {
const source = new CancellationTokenSource();

showQuickPickWithBackStub.callsFake(() => {
source.cancel();
});

const actual = await pickPythonVersion(source.token);
assert.isUndefined(actual);
});
});

0 comments on commit a5005f6

Please sign in to comment.