diff --git a/__tests__/__unit__/DatasetTree.unit.test.ts b/__tests__/__unit__/DatasetTree.unit.test.ts index b0b59dbc2c..09409cd3d4 100644 --- a/__tests__/__unit__/DatasetTree.unit.test.ts +++ b/__tests__/__unit__/DatasetTree.unit.test.ts @@ -766,6 +766,70 @@ describe("DatasetTree Unit Tests", () => { }); + it("tests the dataset filter prompt credentials, favorite route", async () => { + showQuickPick.mockReset(); + showInputBox.mockReset(); + const sessionwocred = new Session({ + user: "", + password: "", + hostname: "fake", + port: 443, + protocol: "https", + type: "basic", + }); + const sessNode = new ZoweNode("sestest", vscode.TreeItemCollapsibleState.Expanded, null, session); + sessNode.contextValue = extension.DS_SESSION_CONTEXT + extension.FAV_SUFFIX; + const dsNode = new ZoweNode("[testSess2]: node", vscode.TreeItemCollapsibleState.Expanded, sessNode, sessionwocred); + dsNode.contextValue = extension.DS_SESSION_CONTEXT + extension.FAV_SUFFIX; + testTree.mSessionNodes.push(dsNode); + const dsNode2 = new ZoweNode("testSess2", vscode.TreeItemCollapsibleState.Expanded, sessNode, sessionwocred); + dsNode2.contextValue = extension.DS_SESSION_CONTEXT + extension.FAV_SUFFIX; + testTree.mSessionNodes.push(dsNode2); + getConfiguration.mockReturnValue({ + persistence: true, + get: (setting: string) => [ + "[test]: brtvs99.public1.test{pds}", + "[test]: brtvs99.test{ds}", + "[test]: brtvs99.fail{fail}", + "[test]: brtvs99.test.search{session}", + "[test]: brtvs99.test.*{session}", + ], + update: jest.fn(()=>{ + return {}; + }) + }); + Object.defineProperty(Profiles, "getInstance", { + value: jest.fn(() => { + return { + allProfiles: [{name: "firstName", profile: {user:undefined, password: undefined}}, {name: "secondName"}], + defaultProfile: {name: "firstName"}, + loadNamedProfile: jest.fn(()=> { + return null; + }), + promptCredentials: jest.fn(()=> { + return ["", "", ""]; + }), + }; + }) + }); + + const spyMe = new DatasetTree(); + Object.defineProperty(spyMe, "datasetFilterPrompt", { + value: jest.fn(() => { + return { + tempNode: dsNode2, + mSessionNodes: {Session: {ISession: {user: "", password: "", base64EncodedAuth: ""}}} + }; + }) + }); + + testTree.initialize(Logger.getAppLogger()); + await testTree.datasetFilterPrompt(dsNode); + + expect(showInformationMessage.mock.calls[0][0]).toEqual("No selection made."); + + }); + it("tests the dataset filter prompt credentials error", async () => { showQuickPick.mockReset(); showInputBox.mockReset(); diff --git a/i18n/sample/src/DatasetTree.i18n.json b/i18n/sample/src/DatasetTree.i18n.json index 089919d541..b1ba79951c 100644 --- a/i18n/sample/src/DatasetTree.i18n.json +++ b/i18n/sample/src/DatasetTree.i18n.json @@ -5,6 +5,8 @@ "intializeFavorites.error.profile2": ". To resolve this, you can create a profile with this name, ", "initializeFavorites.error.profile3": "or remove the favorites with this profile name from the Zowe-DS-Persistent setting, ", "initializeFavorites.error.profile4": "which can be found in your VS Code user settings.", + "loadNamedProfile.error.profileName": "Initialization Error: Could not find profile named: ", + "loadNamedProfile.error.period": ".", "initializeFavorites.fileCorrupted": "Favorites file corrupted: ", "addFavorite": "PDS already in favorites", "enterPattern.log.debug.prompt": "Prompting the user for a data set pattern", diff --git a/src/DatasetTree.ts b/src/DatasetTree.ts index 139c939de8..21c160f80c 100644 --- a/src/DatasetTree.ts +++ b/src/DatasetTree.ts @@ -109,7 +109,15 @@ export class DatasetTree implements vscode.TreeDataProvider { } } else if (favoriteSearchPattern.test(line)) { const sesName = line.substring(1, line.lastIndexOf("]")).trim(); - const zosmfProfile = Profiles.getInstance().loadNamedProfile(sesName); + let zosmfProfile: IProfileLoaded; + try { + zosmfProfile = Profiles.getInstance().loadNamedProfile(sesName); + } catch (error) { + vscode.window.showErrorMessage(localize("loadNamedProfile.error.profileName", + "Initialization Error: Could not find profile named: ") + + sesName + localize("loadNamedProfile.error.period", ".")); + continue; + } const session = zowe.ZosmfSession.createBasicZosmfSession(zosmfProfile.profile); const node = new ZoweNode(line.substring(0, line.lastIndexOf("{")), vscode.TreeItemCollapsibleState.None, this.mFavoriteSession, session);