From e83d1e2ab2622537a4b4eb56a217af454068848f Mon Sep 17 00:00:00 2001 From: Ning Tang Date: Wed, 3 Jul 2024 15:38:55 +0800 Subject: [PATCH] fix: not show the changelog prompt on a fresh install --- packages/vscode-extension/src/utils/releaseNote.ts | 11 ++++------- .../vscode-extension/test/utils/releaseNote.test.ts | 11 ++++++++++- 2 files changed, 14 insertions(+), 8 deletions(-) diff --git a/packages/vscode-extension/src/utils/releaseNote.ts b/packages/vscode-extension/src/utils/releaseNote.ts index bbdaf5dd3e..7312270ae2 100644 --- a/packages/vscode-extension/src/utils/releaseNote.ts +++ b/packages/vscode-extension/src/utils/releaseNote.ts @@ -39,17 +39,14 @@ export class ReleaseNote { } } else { const currentStableVersion = this.context.globalState.get(SyncedState.Version); + await this.context.globalState.update(SyncedState.Version, teamsToolkitVersion); if ( - currentStableVersion === undefined || + currentStableVersion !== undefined && versionUtil.compare(teamsToolkitVersion, currentStableVersion) === 1 ) { - // if syncedVersion is undefined, then it is not existinig user - await this.context.globalState.update( - UserState.IsExisting, - currentStableVersion === undefined ? "no" : "yes" - ); + // it is existinig user + await this.context.globalState.update(UserState.IsExisting, "yes"); ExtTelemetry.sendTelemetryEvent(TelemetryEvent.ShowWhatIsNewNotification); - await this.context.globalState.update(SyncedState.Version, teamsToolkitVersion); const changelog = { title: localize("teamstoolkit.upgrade.changelog"), diff --git a/packages/vscode-extension/test/utils/releaseNote.test.ts b/packages/vscode-extension/test/utils/releaseNote.test.ts index 7b50cef7da..8d001ac6f0 100644 --- a/packages/vscode-extension/test/utils/releaseNote.test.ts +++ b/packages/vscode-extension/test/utils/releaseNote.test.ts @@ -98,7 +98,16 @@ describe("Release Note", () => { sandbox.stub(vscode.window, "showInformationMessage").resolves(); const instance = new ReleaseNote(context); await instance.show(); - sinon.assert.notCalled(contextSpy); + sinon.assert.calledOnce(contextSpy); + chai.assert(telemetryStub.notCalled); + }); + it("should not show changelog when it's a fresh install", async () => { + const contextSpy = sandbox.spy(context.globalState, "update"); + sandbox.stub(context.globalState, "get").returns(undefined); + sandbox.stub(vscode.window, "showInformationMessage").resolves(); + const instance = new ReleaseNote(context); + await instance.show(); + sinon.assert.calledOnce(contextSpy); chai.assert(telemetryStub.notCalled); }); });