Skip to content

Commit

Permalink
Merge branch 'main' into hide-profile-only-one-time
Browse files Browse the repository at this point in the history
Signed-off-by: Rudy Flores <[email protected]>
  • Loading branch information
rudyflores authored Nov 14, 2023
2 parents d69b513 + 72177f2 commit 8265193
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 4 deletions.
1 change: 1 addition & 0 deletions packages/zowe-explorer/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ All notable changes to the "vscode-extension-for-zowe" extension will be documen
### New features and enhancements

- Added support for hiding a Zowe profile across all trees [#2567](https://github.com/zowe/vscode-extension-for-zowe/issues/2567)
- Added Display confirmation dialog when submitting local JCL. [#2061](https://github.com/zowe/vscode-extension-for-zowe/issues/2061)

### Bug fixes

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3731,3 +3731,28 @@ describe("Dataset Actions Unit Tests - Function allocateLike", () => {
expect(errorHandlingSpy).toHaveBeenCalledWith(errorMessage, "test", "Unable to create data set.");
});
});

describe("Dataset Actions Unit Tests - Function confirmJobSubmission", () => {
function createBlockMocks() {
mocked(vscode.window.showInputBox).mockImplementation((options) => {
options.validateInput("test");
return Promise.resolve("test");
});

return {};
}
it("Should use use local JCL doc name for confirmJobSubmission", async () => {
createGlobalMocks();
const blockMocks = createBlockMocks();
jest.spyOn(vscode.workspace, "getConfiguration").mockImplementation(
() =>
({
get: () => sharedUtils.JOB_SUBMIT_DIALOG_OPTS[1],
} as any)
);
jest.spyOn(Gui, "warningMessage").mockResolvedValue({
title: "Submit",
});
await expect(dsActions.confirmJobSubmission(null, true, "Profile\\test.jcl")).resolves.toEqual(true);
});
});
15 changes: 15 additions & 0 deletions packages/zowe-explorer/__tests__/__unit__/job/actions.unit.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -557,6 +557,21 @@ describe("Jobs Actions Unit Tests - Function submitJcl", () => {
expect(blockMocks.errorGuiMsgSpy).toBeCalledWith(errorMsg);
});

it("Checking cancel option scenario of local JCL submission confirmation dialog", async () => {
const blockMocks: any = createBlockMocks();
jest.spyOn(ZoweLogger, "trace").mockImplementation();
Object.defineProperty(vscode.window, "activeTextEditor", {
value: { document: { fileName: "test" } } as any,
configurable: true,
});
jest.spyOn(vscode.commands, "executeCommand").mockImplementation();
jest.spyOn(ZoweLogger, "debug").mockImplementation();
const confirmJobSubmissionSpy = jest.spyOn(dsActions, "confirmJobSubmission");
confirmJobSubmissionSpy.mockResolvedValue(false);
await expect(dsActions.submitJcl(blockMocks.testDatasetTree, {} as any)).resolves.toEqual(undefined);
confirmJobSubmissionSpy.mockRestore();
});

it("Checking failed attempt to submit of active text editor content as JCL without profile chosen from quickpick", async () => {
createGlobalMocks();
const blockMocks = createBlockMocks();
Expand Down
20 changes: 16 additions & 4 deletions packages/zowe-explorer/src/dataset/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -987,11 +987,19 @@ export async function submitJcl(datasetProvider: api.IZoweTree<api.IZoweDatasetT
ZoweLogger.error(notActiveEditorMsg);
return;
}

if (file) {
await vscode.commands.executeCommand("filesExplorer.openFilePreserveFocus", file);
}
const doc = vscode.window.activeTextEditor.document;
ZoweLogger.debug(localize("submitJcl.submitting", "Submitting as JCL in document {0}", doc.fileName));

// prompts for job submit confirmation when submitting local JCL from editor/palette
// no node passed in, ownsJob is true because local file is always owned by userID, passes in local file name
if (!(await this.confirmJobSubmission(null, true, doc.fileName))) {
return;
}

// get session name
const sessionregex = /\[(.*)(\])(?!.*\])/g;
const regExp = sessionregex.exec(doc.fileName);
Expand Down Expand Up @@ -1057,20 +1065,25 @@ export async function submitJcl(datasetProvider: api.IZoweTree<api.IZoweDatasetT
*
* @param node The node/member that is being submitted
* @param ownsJob Whether the current user profile owns this job
* @param fileName When submitting local JCL, use the document file name to submit
* @returns Whether the job submission should continue.
*/
async function confirmJobSubmission(node: api.IZoweTreeNode, ownsJob: boolean): Promise<boolean> {
export async function confirmJobSubmission(node: api.IZoweTreeNode, ownsJob: boolean, fileName?: string): Promise<boolean> {
ZoweLogger.trace("dataset.actions.confirmJobSubmission called.");

const showConfirmationDialog = async (): Promise<boolean> => {
const jclName =
node == null && fileName !== null ? fileName.toString().substring(fileName.lastIndexOf("\\") + 1) : node.getLabel().toString();

const selection = await api.Gui.warningMessage(
localize("confirmJobSubmission.confirm", "Are you sure you want to submit the following job?\n\n{0}", node.getLabel().toString()),
localize("confirmJobSubmission.confirm", "Are you sure you want to submit the following job?\n\n{0}", jclName),
{ items: [{ title: "Submit" }], vsCodeOpts: { modal: true } }
);

return selection != null && selection?.title === "Submit";
};

const confirmationOption: string = vscode.workspace.getConfiguration().get("zowe.jobs.confirmSubmission");

switch (JOB_SUBMIT_DIALOG_OPTS.indexOf(confirmationOption)) {
case JobSubmitDialogOpts.OtherUserJobs:
if (!ownsJob && !(await showConfirmationDialog())) {
Expand All @@ -1091,7 +1104,6 @@ async function confirmJobSubmission(node: api.IZoweTreeNode, ownsJob: boolean):
default:
break;
}

return true;
}

Expand Down

0 comments on commit 8265193

Please sign in to comment.