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

test delete workspace command #5822

Merged
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
@@ -0,0 +1,40 @@
import assert from "assert";
import * as sinon from "sinon";
import * as vscode from 'vscode';

import { DeleteWorkspaceItemCommand } from '../../../commands/deleteWorkspaceItem/deleteWorkspaceItemCommand';
import { WorkspaceTreeItem } from '../../../providers/workspaceTreeProvider';

suite('DeleteWorkspaceItemCommand Tests', () => {
let context: vscode.ExtensionContext;
let outputChannel: vscode.LogOutputChannel;
let command: DeleteWorkspaceItemCommand;
let workspaceTreeItem: WorkspaceTreeItem;

setup(() => {
context = { extension: { packageJSON: { telemetryInstrumentationKey: 'test-key' } } } as any;
outputChannel = { appendLine: sinon.stub() } as any;
command = new DeleteWorkspaceItemCommand(context, outputChannel);
workspaceTreeItem = { label: 'test-item', category: 'plugin' } as any;
});

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

test('getName should return correct command name', () => {
assert.strictEqual("kiota.workspace.deleteItem", command.getName());
});

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 showInformationMessageStub = sinon.stub(vscode.window, 'showInformationMessage').resolves();
const executeCommandStub = sinon.stub(vscode.commands, 'executeCommand').resolves();

await command.execute(workspaceTreeItem);

assert.strictEqual(deleteItemStub.calledOnce, true);
assert.strictEqual(showInformationMessageStub.calledOnceWith('test-item removed successfully.'), true);
assert.strictEqual(executeCommandStub.calledOnceWith('kiota.workspace.refresh'), true);
});
});
Loading