From db2696ba573474631e3aed8ac9ebab606ef99f1d Mon Sep 17 00:00:00 2001 From: Philip Carneiro Date: Fri, 11 Oct 2024 10:59:06 +0100 Subject: [PATCH 1/4] fix errors found in e2e tests --- src/classes/insightsConnection.ts | 50 ++++++++++--------- src/utils/connLabel.ts | 3 ++ src/utils/core.ts | 3 +- .../components/kdbNewConnectionView.ts | 2 +- test/suite/utils.test.ts | 4 ++ 5 files changed, 36 insertions(+), 26 deletions(-) diff --git a/src/classes/insightsConnection.ts b/src/classes/insightsConnection.ts index 1da63f89..6ebc287c 100644 --- a/src/classes/insightsConnection.ts +++ b/src/classes/insightsConnection.ts @@ -358,30 +358,32 @@ export class InsightsConnection { progress.report({ message: "Populating scratchpad..." }); - const scratchpadResponse = await axios.post( - scratchpadURL.toString(), - body, - headers, - ); - - kdbOutputLog( - `Executed successfully, stored in ${variableName}.`, - "INFO", - ); - kdbOutputLog( - `[SCRATCHPAD] Status: ${scratchpadResponse.status}`, - "INFO", - ); - kdbOutputLog( - `[SCRATCHPAD] Populated scratchpad with the following params: ${JSON.stringify(body.params)}`, - "INFO", - ); - window.showInformationMessage( - `Executed successfully, stored in ${variableName}.`, - ); - Telemetry.sendEvent( - "Datasource." + dsTypeString + ".Scratchpad.Populated", - ); + const scratchpadResponse = await axios + .post(scratchpadURL.toString(), body, headers) + .then((response: any) => { + if (response.data.error) { + kdbOutputLog( + `[SCRATCHPAD] Error occured while populating scratchpad: ${response.data.errorMsg}`, + "ERROR", + ); + } else { + kdbOutputLog( + `Executed successfully, stored in ${variableName}.`, + "INFO", + ); + kdbOutputLog(`[SCRATCHPAD] Status: ${response.status}`, "INFO"); + kdbOutputLog( + `[SCRATCHPAD] Populated scratchpad with the following params: ${JSON.stringify(body.params)}`, + "INFO", + ); + window.showInformationMessage( + `Executed successfully, stored in ${variableName}.`, + ); + Telemetry.sendEvent( + "Datasource." + dsTypeString + ".Scratchpad.Populated", + ); + } + }); const p = new Promise((resolve) => resolve()); return p; diff --git a/src/utils/connLabel.ts b/src/utils/connLabel.ts index f2c9f4c9..790efe03 100644 --- a/src/utils/connLabel.ts +++ b/src/utils/connLabel.ts @@ -100,6 +100,9 @@ export function removeConnFromLabels(connName: string) { ); } }); + workspace + .getConfiguration() + .update("kdb.labelsConnectionMap", ext.labelConnMapList, true); } export async function handleLabelsConnMap(labels: string[], connName: string) { diff --git a/src/utils/core.ts b/src/utils/core.ts index 31a6d94b..4fd98856 100644 --- a/src/utils/core.ts +++ b/src/utils/core.ts @@ -57,7 +57,8 @@ export async function checkOpenSslInstalled(): Promise { return semver.clean(installedVersion ? installedVersion[1] : ""); } } catch (err) { - kdbOutputLog(`Error in checking OpenSSL version: ${err}`, "ERROR"); + // Disabled the error, as it is not critical + // kdbOutputLog(`Error in checking OpenSSL version: ${err}`, "ERROR"); Telemetry.sendException(err as Error); } return null; diff --git a/src/webview/components/kdbNewConnectionView.ts b/src/webview/components/kdbNewConnectionView.ts index 2097f2fd..de8b957c 100644 --- a/src/webview/components/kdbNewConnectionView.ts +++ b/src/webview/components/kdbNewConnectionView.ts @@ -941,7 +941,7 @@ export class KdbNewConnectionView extends LitElement { }, }); setTimeout(() => { - this.labels[0] = this.newLblName; + this.labels.unshift(this.newLblName); this.closeModal(); }, 500); } diff --git a/test/suite/utils.test.ts b/test/suite/utils.test.ts index c3fa43c0..f3fd47e8 100644 --- a/test/suite/utils.test.ts +++ b/test/suite/utils.test.ts @@ -1710,6 +1710,10 @@ describe("Utils", () => { labelName: "label1", connections: ["conn1", "conn2"], }); + getConfigurationStub.returns({ + get: sinon.stub(), + update: sinon.stub(), + }); LabelsUtils.removeConnFromLabels("conn1"); From e47155d14359e9a7c10d1386becc7e4024c37e87 Mon Sep 17 00:00:00 2001 From: Philip Carneiro Date: Fri, 11 Oct 2024 11:10:09 +0100 Subject: [PATCH 2/4] add tests --- test/suite/webview.test.ts | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/test/suite/webview.test.ts b/test/suite/webview.test.ts index ac777ccf..1bed0d54 100644 --- a/test/suite/webview.test.ts +++ b/test/suite/webview.test.ts @@ -896,6 +896,40 @@ describe("KdbNewConnectionView", () => { }); }); + describe("createLabel", () => { + let clock: sinon.SinonFakeTimers; + + beforeEach(() => { + clock = sinon.useFakeTimers(); + }); + + afterEach(() => { + clock.restore(); + }); + + it("should post a message and update labels after timeout", () => { + const api = acquireVsCodeApi(); + const postMessageStub = sinon.stub(api, "postMessage"); + const closeModalStub = sinon.stub(view, "closeModal"); + + view.newLblName = "Test Label"; + view.newLblColorName = "Test Color"; + view.labels = []; + + view.createLabel(); + + sinon.assert.calledOnce(postMessageStub); + + // Avança o tempo em 500ms + clock.tick(500); + + assert.equal(view.labels[0], "Test Label"); + sinon.assert.calledOnce(closeModalStub); + + sinon.restore(); + }); + }); + describe("edit", () => { const editConn: EditConnectionMessage = { connType: 0, @@ -931,4 +965,6 @@ describe("KdbNewConnectionView", () => { sinon.restore(); }); }); + + describe("createLabel", () => {}); }); From 456f4c28265139edf52e301b76e31abfa805cf5b Mon Sep 17 00:00:00 2001 From: Philip Carneiro Date: Fri, 11 Oct 2024 11:17:19 +0100 Subject: [PATCH 3/4] improve code quality --- src/classes/insightsConnection.ts | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/src/classes/insightsConnection.ts b/src/classes/insightsConnection.ts index 6ebc287c..85edd732 100644 --- a/src/classes/insightsConnection.ts +++ b/src/classes/insightsConnection.ts @@ -346,7 +346,7 @@ export class InsightsConnection { isTableView: false, params: queryParams, }; - window.withProgress( + await window.withProgress( { location: ProgressLocation.Notification, cancellable: false, @@ -358,7 +358,7 @@ export class InsightsConnection { progress.report({ message: "Populating scratchpad..." }); - const scratchpadResponse = await axios + return await axios .post(scratchpadURL.toString(), body, headers) .then((response: any) => { if (response.data.error) { @@ -384,9 +384,6 @@ export class InsightsConnection { ); } }); - - const p = new Promise((resolve) => resolve()); - return p; }, ); } else { From d3fd871c4f53ee596b1196369fea03c69f08ddc9 Mon Sep 17 00:00:00 2001 From: Philip Carneiro Date: Fri, 11 Oct 2024 11:20:14 +0100 Subject: [PATCH 4/4] remove dummy info --- src/webview/components/kdbDataSourceView.ts | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/webview/components/kdbDataSourceView.ts b/src/webview/components/kdbDataSourceView.ts index 9fcd2808..0dae141f 100644 --- a/src/webview/components/kdbDataSourceView.ts +++ b/src/webview/components/kdbDataSourceView.ts @@ -870,8 +870,7 @@ export class KdbDataSourceView extends LitElement { ).value; this.requestChange(); }}" - >Start Time - ${this.selectedServerVersion}Start Time