From d8eb8d182b8ec3e513b00c72c99a2f0b95c78c0b Mon Sep 17 00:00:00 2001 From: Philip Carneiro Date: Mon, 29 Apr 2024 14:29:41 +0100 Subject: [PATCH] add more tests --- test/suite/services.test.ts | 52 +++++++++++++++++++++++++++---------- 1 file changed, 38 insertions(+), 14 deletions(-) diff --git a/test/suite/services.test.ts b/test/suite/services.test.ts index 6ba1f673..8d94740f 100644 --- a/test/suite/services.test.ts +++ b/test/suite/services.test.ts @@ -743,6 +743,10 @@ describe("connectionManagerService", () => { TreeItemCollapsibleState.None, ); ext.serverProvider = new KdbTreeProvider(servers, insights); + + const localConn = new LocalConnection("127.0.0.1:5001", "testLabel"); + + const insightsConn = new InsightsConnection(insightNode.label, insightNode); describe("retrieveConnection", () => { afterEach(() => { ext.connectionsList.length = 0; @@ -760,7 +764,6 @@ describe("connectionManagerService", () => { }); describe("retrieveConnectedConnection", () => { - const localConn = new LocalConnection("127.0.0.1:5001", "testLabel"); afterEach(() => { ext.connectedConnectionList.length = 0; }); @@ -821,10 +824,6 @@ describe("connectionManagerService", () => { }); describe("setActiveConnection", () => { - const localConn = new LocalConnection( - kdbNode.details.serverName + ":" + kdbNode.details.serverPort, - kdbNode.label, - ); beforeEach(() => { ext.activeConnection = undefined; }); @@ -849,10 +848,6 @@ describe("connectionManagerService", () => { }); describe("disconnect", () => { - const localConn = new LocalConnection( - kdbNode.details.serverName + ":" + kdbNode.details.serverPort, - kdbNode.label, - ); let retrieveConnectionStub, retrieveConnectedConnectionStub; beforeEach(() => { retrieveConnectionStub = sinon.stub( @@ -879,11 +874,6 @@ describe("connectionManagerService", () => { }); describe("executeQuery", () => { - const localConn = new LocalConnection( - kdbNode.details.serverName + ":" + kdbNode.details.serverPort, - kdbNode.label, - ); - const insightsConn = new InsightsConnection(insightNode.label, insightNode); const command = "testCommand"; const context = "testContext"; const stringfy = true; @@ -986,4 +976,38 @@ describe("connectionManagerService", () => { assert.equal(ext.connectionNode, undefined); }); }); + + describe("resetScratchpad", () => { + let connMngService: ConnectionManagementService; + let showErrorMessageStub: sinon.SinonStub; + let showInformationMessageStub: sinon.SinonStub; + let resetScratchpadStub: sinon.SinonStub; + + beforeEach(() => { + connMngService = new ConnectionManagementService(); + showErrorMessageStub = sinon.stub(window, "showErrorMessage"); + showInformationMessageStub = sinon.stub(window, "showInformationMessage"); + ext.activeConnection = insightsConn; + resetScratchpadStub = sinon.stub(ext.activeConnection, "resetScratchpad"); + }); + + afterEach(() => { + sinon.restore(); + }); + + it("should call resetScratchpad on activeConnection if selection is Yes and activeConnection is an instance of InsightsConnection", async () => { + showInformationMessageStub.resolves("Yes"); + await connMngService.resetScratchpad(); + sinon.assert.calledOnce(resetScratchpadStub); + sinon.assert.notCalled(showErrorMessageStub); + }); + + it("should show error message if activeConnection is not an instance of InsightsConnection", async () => { + showInformationMessageStub.resolves("Yes"); + ext.activeConnection = undefined; + await connMngService.resetScratchpad(); + sinon.assert.calledOnce(showErrorMessageStub); + sinon.assert.notCalled(resetScratchpadStub); + }); + }); });