Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Task: test show plugins and clients #5838

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,16 @@ export class DeleteWorkspaceItemCommand extends Command {

public async execute(workspaceTreeItem: WorkspaceTreeItem): Promise<void> {
const type = workspaceTreeItem.category && isPluginType(workspaceTreeItem.category) ? "plugin" : "client";
const yesAnswer = vscode.l10n.t("Yes");
const yesAnswer: vscode.MessageItem = { title: vscode.l10n.t("Yes") };
const noAnswer: vscode.MessageItem = { title: vscode.l10n.t("No") };

const response = await vscode.window.showWarningMessage(
vscode.l10n.t("Do you want to delete this item?"),
yesAnswer,
vscode.l10n.t("No")
noAnswer
);
if (response === yesAnswer) {

if (response?.title === yesAnswer.title) {
const result = await this.deleteItem(type, workspaceTreeItem);
if (result) {
const isSuccess = result.some(k => k.message.includes('removed successfully'));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,16 +27,18 @@ suite('DeleteWorkspaceItemCommand Tests', () => {
});

test('execute should show success message and refresh workspace on success', async () => {
const deleteItemStub = sinon.stub(command as any, 'deleteItem').resolves([{ message: 'removed successfully' }]);
const showWarningMessageStub = sinon.stub(vscode.window, 'showWarningMessage').resolves({ title: "Yes" });
const yesAnswer: vscode.MessageItem = { title: vscode.l10n.t("Yes") };

const showWarningMessageStub = sinon.stub(vscode.window, 'showWarningMessage').resolves(yesAnswer);
const showInformationMessageStub = sinon.stub(vscode.window, 'showInformationMessage').resolves();
const executeCommandStub = sinon.stub(vscode.commands, 'executeCommand').resolves();
const deleteItemStub = sinon.stub(command as any, 'deleteItem').resolves([{ message: 'removed successfully' }]);

await command.execute(workspaceTreeItem);

assert.strictEqual(showWarningMessageStub.calledOnce, true);
assert.strictEqual(showInformationMessageStub.calledOnce, true);
assert.strictEqual(executeCommandStub.calledWith('kiota.workspace.refresh'), true);
assert.strictEqual(deleteItemStub.calledOnce, true);
assert.strictEqual(showWarningMessageStub.calledOnceWith("Do you want to delete this item?", sinon.match("Yes"), sinon.match("No")), true);
assert.strictEqual(showInformationMessageStub.calledOnceWith('test-item removed successfully.'), true);
assert.strictEqual(executeCommandStub.calledOnceWith('kiota.workspace.refresh'), true);
});
});
Loading