Skip to content

Commit

Permalink
Merge pull request #2646 from zowe/Check-for-profile
Browse files Browse the repository at this point in the history
Submit as JCL: check for profile before presenting quick pick
  • Loading branch information
zFernand0 authored Jan 9, 2024
2 parents 63c9027 + 7ab45b6 commit 86bdfb5
Show file tree
Hide file tree
Showing 3 changed files with 85 additions and 17 deletions.
1 change: 1 addition & 0 deletions packages/zowe-explorer/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ All notable changes to the "vscode-extension-for-zowe" extension will be documen

- Added new data set creation template for partitioned data set extended. [#2600](https://github.com/zowe/vscode-extension-for-zowe/issues/2600)
- Added "Open with Encoding" feature to open data sets and USS files in a non-standard codepage. [#2435](https://github.com/zowe/vscode-extension-for-zowe/issues/2435)
- Implemented profile determination without triggering quick pick for `Submit JCL` if the file is part of Zowe Explorer's temp files. [#2628](https://github.com/zowe/vscode-extension-for-zowe/issues/2628)

### Bug fixes

Expand Down
70 changes: 65 additions & 5 deletions packages/zowe-explorer/__tests__/__unit__/job/actions.unit.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -419,16 +419,26 @@ describe("Jobs Actions Unit Tests - Function submitJcl", () => {
const datasetSessionNode = createDatasetSessionNode(session, imperativeProfile);
const textDocument = createTextDocument("HLQ.TEST.AFILE(mem)", datasetSessionNode);
(textDocument.languageId as any) = "jcl";
(textDocument.uri.fsPath as any) = "/user/temp/textdocument.txt";
const profileInstance = createInstanceOfProfile(imperativeProfile);
const jesApi = createJesApi(imperativeProfile);
const mockCheckCurrentProfile = jest.fn();
const mockLoadNamedProfile = jest.fn();
bindJesApi(jesApi);
Object.defineProperty(profileInstance, "loadNamedProfile", {
value: jest.fn(),
configurable: true,
});
const errorGuiMsgSpy = jest.spyOn(Gui, "errorMessage");
const errorLogSpy = jest.spyOn(ZoweLogger, "error");
Object.defineProperty(Profiles, "getInstance", {
value: jest.fn(() => {
return {
loadNamedProfile: mockLoadNamedProfile.mockReturnValueOnce(imperativeProfile),
checkCurrentProfile: mockCheckCurrentProfile.mockReturnValueOnce({
name: imperativeProfile.name,
status: "unverified",
}),
validProfile: ValidProfileEnum.UNVERIFIED,
};
}),
});

return {
session,
Expand All @@ -443,6 +453,7 @@ describe("Jobs Actions Unit Tests - Function submitJcl", () => {
mockCheckCurrentProfile,
errorLogSpy,
errorGuiMsgSpy,
mockLoadNamedProfile,
};
}

Expand Down Expand Up @@ -549,9 +560,13 @@ describe("Jobs Actions Unit Tests - Function submitJcl", () => {
const blockMocks: any = createBlockMocks();
jest.spyOn(ZoweLogger, "trace").mockImplementation();
Object.defineProperty(vscode.window, "activeTextEditor", {
value: { document: { fileName: "test" } } as any,
value: { document: { fileName: "test", uri: { fsPath: "fake/profilename/document.txt" } } } as any,
configurable: true,
});
blockMocks.testDatasetTree.getChildren.mockResolvedValueOnce([
new ZoweDatasetNode({ label: "node", collapsibleState: vscode.TreeItemCollapsibleState.None, parentNode: blockMocks.datasetSessionNode }),
blockMocks.datasetSessionNode,
]);
jest.spyOn(vscode.commands, "executeCommand").mockImplementation();
jest.spyOn(ZoweLogger, "debug").mockImplementation();
const confirmJobSubmissionSpy = jest.spyOn(dsActions, "confirmJobSubmission");
Expand All @@ -563,6 +578,10 @@ describe("Jobs Actions Unit Tests - Function submitJcl", () => {
it("Checking failed attempt to submit of active text editor content as JCL without profile chosen from quickpick", async () => {
createGlobalMocks();
const blockMocks = createBlockMocks();
Object.defineProperty(ProfileManagement, "getRegisteredProfileNameList", {
value: jest.fn().mockReturnValue(["firstName", "secondName"]),
configurable: true,
});
mocked(zowe.ZosmfSession.createSessCfgFromArgs).mockReturnValue(blockMocks.session.ISession);
mocked(Profiles.getInstance).mockReturnValue(blockMocks.profileInstance);
mocked(vscode.window.showQuickPick).mockResolvedValueOnce(undefined); // Here we imitate the case when no profile was selected
Expand Down Expand Up @@ -606,6 +625,47 @@ describe("Jobs Actions Unit Tests - Function submitJcl", () => {
expect(mocked(Gui.errorMessage)).toBeCalled();
expect(mocked(Gui.errorMessage).mock.calls[0][0]).toContain(testError.message);
});
it("If there are no registered profiles", async () => {
createGlobalMocks();
const blockMocks: any = createBlockMocks();
Object.defineProperty(ProfileManagement, "getRegisteredProfileNameList", {
value: jest.fn().mockReturnValue([]),
configurable: true,
});
blockMocks.testDatasetTree.getChildren.mockResolvedValueOnce([
new ZoweDatasetNode({ label: "node", collapsibleState: vscode.TreeItemCollapsibleState.None, parentNode: blockMocks.datasetSessionNode }),
blockMocks.datasetSessionNode,
]);
mocked(zowe.ZosmfSession.createSessCfgFromArgs).mockReturnValue(blockMocks.session);
mocked(Profiles.getInstance).mockReturnValue(blockMocks.profileInstance);
activeTextEditorDocument.mockReturnValue(blockMocks.textDocument);
const showMessagespy = jest.spyOn(Gui, "showMessage");

await dsActions.submitJcl(blockMocks.testDatasetTree, undefined);

expect(showMessagespy).toBeCalledWith("No profiles available");
});
it("Getting session name from the path itself", async () => {
globals.defineGlobals("/user/");
createGlobalMocks();
const blockMocks: any = createBlockMocks();
mocked(zowe.ZosmfSession.createSessCfgFromArgs).mockReturnValue(blockMocks.session);
mocked(Profiles.getInstance).mockReturnValue(blockMocks.profileInstance);
blockMocks.testDatasetTree.getChildren.mockResolvedValueOnce([
new ZoweDatasetNode({ label: "node", collapsibleState: vscode.TreeItemCollapsibleState.None, parentNode: blockMocks.datasetSessionNode }),
blockMocks.datasetSessionNode,
]);
blockMocks.datasetSessionNode.label = "temp";
activeTextEditorDocument.mockReturnValue(blockMocks.textDocument);
const submitJclSpy = jest.spyOn(blockMocks.jesApi, "submitJcl");
submitJclSpy.mockClear();
submitJclSpy.mockResolvedValueOnce(blockMocks.iJob);
await dsActions.submitJcl(blockMocks.testDatasetTree, undefined);

expect(submitJclSpy).toBeCalled();
expect(mocked(Gui.showMessage)).toBeCalled();
expect(mocked(Gui.showMessage).mock.calls.length).toBe(1);
});
});

describe("Jobs Actions Unit Tests - Function submitMember", () => {
Expand Down
31 changes: 19 additions & 12 deletions packages/zowe-explorer/src/dataset/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -931,20 +931,27 @@ export async function submitJcl(datasetProvider: api.IZoweTree<api.IZoweDatasetT
const profiles = Profiles.getInstance();
let sessProfileName;
if (regExp === null) {
const profileNamesList = ProfileManagement.getRegisteredProfileNameList(globals.Trees.JES);
if (profileNamesList.length) {
const quickPickOptions: vscode.QuickPickOptions = {
placeHolder: localize("submitJcl.qp.placeholder", "Select the Profile to use to submit the job"),
ignoreFocusOut: true,
canPickMany: false,
};
sessProfileName = await api.Gui.showQuickPick(profileNamesList, quickPickOptions);
if (!sessProfileName) {
api.Gui.infoMessage(localizedStrings.opCancelled);
return;
if (!doc.uri.fsPath.includes(globals.ZOWETEMPFOLDER)) {
const profileNamesList = ProfileManagement.getRegisteredProfileNameList(globals.Trees.JES);
if (profileNamesList.length > 1) {
const quickPickOptions: vscode.QuickPickOptions = {
placeHolder: localize("submitJcl.qp.placeholder", "Select the Profile to use to submit the job"),
ignoreFocusOut: true,
canPickMany: false,
};
sessProfileName = await api.Gui.showQuickPick(profileNamesList, quickPickOptions);
if (!sessProfileName) {
api.Gui.infoMessage(localizedStrings.opCancelled);
return;
}
} else if (profileNamesList.length > 0) {
sessProfileName = profileNamesList[0];
} else {
api.Gui.showMessage(localize("submitJcl.noProfile", "No profiles available"));
}
} else {
api.Gui.showMessage(localize("submitJcl.noProfile", "No profiles available"));
const filePathArray = doc.uri.fsPath.split(path.sep);
sessProfileName = filePathArray[filePathArray.length - 2];
}
} else {
sessProfileName = regExp[1];
Expand Down

0 comments on commit 86bdfb5

Please sign in to comment.