Skip to content

Commit

Permalink
add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Philip-Carneiro committed Oct 1, 2024
1 parent 7a09ec9 commit cd9ad5c
Show file tree
Hide file tree
Showing 2 changed files with 89 additions and 1 deletion.
1 change: 0 additions & 1 deletion test/suite/commands.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import assert from "assert";
import mock from "mock-fs";
import * as sinon from "sinon";
import * as vscode from "vscode";
import * as fs from "fs";
import * as dataSourceCommand from "../../src/commands/dataSourceCommand";
import * as installTools from "../../src/commands/installTools";
import * as serverCommand from "../../src/commands/serverCommand";
Expand Down
89 changes: 89 additions & 0 deletions test/suite/panels.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import { createDefaultDataSourceFile } from "../../src/models/dataSource";
import { DataSourcesPanel } from "../../src/panels/datasource";
import { KdbResultsViewProvider } from "../../src/services/resultsPanelProvider";
import * as utils from "../../src/utils/execution";
import * as coreUtils from "../../src/utils/core";
import { InsightsNode, KdbNode } from "../../src/services/kdbTreeProvider";
import { TreeItemCollapsibleState } from "vscode";
import { NewConnectionPannel } from "../../src/panels/newConnection";
Expand Down Expand Up @@ -383,6 +384,94 @@ describe("WebPanels", () => {
});
});

describe("updateWebView", () => {
const uriTest: vscode.Uri = vscode.Uri.parse("test");

let resultsPanel: KdbResultsViewProvider;
let postMessageStub: sinon.SinonStub;
let kdbOutputLogStub: sinon.SinonStub;
let convertToGridStub: sinon.SinonStub;

beforeEach(() => {
resultsPanel = new KdbResultsViewProvider(uriTest);
resultsPanel["_view"] = {
webview: {
postMessage: sinon.stub(),
},
} as any;
postMessageStub = resultsPanel["_view"].webview
.postMessage as sinon.SinonStub;
kdbOutputLogStub = sinon.stub(coreUtils, "kdbOutputLog");
convertToGridStub = sinon.stub(resultsPanel, "convertToGrid");
});

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

it("should log an error if there is no view to update", () => {
resultsPanel["_view"] = undefined;
resultsPanel.updateWebView("test");
sinon.assert.calledWith(
kdbOutputLogStub,
"[Results Tab] No view to update",
"ERROR",
);
});

it("should handle string queryResult", () => {
const queryResult = "test string";
resultsPanel.updateWebView(queryResult);
sinon.assert.calledWith(postMessageStub, {
command: "setResultsContent",
results: `<p class="results-txt">test string</p>`,
});
});

it("should handle number queryResult", () => {
const queryResult = 123;
resultsPanel.updateWebView(queryResult);
sinon.assert.calledWith(postMessageStub, {
command: "setResultsContent",
results: `<p class="results-txt">123</p>`,
});
});

it("should handle empty string queryResult", () => {
const queryResult = "";
resultsPanel.updateWebView(queryResult);
sinon.assert.calledWith(postMessageStub, {
command: "setResultsContent",
results: "<p>No results to show</p>",
});
});

it("should handle object queryResult and call convertToGrid", () => {
const queryResult = { data: "test" };
const gridOptions = { columnDefs: [], rowData: [] };
convertToGridStub.returns(gridOptions);
resultsPanel.updateWebView(queryResult);
sinon.assert.calledWith(
convertToGridStub,
queryResult,
resultsPanel.isInsights,
);
sinon.assert.calledWith(postMessageStub, {
command: "setGridOptions",
gridOptions: gridOptions,
});
});

it("should handle null queryResult", () => {
const queryResult = null;
resultsPanel.updateWebView(queryResult);
sinon.assert.calledWith(postMessageStub, {
command: "setResultsContent",
results: "",
});
});
});

describe("_getWebviewContent", () => {
const uriTest: vscode.Uri = vscode.Uri.parse("test");

Expand Down

0 comments on commit cd9ad5c

Please sign in to comment.