Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[KXI-30428] allow user to disable install kdb popup #419

Merged
merged 8 commits into from
Sep 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,10 @@
"type": "string",
"description": "QHOME directory for q runtime"
},
"kdb.neverShowQInstallAgain": {
"type": "boolean",
"description": "Never show q install walkthrough again"
},
"kdb.hideSubscribeRegistrationNotification": {
"type": "boolean",
"description": "Hide subscribe for registration notification",
Expand Down
1 change: 0 additions & 1 deletion src/commands/serverCommand.ts
Original file line number Diff line number Diff line change
Expand Up @@ -545,7 +545,6 @@ export async function removeConnection(viewItem: KdbNode | InsightsNode) {

export async function connect(connLabel: string): Promise<void> {
const connMngService = new ConnectionManagementService();
commands.executeCommand("kdb-results.focus");
ExecutionConsole.start();
const viewItem = connMngService.retrieveConnection(connLabel);
if (viewItem === undefined) {
Expand Down
4 changes: 3 additions & 1 deletion src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -177,11 +177,13 @@ export async function activate(context: ExtensionContext) {
AuthSettings.init(context);
ext.secretSettings = AuthSettings.instance;

commands.executeCommand("kdb-results.focus");

kdbOutputLog("kdb extension is now active!", "INFO");

try {
// check for installed q runtime
await checkLocalInstall();
await checkLocalInstall(true);
} catch (err) {
window.showErrorMessage(`${err}`);
}
Expand Down
25 changes: 22 additions & 3 deletions src/utils/core.ts
Original file line number Diff line number Diff line change
Expand Up @@ -405,8 +405,18 @@ export function delay(ms: number) {
return new Promise((resolve) => setTimeout(resolve, ms));
}

export async function checkLocalInstall(): Promise<void> {
export async function checkLocalInstall(
isExtensionStartCheck?: boolean,
): Promise<void> {
const QHOME = workspace.getConfiguration().get<string>("kdb.qHomeDirectory");
if (isExtensionStartCheck) {
const notShow = workspace
.getConfiguration()
.get<boolean>("kdb.neverShowQInstallAgain");
if (notShow) {
return;
}
}
if (QHOME || env.QHOME) {
env.QHOME = QHOME || env.QHOME;
if (!pathExists(env.QHOME!)) {
Expand Down Expand Up @@ -454,12 +464,21 @@ export async function checkLocalInstall(): Promise<void> {
.showInformationMessage(
"Local q installation not found!",
"Install new instance",
"Cancel",
"No",
"Never show again",
)
.then(async (installResult) => {
if (installResult === "Install new instance") {
await installTools();
} else if (installResult === "Cancel") {
} else if (installResult === "Never show again") {
await workspace
.getConfiguration()
.update(
"kdb.neverShowQInstallAgain",
true,
ConfigurationTarget.Global,
);
} else {
showRegistrationNotification();
}
});
Expand Down
70 changes: 70 additions & 0 deletions test/suite/utils.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1834,4 +1834,74 @@ describe("Utils", () => {
assert.strictEqual(result, false);
});
});

describe("checkLocalInstall", () => {
let getConfigurationStub: sinon.SinonStub;
let updateConfigurationStub: sinon.SinonStub;
let showInformationMessageStub: sinon.SinonStub;
let executeCommandStub: sinon.SinonStub;

beforeEach(() => {
getConfigurationStub = sinon
.stub(vscode.workspace, "getConfiguration")
.returns({
get: sinon.stub().returns(false),
update: sinon.stub().resolves(),
} as any);
updateConfigurationStub = getConfigurationStub()
.update as sinon.SinonStub;
showInformationMessageStub = sinon
.stub(vscode.window, "showInformationMessage")
.resolves();
executeCommandStub = sinon
.stub(vscode.commands, "executeCommand")
.resolves();
});

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

it("should return if 'neverShowQInstallAgain' is true", async () => {
getConfigurationStub()
.get.withArgs("kdb.neverShowQInstallAgain")
.returns(true);

await coreUtils.checkLocalInstall(true);

assert.strictEqual(showInformationMessageStub.called, false);
assert.strictEqual(executeCommandStub.called, false);
});
it("should continue if 'neverShowQInstallAgain' is false", async () => {
getConfigurationStub()
.get.withArgs("kdb.neverShowQInstallAgain")
.returns(false);

await coreUtils.checkLocalInstall(true);

assert.strictEqual(showInformationMessageStub.called, true);
assert.strictEqual(executeCommandStub.called, true);
});

it("should handle 'Never show again' response", async () => {
getConfigurationStub()
.get.withArgs("kdb.qHomeDirectory")
.returns(undefined);
getConfigurationStub()
.get.withArgs("kdb.neverShowQInstallAgain")
.returns(false);
showInformationMessageStub.resolves("Never show again");

await coreUtils.checkLocalInstall();

assert.strictEqual(
updateConfigurationStub.calledWith(
"kdb.neverShowQInstallAgain",
true,
vscode.ConfigurationTarget.Global,
),
true,
);
});
});
});