Skip to content

Commit

Permalink
extension/src/welcome: fix 'go.showWelcome' setting interpretation
Browse files Browse the repository at this point in the history
Fixes #3319

Change-Id: Idc64d150c170c96f6e2bee4016236666bf4d4c64
Reviewed-on: https://go-review.googlesource.com/c/vscode-go/+/577075
kokoro-CI: kokoro <noreply+kokoro@google.com>
Commit-Queue: Hyang-Ah Hana Kim <hyangah@gmail.com>
Reviewed-by: Peter Weinberger <pjw@google.com>
  • Loading branch information
hyangah committed Apr 6, 2024
1 parent ad37a53 commit f8173bc
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 44 deletions.
11 changes: 5 additions & 6 deletions extension/src/welcome.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import path = require('path');
import semver = require('semver');
import { extensionId } from './const';
import { GoExtensionContext } from './context';
import { extensionInfo } from './config';
import { extensionInfo, getGoConfig } from './config';
import { getFromGlobalState, updateGlobalState } from './stateUtils';
import { createRegisterCommand } from './commands';

Expand All @@ -29,11 +29,7 @@ export class WelcomePanel {
}
});
}

// Show the Go welcome page on update.
if (!extensionInfo.isInCloudIDE && vscode.workspace.getConfiguration('go.showWelcome')) {
showGoWelcomePage();
}
showGoWelcomePage();
}

public static currentPanel: WelcomePanel | undefined;
Expand Down Expand Up @@ -278,6 +274,9 @@ function showGoWelcomePage() {
}

export function shouldShowGoWelcomePage(showVersions: string[], newVersion: string, oldVersion: string): boolean {
if (!extensionInfo.isInCloudIDE && getGoConfig().get('showWelcome') === false) {
return false;
}
if (newVersion === oldVersion) {
return false;
}
Expand Down
94 changes: 56 additions & 38 deletions extension/test/integration/welcome.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,52 +8,70 @@ import assert from 'assert';
import { shouldShowGoWelcomePage } from '../../src/welcome';
import { extensionId } from '../../src/const';
import { WelcomePanel } from '../../src/welcome';
import sinon = require('sinon');
import * as config from '../../src/config';
import { MockCfg } from '../mocks/MockCfg';

suite('WelcomePanel Tests', () => {
// 0:showVersions, 1:newVersion, 2:oldVersion, 3:expected
type testCase = [string[], string, string, boolean];
let sandbox: sinon.SinonSandbox;
setup(() => {
sandbox = sinon.createSandbox();
});
teardown(() => sandbox.restore());

// 0:showVersions, 1:newVersion, 2:oldVersion, 3: showWelcome, 4:expected
//
// If showWelcome is false, then expected has to be false.
// Otherwise, expected is true if (and only if) newVersion occurs in showVersions
// and is newer than oldVersion (as semantic versions).
type testCase = [string[], string, string, boolean, boolean];
const testCases: testCase[] = [
[[], '0.22.0', '0.0.0', false],
[[], '0.22.0', '0.21.0', false],
[[], '0.22.0', '0.22.0-rc.1', false],
[[], '0.22.0', '0.22.0', false],
[[], '0.22.0', '0.23.0', false],
[[], '0.22.0', '0.0.0', true, false],
[[], '0.22.0', '0.21.0', true, false],
[[], '0.22.0', '0.22.0-rc.1', true, false],
[[], '0.22.0', '0.22.0', true, false],
[[], '0.22.0', '0.23.0', true, false],

[['0.22.0'], '0.22.0', '0.0.0', true],
[['0.22.0'], '0.22.0', '0.21.0-rc.1', true],
[['0.22.0'], '0.22.0', '0.21.0', true],
[['0.22.0'], '0.22.0', '0.22.0-rc.1', true],
[['0.22.0'], '0.22.0', '0.22.0', false],
[['0.22.0'], '0.22.0', '0.22.1', false],
[['0.22.0'], '0.22.0', '0.23.0', false],
[['0.22.0'], '0.22.0', '1.0.0', false],
[['0.22.0'], '0.22.0', '2021.1.100', false],
[['0.22.0'], '0.22.0', '0.0.0', true, true],
[['0.22.0'], '0.22.0', '0.0.0', false, false],
[['0.22.0'], '0.22.0', '0.21.0-rc.1', true, true],
[['0.22.0'], '0.22.0', '0.21.0', true, true],
[['0.22.0'], '0.22.0', '0.22.0-rc.1', true, true],
[['0.22.0'], '0.22.0', '0.22.0', true, false],
[['0.22.0'], '0.22.0', '0.22.1', true, false],
[['0.22.0'], '0.22.0', '0.23.0', true, false],
[['0.22.0'], '0.22.0', '1.0.0', true, false],
[['0.22.0'], '0.22.0', '2021.1.100', true, false],

[['0.22.0'], '0.22.0-rc.2', '0.0.0', true],
[['0.22.0'], '0.22.0-rc.2', '0.21.0-rc.1', true],
[['0.22.0'], '0.22.0-rc.2', '0.21.0', true],
[['0.22.0'], '0.22.0-rc.2', '0.22.0-rc.1', true],
[['0.22.0'], '0.22.0-rc.2', '0.22.0-rc.2', false],
[['0.22.0'], '0.22.0-rc.2', '0.22.0-rc.3', true],
[['0.22.0'], '0.22.0-rc.2', '0.22.0', true],
[['0.22.0'], '0.22.0-rc.2', '0.22.1', false],
[['0.22.0'], '0.22.0-rc.2', '0.23.0', false],
[['0.22.0'], '0.22.0-rc.2', '1.0.0', false],
[['0.22.0'], '0.22.0-rc.2', '2021.1.100', false],
[['0.22.0'], '0.22.0-rc.2', '0.0.0', true, true],
[['0.22.0'], '0.22.0-rc.2', '0.21.0-rc.1', true, true],
[['0.22.0'], '0.22.0-rc.2', '0.21.0', true, true],
[['0.22.0'], '0.22.0-rc.2', '0.22.0-rc.1', true, true],
[['0.22.0'], '0.22.0-rc.2', '0.22.0-rc.2', true, false],
[['0.22.0'], '0.22.0-rc.2', '0.22.0-rc.3', true, true],
[['0.22.0'], '0.22.0-rc.2', '0.22.0', true, true],
[['0.22.0'], '0.22.0-rc.2', '0.22.1', true, false],
[['0.22.0'], '0.22.0-rc.2', '0.23.0', true, false],
[['0.22.0'], '0.22.0-rc.2', '1.0.0', true, false],
[['0.22.0'], '0.22.0-rc.2', '2021.1.100', true, false],

[['0.22.0'], '0.22.1', '0.0.0', false],
[['0.22.0'], '0.22.1', '0.21.0-rc.1', false],
[['0.22.0'], '0.22.1', '0.21.0', false],
[['0.22.0'], '0.22.1', '0.22.0-rc.1', false],
[['0.22.0'], '0.22.1', '0.22.0', false],
[['0.22.0'], '0.22.1', '0.23.0', false],
[['0.22.0'], '0.22.1', '1.0.0', false],
[['0.22.0'], '0.22.1', '2021.1.100', false]
[['0.22.0'], '0.22.1', '0.0.0', true, false],
[['0.22.0'], '0.22.1', '0.21.0-rc.1', true, false],
[['0.22.0'], '0.22.1', '0.21.0', true, false],
[['0.22.0'], '0.22.1', '0.22.0-rc.1', true, false],
[['0.22.0'], '0.22.1', '0.22.0', true, false],
[['0.22.0'], '0.22.1', '0.23.0', true, false],
[['0.22.0'], '0.22.1', '1.0.0', true, false],
[['0.22.0'], '0.22.1', '2021.1.100', true, false]
];
testCases.forEach((c: testCase) => {
const [showVersions, newVersion, oldVersion, expected] = c;

test(`shouldShowGoWelcomePage(${JSON.stringify(showVersions)}, ${newVersion}, ${oldVersion})`, () => {
const [showVersions, newVersion, oldVersion, showWelcome, expected] = c;
test(`shouldShowGoWelcomePage(${JSON.stringify(
showVersions
)}, ${newVersion}, ${oldVersion}, (showWelcome=${showWelcome}))`, () => {
const goConfig = new MockCfg([]);
sandbox.stub(config, 'getGoConfig').returns(goConfig);
sinon.stub(goConfig, 'get').withArgs('showWelcome').returns(showWelcome);
assert.strictEqual(shouldShowGoWelcomePage(showVersions, newVersion, oldVersion), expected);
});
});
Expand Down

0 comments on commit f8173bc

Please sign in to comment.