-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Frank Schmid
committed
Dec 27, 2017
1 parent
a47acc5
commit b4f10b1
Showing
1 changed file
with
72 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
import * as chai from "chai"; | ||
import * as sinon from "sinon"; | ||
import * as sinon_chai from "sinon-chai"; | ||
import { commands, ExtensionContext, Memento, window } from "vscode"; | ||
import { ICommand } from "../../src/lib/CommandBase"; | ||
import { CommandHandler } from "../../src/lib/CommandHandler"; | ||
import { NodeKind, ServerlessNode } from "../../src/lib/ServerlessNode"; | ||
|
||
// tslint:disable:max-classes-per-file | ||
// tslint:disable:no-unused-expression | ||
|
||
chai.use(sinon_chai); | ||
const expect = chai.expect; | ||
|
||
class TestContext implements ExtensionContext { | ||
public subscriptions: Array<{ dispose(): any; }> = []; | ||
public workspaceState: Memento; | ||
public globalState: Memento; | ||
public extensionPath: string = "myExtensionPath"; | ||
public asAbsolutePath: sinon.SinonStub = sinon.stub(); | ||
public storagePath: string = "myStoragePath"; | ||
} | ||
|
||
class TestCommand implements ICommand { | ||
constructor(public context: ExtensionContext) { | ||
this.invoke = sinon.stub(); | ||
} | ||
|
||
public invoke(node: ServerlessNode): Thenable<void> { | ||
throw new Error("Method not implemented."); | ||
} | ||
} | ||
|
||
describe("CommandHandler", () => { | ||
let sandbox: sinon.SinonSandbox; | ||
let windowShowInputBoxStub: sinon.SinonStub; | ||
|
||
before(() => { | ||
sandbox = sinon.createSandbox(); | ||
}); | ||
|
||
beforeEach(() => { | ||
windowShowInputBoxStub = sandbox.stub(window, "showInputBox"); | ||
}); | ||
|
||
afterEach(() => { | ||
sandbox.restore(); | ||
}); | ||
|
||
describe("registerCommand", () => { | ||
let testContext: ExtensionContext; | ||
let commandsRegisterCommandSpy: sinon.SinonSpy; | ||
|
||
beforeEach(() => { | ||
testContext = new TestContext(); | ||
commandsRegisterCommandSpy = sandbox.spy(commands, "registerCommand"); | ||
}); | ||
|
||
it("should register command and keep subscription", async () => { | ||
CommandHandler.registerCommand( | ||
TestCommand, | ||
"serverless.test", | ||
testContext, | ||
); | ||
|
||
expect(testContext.subscriptions).to.have.length(1); | ||
expect(commandsRegisterCommandSpy).to.have.been.calledOnce; | ||
const registeredCommands = await commands.getCommands(); | ||
expect(registeredCommands).to.include("serverless.test"); | ||
}); | ||
}); | ||
}); |