Skip to content

Commit e40f0ac

Browse files
authored
fix: correct AbstractCommand for context menus (#231)
* fix: correct AbstractCommand for context menus * chore: condense to optional chaining operator
1 parent a2d4d77 commit e40f0ac

File tree

2 files changed

+46
-1
lines changed

2 files changed

+46
-1
lines changed

src/runtime/lib/API.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ export abstract class AbstractCommand<T> implements GenericCommand, Command {
7676
}
7777

7878
private async _invoke(commandName: string, ...args: any[]): Promise<T> {
79-
const typeArg = args.find((arg) => arg.CommandType);
79+
const typeArg = args.find((arg) => arg?.CommandType);
8080
const commandType = typeArg !== undefined ? typeArg.CommandType : ActionType.COMMAND;
8181
let output: any;
8282

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
/*---------------------------------------------------------------------------------------------
2+
* Alexa Skills Toolkit for Visual Studio Code
3+
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
4+
* SPDX-License-Identifier: Apache-2.0
5+
*--------------------------------------------------------------------------------------------*/
6+
import * as vscode from "vscode";
7+
import * as assert from "assert";
8+
import * as sinon from "sinon";
9+
10+
import {DeviceRegistryCommand} from "../../../src/askContainer/commands/deviceRegistryCommand";
11+
import {stubTelemetryClient} from "../../../test/testUtilities";
12+
13+
describe("Command askContainer.skillsConsole.deviceRegistry", () => {
14+
let command: DeviceRegistryCommand;
15+
let sandbox: sinon.SinonSandbox;
16+
17+
after(() => {
18+
command.dispose();
19+
});
20+
beforeEach(() => {
21+
sandbox = sinon.createSandbox();
22+
stubTelemetryClient(sandbox);
23+
});
24+
25+
afterEach(() => {
26+
sandbox.restore();
27+
});
28+
29+
it("Should show the view when executed", async () => {
30+
const showViewSpy = sinon.spy();
31+
command = new DeviceRegistryCommand({showView: showViewSpy} as any);
32+
33+
/*
34+
undefined argument due to
35+
36+
https://code.visualstudio.com/api/references/contribution-points#contributes.menus
37+
Note: When a command is invoked from a (context) menu, VS Code tries to infer the currently selected resource
38+
and passes that as a parameter when invoking the command.
39+
40+
*/
41+
await vscode.commands.executeCommand("askContainer.skillsConsole.deviceRegistry", undefined);
42+
43+
assert.ok(showViewSpy.called);
44+
});
45+
});

0 commit comments

Comments
 (0)