Skip to content

Commit

Permalink
add more tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Philip-Carneiro-KX committed Apr 29, 2024
1 parent 4ff40da commit d8eb8d1
Showing 1 changed file with 38 additions and 14 deletions.
52 changes: 38 additions & 14 deletions test/suite/services.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -760,7 +764,6 @@ describe("connectionManagerService", () => {
});

describe("retrieveConnectedConnection", () => {
const localConn = new LocalConnection("127.0.0.1:5001", "testLabel");
afterEach(() => {
ext.connectedConnectionList.length = 0;
});
Expand Down Expand Up @@ -821,10 +824,6 @@ describe("connectionManagerService", () => {
});

describe("setActiveConnection", () => {
const localConn = new LocalConnection(
kdbNode.details.serverName + ":" + kdbNode.details.serverPort,
kdbNode.label,
);
beforeEach(() => {
ext.activeConnection = undefined;
});
Expand All @@ -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(
Expand All @@ -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;
Expand Down Expand Up @@ -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);
});
});
});

0 comments on commit d8eb8d1

Please sign in to comment.