diff --git a/packages/zowe-explorer/__tests__/__unit__/extension.unit.test.ts b/packages/zowe-explorer/__tests__/__unit__/extension.unit.test.ts index 02844adc82..d1a3631f85 100644 --- a/packages/zowe-explorer/__tests__/__unit__/extension.unit.test.ts +++ b/packages/zowe-explorer/__tests__/__unit__/extension.unit.test.ts @@ -351,6 +351,11 @@ async function createGlobalMocks() { "zowe.automaticProfileValidation": true, }), }); + jest.spyOn(ProfilesUtils, "getProfileInfo").mockResolvedValue({ + getTeamConfig: jest.fn().mockReturnValue({ + exists: jest.fn(), + }), + } as any); Object.defineProperty(globalMocks.mockProfilesCache, "getProfileInfo", { value: jest.fn(() => { return { value: globalMocks.mockProfCacheProfileInfo, configurable: true }; diff --git a/packages/zowe-explorer/__tests__/__unit__/utils/ProfilesUtils.unit.test.ts b/packages/zowe-explorer/__tests__/__unit__/utils/ProfilesUtils.unit.test.ts index 27c037fe82..2f20c7d619 100644 --- a/packages/zowe-explorer/__tests__/__unit__/utils/ProfilesUtils.unit.test.ts +++ b/packages/zowe-explorer/__tests__/__unit__/utils/ProfilesUtils.unit.test.ts @@ -1033,6 +1033,8 @@ describe("ProfilesUtils unit tests", () => { { name: null, type: "zosmf", error: "failed" as any }, ], } as any); + jest.spyOn(ZoweLocalStorage, "getValue").mockReturnValue(Definitions.V1MigrationStatus.JustMigrated); + jest.spyOn(ZoweLocalStorage, "setValue").mockImplementation(); Object.defineProperty(vscode.workspace, "openTextDocument", { value: jest.fn().mockReturnValue({}), configurable: true }); Object.defineProperty(Gui, "showTextDocument", { value: jest.fn(), configurable: true }); const onlyV1ProfsExistMock = new MockedProperty(imperative.ProfileInfo, "onlyV1ProfilesExist", { @@ -1070,6 +1072,13 @@ describe("ProfilesUtils unit tests", () => { it("should prompt user if v1 profiles detected and Create New is selected", async () => { const mockReadProfilesFromDisk = jest.fn(); + jest.spyOn(vscode.workspace, "getConfiguration").mockReturnValue({ + persistent: true, + get: jest.fn(), + has: jest.fn(), + inspect: jest.fn(), + update: jest.fn(), + }); const profInfoSpy = jest.spyOn(ProfilesUtils, "getProfileInfo").mockResolvedValue({ readProfilesFromDisk: mockReadProfilesFromDisk, getTeamConfig: jest.fn().mockReturnValue([]), @@ -1077,6 +1086,8 @@ describe("ProfilesUtils unit tests", () => { } as never); const infoMsgSpy = jest.spyOn(Gui, "infoMessage").mockResolvedValueOnce("Create New"); + jest.spyOn(ZoweLocalStorage, "getValue").mockReturnValue(Definitions.V1MigrationStatus.JustMigrated); + jest.spyOn(ZoweLocalStorage, "setValue").mockImplementation(); const onlyV1ProfsExistMock = new MockedProperty(imperative.ProfileInfo, "onlyV1ProfilesExist", { configurable: true, get: () => true, @@ -1102,12 +1113,17 @@ describe("ProfilesUtils unit tests", () => { const executeCommandMock = jest.spyOn(vscode.commands, "executeCommand").mockImplementation(); blockMocks.getValueMock.mockReturnValueOnce(Definitions.V1MigrationStatus.JustMigrated); blockMocks.setValueMock.mockImplementation(); + jest.spyOn(ProfilesUtils, "getProfileInfo").mockResolvedValue({ + getTeamConfig: jest.fn().mockReturnValue({ exists: false }), + } as any); + const onlyV1ProfilesExistMock = new MockedProperty(imperative.ProfileInfo, "onlyV1ProfilesExist", { get: () => true }); const v1ProfileOptsMock = jest.spyOn(ProfilesUtils as any, "v1ProfileOptions").mockResolvedValue(ProfilesConvertStatus.CreateNewSelected); await ProfilesUtils.handleV1MigrationStatus(); expect(executeCommandMock.mock.lastCall?.[0]).toBe("zowe.ds.addSession"); expect(v1ProfileOptsMock).toHaveBeenCalled(); blockMocks.getValueMock.mockRestore(); blockMocks.setValueMock.mockRestore(); + onlyV1ProfilesExistMock[Symbol.dispose](); }); it("should reload the window once if the user just migrated from v1", async () => { diff --git a/packages/zowe-explorer/src/utils/ProfilesUtils.ts b/packages/zowe-explorer/src/utils/ProfilesUtils.ts index e3407a6005..a7369eaef5 100644 --- a/packages/zowe-explorer/src/utils/ProfilesUtils.ts +++ b/packages/zowe-explorer/src/utils/ProfilesUtils.ts @@ -367,15 +367,20 @@ export class ProfilesUtils { // VS Code registers our updated TreeView IDs. Otherwise, VS Code's "Refresh Extensions" option will break v3 init. const ussPersistentSettings = vscode.workspace.getConfiguration("Zowe-USS-Persistent"); const upgradingFromV1 = ZoweLocalStorage.getValue(Definitions.LocalStorageKey.V1_MIGRATION_STATUS); + const mProfileInfo = await ProfilesUtils.getProfileInfo(); if (ussPersistentSettings != null && upgradingFromV1 == null && imperative.ProfileInfo.onlyV1ProfilesExist) { await ZoweLocalStorage.setValue(Definitions.LocalStorageKey.V1_MIGRATION_STATUS, Definitions.V1MigrationStatus.JustMigrated); await vscode.commands.executeCommand("workbench.action.reloadWindow"); } - const userSelection = imperative.ProfileInfo.onlyV1ProfilesExist ? await this.v1ProfileOptions() : undefined; + + if (upgradingFromV1 == null || mProfileInfo.getTeamConfig().exists || !imperative.ProfileInfo.onlyV1ProfilesExist) { + return; + } + const userSelection = await this.v1ProfileOptions(); // Open the "Add Session" quick pick if the user selected "Create New" in the v1 migration prompt. if (userSelection === ProfilesConvertStatus.CreateNewSelected) { - vscode.commands.executeCommand("zowe.ds.addSession", SharedTreeProviders.ds); + await vscode.commands.executeCommand("zowe.ds.addSession", SharedTreeProviders.ds); } } @@ -563,10 +568,12 @@ export class ProfilesUtils { switch (selection) { case createButton: ZoweLogger.info("Create new team configuration chosen."); + await ZoweLocalStorage.setValue(Definitions.LocalStorageKey.V1_MIGRATION_STATUS, undefined); return ProfilesConvertStatus.CreateNewSelected; case convertButton: ZoweLogger.info("Convert v1 profiles to team configuration chosen."); await this.convertV1Profs(); + await ZoweLocalStorage.setValue(Definitions.LocalStorageKey.V1_MIGRATION_STATUS, undefined); return ProfilesConvertStatus.ConvertSelected; default: return undefined;