Skip to content

Commit ca8169b

Browse files
author
Kartik Raj
committed
Events to add an environment are handled appropriately if a grouped list is present
1 parent 765bcc9 commit ca8169b

File tree

1 file changed

+52
-2
lines changed

1 file changed

+52
-2
lines changed

src/test/configuration/interpreterSelector/commands/setInterpreter.unit.test.ts

+52-2
Original file line numberDiff line numberDiff line change
@@ -455,7 +455,7 @@ suite('Set Interpreter Command', () => {
455455
verify(interpreterService.triggerRefresh()).once();
456456
});
457457

458-
test('If an event to update quickpick is received, the quickpick is updated accordingly', async () => {
458+
test('Events to update quickpick updates the quickpick accordingly', async () => {
459459
const state: InterpreterStateArgs = { path: 'some path', workspace: undefined };
460460
const multiStepInput = TypeMoq.Mock.ofType<IMultiStepInput<InterpreterStateArgs>>();
461461
let actualParameters: IQuickPickParameters<QuickPickItem> | undefined;
@@ -516,7 +516,9 @@ suite('Set Interpreter Command', () => {
516516
.setup((i) => i.getRecommendedSuggestion(TypeMoq.It.isAny(), TypeMoq.It.isAny()))
517517
.returns(() => refreshedItem);
518518
interpreterSelector
519-
.setup((i) => i.suggestionToQuickPickItem(TypeMoq.It.isAny(), undefined, false))
519+
.setup((i) =>
520+
i.suggestionToQuickPickItem(TypeMoq.It.isValue(refreshedItem.interpreter), undefined, false),
521+
)
520522
.returns(() => refreshedItem);
521523
when(interpreterService.refreshPromise).thenReturn(undefined);
522524

@@ -542,6 +544,54 @@ suite('Set Interpreter Command', () => {
542544
},
543545
'Quickpick not updated correctly after refresh has finished',
544546
);
547+
548+
const newItem = {
549+
description: `${workspacePath}/interpreterPath1`,
550+
detail: '',
551+
label: 'This is the selected Python path',
552+
path: `${workspacePath}/interpreterPath1`,
553+
interpreter: {
554+
path: `${workspacePath}/interpreterPath1`,
555+
envType: EnvironmentType.Venv,
556+
} as PythonEnvironment,
557+
};
558+
const changeEvent2: PythonEnvironmentsChangedEvent = {
559+
old: undefined,
560+
new: newItem.interpreter,
561+
};
562+
interpreterSelector.reset();
563+
interpreterSelector
564+
.setup((i) => i.getSuggestions(TypeMoq.It.isAny(), TypeMoq.It.isAny()))
565+
.returns(() => [refreshedItem, newItem]);
566+
interpreterSelector
567+
.setup((i) => i.getRecommendedSuggestion(TypeMoq.It.isAny(), TypeMoq.It.isAny()))
568+
.returns(() => refreshedItem);
569+
interpreterSelector
570+
.setup((i) =>
571+
i.suggestionToQuickPickItem(TypeMoq.It.isValue(refreshedItem.interpreter), undefined, false),
572+
)
573+
.returns(() => refreshedItem);
574+
interpreterSelector
575+
.setup((i) => i.suggestionToQuickPickItem(TypeMoq.It.isValue(newItem.interpreter), undefined, false))
576+
.returns(() => newItem);
577+
await onChangedCallback!(changeEvent2, (quickPick as unknown) as QuickPick<QuickPickItem>); // Invoke callback, meaning that the items are supposed to change.
578+
579+
assert.deepStrictEqual(
580+
quickPick,
581+
{
582+
items: [
583+
expectedEnterInterpreterPathSuggestion,
584+
defaultInterpreterPathSuggestion,
585+
separator,
586+
recommended,
587+
{ label: EnvGroups.Workspace, kind: QuickPickItemKind.Separator },
588+
newItem,
589+
],
590+
activeItems: [recommended],
591+
busy: false,
592+
},
593+
'Quickpick not updated correctly',
594+
);
545595
});
546596

547597
test('If an item is selected, update state and return', async () => {

0 commit comments

Comments
 (0)