From 8fe027a4497c6b97d48fa851b3837a9a861ce4ec Mon Sep 17 00:00:00 2001 From: Billie Simmons <49491949+JillieBeanSim@users.noreply.github.com> Date: Tue, 10 Oct 2023 09:42:02 -0400 Subject: [PATCH 01/11] Submit JCL right-click option added for local JCL Signed-off-by: Billie Simmons <49491949+JillieBeanSim@users.noreply.github.com> --- packages/zowe-explorer/package.json | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/packages/zowe-explorer/package.json b/packages/zowe-explorer/package.json index c602c3c2d8..b79b9c3b1d 100644 --- a/packages/zowe-explorer/package.json +++ b/packages/zowe-explorer/package.json @@ -822,6 +822,20 @@ "group": "navigation" } ], + "editor/context": [ + { + "when": "resourceLangId == jcl", + "command": "zowe.ds.submitJcl", + "group": "000_zowe_dsMainframeInteraction@1" + } + ], + "explorer/context": [ + { + "when": "resourceLangId == jcl", + "command": "zowe.ds.submitJcl", + "group": "000_zowe_dsMainframeInteraction@1" + } + ], "view/item/context": [ { "when": "viewItem =~ /^(?!.*_fav.*)ussSession.*/ && !listMultiSelection", From 9ade075f1f6fb675a64be1bbf146d004bc4a13e0 Mon Sep 17 00:00:00 2001 From: Billie Simmons <49491949+JillieBeanSim@users.noreply.github.com> Date: Tue, 10 Oct 2023 09:42:10 -0400 Subject: [PATCH 02/11] Add check for doc language in the Submit JCL method Signed-off-by: Billie Simmons <49491949+JillieBeanSim@users.noreply.github.com> --- packages/zowe-explorer/src/dataset/actions.ts | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/packages/zowe-explorer/src/dataset/actions.ts b/packages/zowe-explorer/src/dataset/actions.ts index 7c7d64c02e..aa7d712e40 100644 --- a/packages/zowe-explorer/src/dataset/actions.ts +++ b/packages/zowe-explorer/src/dataset/actions.ts @@ -976,12 +976,21 @@ export async function showAttributes(node: api.IZoweDatasetTreeNode, datasetProv export async function submitJcl(datasetProvider: api.IZoweTree): Promise { ZoweLogger.trace("dataset.actions.submitJcl called."); if (!vscode.window.activeTextEditor) { - const errorMsg = localize("submitJcl.noDocumentOpen", "No editor with a document that could be submitted as JCL is currently open."); - api.Gui.errorMessage(errorMsg); - ZoweLogger.error(errorMsg); + const notActiveEditorMsg = localize( + "submitJcl.notActiveEditorMsg", + "No editor with a document that could be submitted as JCL is currently open." + ); + api.Gui.errorMessage(notActiveEditorMsg); + ZoweLogger.error(notActiveEditorMsg); return; } const doc = vscode.window.activeTextEditor.document; + if (doc.languageId !== "jcl") { + const notJclMsg = localize("submitJcl.notJclMsg", "The document being submitted is not a JCL, submission cancelled."); + api.Gui.errorMessage(notJclMsg); + ZoweLogger.error(notJclMsg); + return; + } ZoweLogger.debug(localize("submitJcl.submitting", "Submitting JCL in document {0}", doc.fileName)); // get session name const sessionregex = /\[(.*)(\])(?!.*\])/g; From 0bf58caf89a03fac473dbbe285742f256a7e97ae Mon Sep 17 00:00:00 2001 From: Billie Simmons <49491949+JillieBeanSim@users.noreply.github.com> Date: Tue, 10 Oct 2023 09:49:01 -0400 Subject: [PATCH 03/11] fix unit tests Signed-off-by: Billie Simmons <49491949+JillieBeanSim@users.noreply.github.com> --- .../zowe-explorer/__tests__/__unit__/job/actions.unit.test.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/packages/zowe-explorer/__tests__/__unit__/job/actions.unit.test.ts b/packages/zowe-explorer/__tests__/__unit__/job/actions.unit.test.ts index 85737a5c89..ad589fd9e2 100644 --- a/packages/zowe-explorer/__tests__/__unit__/job/actions.unit.test.ts +++ b/packages/zowe-explorer/__tests__/__unit__/job/actions.unit.test.ts @@ -486,6 +486,7 @@ describe("Jobs Actions Unit Tests - Function submitJcl", () => { Object.defineProperty(profileInstance, "loadNamedProfile", { value: jest.fn(), }); + (textDocument.languageId as any) = "jcl"; return { session, From a761593bfdd7d9622847335c4fbbd30b56e97e1c Mon Sep 17 00:00:00 2001 From: Billie Simmons <49491949+JillieBeanSim@users.noreply.github.com> Date: Tue, 10 Oct 2023 09:55:37 -0400 Subject: [PATCH 04/11] add CHANGELOG Signed-off-by: Billie Simmons <49491949+JillieBeanSim@users.noreply.github.com> --- packages/zowe-explorer/CHANGELOG.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/packages/zowe-explorer/CHANGELOG.md b/packages/zowe-explorer/CHANGELOG.md index b4815bcd01..ef6267c634 100644 --- a/packages/zowe-explorer/CHANGELOG.md +++ b/packages/zowe-explorer/CHANGELOG.md @@ -10,10 +10,11 @@ All notable changes to the "vscode-extension-for-zowe" extension will be documen - Introduce a new user interface for managing profiles via right-click action "Manage Profile". - Added new edit feature on `Edit Attributes` view for changing file tags on USS [#2113](https://github.com/zowe/vscode-extension-for-zowe/issues/2113) - Added new API {ZE Extender MetaData} to allow extenders to have the metadata of registered extenders to aid in team configuration file creation from a view that isn't Zowe Explorer's. [#2394](https://github.com/zowe/vscode-extension-for-zowe/issues/2394) +- Added new right-click action for `Submit JCL` to local JCL files in VS Code file explorer as well as JCL opened in the VS Code text editor. [#2475](https://github.com/zowe/vscode-extension-for-zowe/issues/2475) ### Bug fixes -- Fixed submitting local JCL using command pallet option `Zowe Explorer: Submit JCL` by adding a check for chosen profile returned to continue the action. [#1625](https://github.com/zowe/vscode-extension-for-zowe/issues/1625) +- Fixed submitting local JCL using command pallet option `Zowe Explorer: Submit JCL` by adding a check for chosen profile returned to continue the action and added check on the language id for JCL. [#1625](https://github.com/zowe/vscode-extension-for-zowe/issues/1625) - Fixed conflict resolution being skipped if local and remote file have different contents but are the same size. [#2496](https://github.com/zowe/vscode-extension-for-zowe/issues/2496) ## `2.11.0` From 64ea1e431ef6d0ace622c8b40c2cb37d1bb95ef3 Mon Sep 17 00:00:00 2001 From: Billie Simmons <49491949+JillieBeanSim@users.noreply.github.com> Date: Tue, 10 Oct 2023 09:58:29 -0400 Subject: [PATCH 05/11] run prepublish Signed-off-by: Billie Simmons <49491949+JillieBeanSim@users.noreply.github.com> --- .../zowe-explorer/i18n/sample/src/dataset/actions.i18n.json | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/packages/zowe-explorer/i18n/sample/src/dataset/actions.i18n.json b/packages/zowe-explorer/i18n/sample/src/dataset/actions.i18n.json index aa1718439c..114e621ffc 100644 --- a/packages/zowe-explorer/i18n/sample/src/dataset/actions.i18n.json +++ b/packages/zowe-explorer/i18n/sample/src/dataset/actions.i18n.json @@ -42,7 +42,8 @@ "showAttributes.lengthError": "No matching names found for query: {0}", "showAttributes.error": "Unable to list attributes.", "attributes.title": "Attributes", - "submitJcl.noDocumentOpen": "No editor with a document that could be submitted as JCL is currently open.", + "submitJcl.notActiveEditorMsg": "No editor with a document that could be submitted as JCL is currently open.", + "submitJcl.notJclMsg": "The document being submitted is not a JCL, submission cancelled.", "submitJcl.submitting": "Submitting JCL in document {0}", "submitJcl.qp.placeholder": "Select the Profile to use to submit the job", "submitJcl.noProfile": "No profiles available", From f7b34f3caecf8c9ac16184203cab3ab8fce21d39 Mon Sep 17 00:00:00 2001 From: Billie Simmons <49491949+JillieBeanSim@users.noreply.github.com> Date: Wed, 11 Oct 2023 14:20:25 -0400 Subject: [PATCH 06/11] update checks for langId and add passing of file when needed Signed-off-by: Billie Simmons <49491949+JillieBeanSim@users.noreply.github.com> --- .../__unit__/dataset/init.unit.test.ts | 2 +- .../__unit__/job/actions.unit.test.ts | 262 ++++++++++++------ packages/zowe-explorer/package.json | 4 +- packages/zowe-explorer/src/dataset/actions.ts | 14 +- packages/zowe-explorer/src/dataset/init.ts | 2 +- 5 files changed, 189 insertions(+), 95 deletions(-) diff --git a/packages/zowe-explorer/__tests__/__unit__/dataset/init.unit.test.ts b/packages/zowe-explorer/__tests__/__unit__/dataset/init.unit.test.ts index bacbe6f822..297a96ea7d 100644 --- a/packages/zowe-explorer/__tests__/__unit__/dataset/init.unit.test.ts +++ b/packages/zowe-explorer/__tests__/__unit__/dataset/init.unit.test.ts @@ -156,7 +156,7 @@ describe("Test src/dataset/extension", () => { }, { name: "zowe.ds.submitJcl", - mock: [{ spy: jest.spyOn(dsActions, "submitJcl"), arg: [dsProvider] }], + mock: [{ spy: jest.spyOn(dsActions, "submitJcl"), arg: [dsProvider, test.value] }], }, { name: "zowe.ds.submitMember", diff --git a/packages/zowe-explorer/__tests__/__unit__/job/actions.unit.test.ts b/packages/zowe-explorer/__tests__/__unit__/job/actions.unit.test.ts index ad589fd9e2..3f99de5765 100644 --- a/packages/zowe-explorer/__tests__/__unit__/job/actions.unit.test.ts +++ b/packages/zowe-explorer/__tests__/__unit__/job/actions.unit.test.ts @@ -46,6 +46,34 @@ import { ZosJobsProvider } from "../../../src/job/ZosJobsProvider"; const activeTextEditorDocument = jest.fn(); function createGlobalMocks() { + const newMocks = { + JobNode1: new Job( + "testProfile", + vscode.TreeItemCollapsibleState.None, + null as any, + createISession(), + settingJobObjects(createIJobObject(), "ZOWEUSR1", "JOB045123", "ABEND S222"), + createIProfile() + ), + JobNode2: new Job( + "testProfile", + vscode.TreeItemCollapsibleState.None, + null as any, + createISession(), + settingJobObjects(createIJobObject(), "ZOWEUSR1", "JOB045120", "CC 0000"), + createIProfile() + ), + JobNode3: new Job( + "testProfile", + vscode.TreeItemCollapsibleState.None, + null as any, + createISession(), + settingJobObjects(createIJobObject(), "ZOWEUSR2", "JOB045125", "CC 0000"), + createIProfile() + ), + mockJobArray: [], + }; + newMocks.mockJobArray = [newMocks.JobNode1, newMocks.JobNode2, newMocks.JobNode3] as any; Object.defineProperty(vscode.workspace, "getConfiguration", { value: jest.fn().mockImplementation(() => new Map([["zowe.jobs.confirmSubmission", false]])), configurable: true, @@ -93,41 +121,7 @@ function createGlobalMocks() { job.retcode = setjobreturncode; return job; } - const newMocks = jest.fn().mockReturnValue([ - (() => { - const JobNode1 = new Job( - "testProfile", - vscode.TreeItemCollapsibleState.None, - null, - createISession(), - settingJobObjects(createIJobObject(), "ZOWEUSR1", "JOB045123", "ABEND S222"), - createIProfile() - ); - return JobNode1; - })(), - (() => { - const JobNode2 = new Job( - "testProfile", - vscode.TreeItemCollapsibleState.None, - null, - createISession(), - settingJobObjects(createIJobObject(), "ZOWEUSR1", "JOB045120", "CC 0000"), - createIProfile() - ); - return JobNode2; - })(), - (() => { - const JobNode3 = new Job( - "testProfile", - vscode.TreeItemCollapsibleState.None, - null, - createISession(), - settingJobObjects(createIJobObject(), "ZOWEUSR2", "JOB045125", "CC 0000"), - createIProfile() - ); - return JobNode3; - })(), - ]); + return newMocks; } @@ -157,7 +151,7 @@ describe("Jobs Actions Unit Tests - Function setPrefix", () => { it("Checking that the prefix is set correctly on the job", async () => { createGlobalMocks(); const blockMocks = createBlockMocks(); - const node = new Job("job", vscode.TreeItemCollapsibleState.None, null, blockMocks.session, null, null); + const node = new Job("job", vscode.TreeItemCollapsibleState.None, null as any, blockMocks.session, null as any, null as any); const mySpy = mocked(vscode.window.showInputBox).mockResolvedValue("*"); await jobActions.setPrefix(node, blockMocks.testJobsTree); @@ -192,7 +186,14 @@ describe("Jobs Actions Unit Tests - Function setOwner", () => { it("Checking that the owner is set correctly on the job", async () => { createGlobalMocks(); const blockMocks = createBlockMocks(); - const node = new Job("job", vscode.TreeItemCollapsibleState.None, null, blockMocks.session, blockMocks.iJob, blockMocks.imperativeProfile); + const node = new Job( + "job", + vscode.TreeItemCollapsibleState.None, + null as any, + blockMocks.session, + blockMocks.iJob, + blockMocks.imperativeProfile + ); const mySpy = mocked(vscode.window.showInputBox).mockResolvedValue("OWNER"); await jobActions.setOwner(node, blockMocks.testJobsTree); @@ -224,7 +225,14 @@ describe("Jobs Actions Unit Tests - Function stopCommand", () => { it("Checking that stop command of Job Node is executed properly", async () => { createGlobalMocks(); const blockMocks = createBlockMocks(); - const node = new Job("job", vscode.TreeItemCollapsibleState.None, null, blockMocks.session, blockMocks.iJob, blockMocks.imperativeProfile); + const node = new Job( + "job", + vscode.TreeItemCollapsibleState.None, + null as any, + blockMocks.session, + blockMocks.iJob, + blockMocks.imperativeProfile + ); mocked(zowe.IssueCommand.issueSimple).mockResolvedValueOnce({ success: false, @@ -238,7 +246,14 @@ describe("Jobs Actions Unit Tests - Function stopCommand", () => { it("Checking failed attempt to issue stop command for Job Node.", async () => { createGlobalMocks(); const blockMocks = createBlockMocks(); - const node = new Job("job", vscode.TreeItemCollapsibleState.None, null, blockMocks.session, undefined, blockMocks.imperativeProfile); + const node = new Job( + "job", + vscode.TreeItemCollapsibleState.None, + null as any, + blockMocks.session, + undefined as any, + blockMocks.imperativeProfile + ); mocked(zowe.IssueCommand.issueSimple).mockResolvedValueOnce({ success: false, zosmfResponse: [], @@ -265,7 +280,14 @@ describe("Jobs Actions Unit Tests - Function modifyCommand", () => { it("Checking modification of Job Node", async () => { createGlobalMocks(); const blockMocks = createBlockMocks(); - const node = new Job("job", vscode.TreeItemCollapsibleState.None, null, blockMocks.session, blockMocks.iJob, blockMocks.imperativeProfile); + const node = new Job( + "job", + vscode.TreeItemCollapsibleState.None, + null as any, + blockMocks.session, + blockMocks.iJob, + blockMocks.imperativeProfile + ); mocked(vscode.window.showInputBox).mockResolvedValue("modify"); mocked(zowe.IssueCommand.issueSimple).mockResolvedValueOnce({ @@ -280,7 +302,14 @@ describe("Jobs Actions Unit Tests - Function modifyCommand", () => { it("Checking failed attempt to modify Job Node", async () => { createGlobalMocks(); const blockMocks = createBlockMocks(); - const node = new Job("job", vscode.TreeItemCollapsibleState.None, null, blockMocks.session, undefined, blockMocks.imperativeProfile); + const node = new Job( + "job", + vscode.TreeItemCollapsibleState.None, + null as any, + blockMocks.session, + undefined as any, + blockMocks.imperativeProfile + ); mocked(vscode.window.showInputBox).mockResolvedValue("modify"); mocked(zowe.IssueCommand.issueSimple).mockResolvedValueOnce({ success: false, @@ -312,7 +341,14 @@ describe("Jobs Actions Unit Tests - Function downloadSpool", () => { createGlobalMocks(); const blockMocks = createBlockMocks(); const jobs: Job[] = []; - const node = new Job("job", vscode.TreeItemCollapsibleState.None, null, blockMocks.session, blockMocks.iJob, blockMocks.imperativeProfile); + const node = new Job( + "job", + vscode.TreeItemCollapsibleState.None, + null as any, + blockMocks.session, + blockMocks.iJob, + blockMocks.imperativeProfile + ); const fileUri = { fsPath: "/tmp/foo", scheme: "", @@ -346,7 +382,7 @@ describe("Jobs Actions Unit Tests - Function downloadSpool", () => { query: "", }; mocked(Gui.showOpenDialog).mockResolvedValue([fileUri as vscode.Uri]); - await jobActions.downloadSpool(undefined); + await jobActions.downloadSpool(undefined as any); expect(mocked(Gui.errorMessage).mock.calls.length).toBe(1); }); }); @@ -375,7 +411,7 @@ describe("Jobs Actions Unit Tests - Function downloadSingleSpool", () => { const node = new Job( "test:dd - 1", vscode.TreeItemCollapsibleState.None, - null, + null as any, blockMocks.session, blockMocks.iJob, blockMocks.imperativeProfile @@ -413,7 +449,7 @@ describe("Jobs Actions Unit Tests - Function downloadSingleSpool", () => { const node = new Job( "test:dd - 1", vscode.TreeItemCollapsibleState.None, - null, + null as any, blockMocks.session, blockMocks.iJob, blockMocks.imperativeProfile @@ -456,7 +492,14 @@ describe("Jobs Actions Unit Tests - Function downloadJcl", () => { it("Checking download of Job JCL", async () => { createGlobalMocks(); const blockMocks = createBlockMocks(); - const node = new Job("job", vscode.TreeItemCollapsibleState.None, null, blockMocks.session, blockMocks.iJob, blockMocks.imperativeProfile); + const node = new Job( + "job", + vscode.TreeItemCollapsibleState.None, + null as any, + blockMocks.session, + blockMocks.iJob, + blockMocks.imperativeProfile + ); await jobActions.downloadJcl(node); expect(mocked(zowe.GetJobs.getJclForJob)).toBeCalled(); expect(mocked(vscode.workspace.openTextDocument)).toBeCalled(); @@ -465,7 +508,7 @@ describe("Jobs Actions Unit Tests - Function downloadJcl", () => { it("Checking failed attempt to download Job JCL", async () => { createGlobalMocks(); const blockMocks = createBlockMocks(); - await jobActions.downloadJcl(undefined); + await jobActions.downloadJcl(undefined as any); expect(mocked(Gui.errorMessage)).toBeCalled(); }); }); @@ -478,15 +521,17 @@ describe("Jobs Actions Unit Tests - Function submitJcl", () => { const imperativeProfile = createIProfile(); const datasetSessionNode = createDatasetSessionNode(session, imperativeProfile); const textDocument = createTextDocument("HLQ.TEST.AFILE(mem)", datasetSessionNode); + (textDocument.languageId as any) = "jcl"; const profileInstance = createInstanceOfProfile(imperativeProfile); const jesApi = createJesApi(imperativeProfile); const mockCheckCurrentProfile = jest.fn(); bindJesApi(jesApi); - Object.defineProperty(profileInstance, "loadNamedProfile", { value: jest.fn(), + configurable: true, }); - (textDocument.languageId as any) = "jcl"; + const errorGuiMsgSpy = jest.spyOn(Gui, "errorMessage"); + const errorLogSpy = jest.spyOn(ZoweLogger, "error"); return { session, @@ -499,6 +544,8 @@ describe("Jobs Actions Unit Tests - Function submitJcl", () => { profileInstance, jesApi, mockCheckCurrentProfile, + errorLogSpy, + errorGuiMsgSpy, }; } @@ -513,14 +560,14 @@ describe("Jobs Actions Unit Tests - Function submitJcl", () => { }) ); blockMocks.testDatasetTree.getChildren.mockResolvedValueOnce([ - new ZoweDatasetNode("node", vscode.TreeItemCollapsibleState.None, blockMocks.datasetSessionNode, null), + new ZoweDatasetNode("node", vscode.TreeItemCollapsibleState.None, blockMocks.datasetSessionNode, null as any), blockMocks.datasetSessionNode, ]); activeTextEditorDocument.mockReturnValue(blockMocks.textDocument); const submitJclSpy = jest.spyOn(blockMocks.jesApi, "submitJcl"); submitJclSpy.mockClear(); submitJclSpy.mockResolvedValueOnce(blockMocks.iJob); - await dsActions.submitJcl(blockMocks.testDatasetTree); + await dsActions.submitJcl(blockMocks.testDatasetTree, undefined); expect(submitJclSpy).toBeCalled(); expect(mocked(Gui.showMessage)).toBeCalled(); @@ -541,14 +588,14 @@ describe("Jobs Actions Unit Tests - Function submitJcl", () => { }) ); blockMocks.testDatasetTree.getChildren.mockResolvedValueOnce([ - new ZoweDatasetNode("node", vscode.TreeItemCollapsibleState.None, blockMocks.datasetSessionNode, null), + new ZoweDatasetNode("node", vscode.TreeItemCollapsibleState.None, blockMocks.datasetSessionNode, null as any), blockMocks.datasetSessionNode, ]); activeTextEditorDocument.mockReturnValue(blockMocks.textDocument); const submitJclSpy = jest.spyOn(blockMocks.jesApi, "submitJcl"); submitJclSpy.mockClear(); submitJclSpy.mockResolvedValueOnce(blockMocks.iJob); - await dsActions.submitJcl(blockMocks.testDatasetTree); + await dsActions.submitJcl(blockMocks.testDatasetTree, undefined); expect(submitJclSpy).toBeCalled(); expect(mocked(Gui.showMessage)).toBeCalled(); @@ -557,6 +604,42 @@ describe("Jobs Actions Unit Tests - Function submitJcl", () => { "Job submitted [JOB1234](command:zowe.jobs.setJobSpool?%5B%22sestest%22%2C%22JOB1234%22%5D)" ); }); + it("Checking failure of submitting of active text editor content not JCL", async () => { + createGlobalMocks(); + const blockMocks: any = createBlockMocks(); + mocked(zowe.ZosmfSession.createSessCfgFromArgs).mockReturnValue(blockMocks.session); + mocked(Profiles.getInstance).mockReturnValue(blockMocks.profileInstance); + mocked(vscode.window.showQuickPick).mockReturnValueOnce( + new Promise((resolve) => { + resolve(blockMocks.datasetSessionNode.label); + }) + ); + blockMocks.testDatasetTree.getChildren.mockResolvedValueOnce([ + new ZoweDatasetNode("node", vscode.TreeItemCollapsibleState.None, blockMocks.datasetSessionNode, null as any), + blockMocks.datasetSessionNode, + ]); + activeTextEditorDocument.mockReturnValue(blockMocks.textDocument); + (blockMocks.textDocument.languageId as string) = "java"; + await dsActions.submitJcl(blockMocks.testDatasetTree, undefined); + + const errorMsg = "The document being submitted is not a JCL, submission cancelled."; + expect(blockMocks.errorLogSpy).toBeCalledWith(errorMsg); + expect(blockMocks.errorGuiMsgSpy).toBeCalledWith(errorMsg); + }); + // it("Checking failure of submitting JCL via command palette if not active text editor", async () => { + // createGlobalMocks(); + // Object.defineProperty(vscode.workspace, "activeTextEditor", { + // value: jest.fn().mockReturnValue(undefined), + // configurable: true, + // }); + // const blockMocks = createBlockMocks(); + + // await dsActions.submitJcl(blockMocks.testDatasetTree, undefined); + + // const errorMsg = "No editor with a document that could be submitted as JCL is currently open."; + // expect(blockMocks.errorLogSpy).toBeCalledWith(errorMsg); + // expect(blockMocks.errorGuiMsgSpy).toBeCalledWith(errorMsg); + // }); it("Checking failed attempt to submit of active text editor content as JCL without profile chosen from quickpick", async () => { createGlobalMocks(); @@ -565,7 +648,7 @@ describe("Jobs Actions Unit Tests - Function submitJcl", () => { mocked(Profiles.getInstance).mockReturnValue(blockMocks.profileInstance); mocked(vscode.window.showQuickPick).mockResolvedValueOnce(undefined); // Here we imitate the case when no profile was selected blockMocks.testDatasetTree.getChildren.mockResolvedValueOnce([ - new ZoweDatasetNode("node", vscode.TreeItemCollapsibleState.None, blockMocks.datasetSessionNode, null), + new ZoweDatasetNode("node", vscode.TreeItemCollapsibleState.None, blockMocks.datasetSessionNode, null as any), blockMocks.datasetSessionNode, ]); activeTextEditorDocument.mockReturnValue(blockMocks.textDocument); @@ -573,7 +656,7 @@ describe("Jobs Actions Unit Tests - Function submitJcl", () => { const submitJclSpy = jest.spyOn(blockMocks.jesApi, "submitJcl"); submitJclSpy.mockClear(); - await dsActions.submitJcl(blockMocks.testDatasetTree); + await dsActions.submitJcl(blockMocks.testDatasetTree, undefined); expect(submitJclSpy).not.toBeCalled(); expect(messageSpy).toBeCalledWith("Operation Cancelled"); @@ -590,7 +673,7 @@ describe("Jobs Actions Unit Tests - Function submitJcl", () => { }) ); blockMocks.testDatasetTree.getChildren.mockResolvedValueOnce([ - new ZoweDatasetNode("node", vscode.TreeItemCollapsibleState.None, blockMocks.datasetSessionNode, null), + new ZoweDatasetNode("node", vscode.TreeItemCollapsibleState.None, blockMocks.datasetSessionNode, null as any), blockMocks.datasetSessionNode, ]); activeTextEditorDocument.mockReturnValue(blockMocks.textDocument); @@ -598,7 +681,7 @@ describe("Jobs Actions Unit Tests - Function submitJcl", () => { submitJclSpy.mockClear(); const testError = new Error("submitJcl failed"); submitJclSpy.mockRejectedValueOnce(testError); - await dsActions.submitJcl(blockMocks.testDatasetTree); + await dsActions.submitJcl(blockMocks.testDatasetTree, undefined); expect(submitJclSpy).toBeCalled(); expect(mocked(Gui.errorMessage)).toBeCalled(); @@ -632,9 +715,9 @@ describe("Jobs Actions Unit Tests - Function submitMember", () => { createGlobalMocks(); const blockMocks = createBlockMocks(); mocked(Profiles.getInstance).mockReturnValue(blockMocks.profileInstance); - const subNode = new ZoweDatasetNode("dataset", vscode.TreeItemCollapsibleState.Collapsed, blockMocks.datasetSessionNode, null); + const subNode = new ZoweDatasetNode("dataset", vscode.TreeItemCollapsibleState.Collapsed, blockMocks.datasetSessionNode, null as any); subNode.contextValue = globals.DS_PDS_CONTEXT; - const member = new ZoweDatasetNode("member", vscode.TreeItemCollapsibleState.None, subNode, null); + const member = new ZoweDatasetNode("member", vscode.TreeItemCollapsibleState.None, subNode, null as any); member.contextValue = globals.DS_MEMBER_CONTEXT; const submitJobSpy = jest.spyOn(blockMocks.jesApi, "submitJob"); submitJobSpy.mockResolvedValueOnce(blockMocks.iJob); @@ -662,9 +745,9 @@ describe("Jobs Actions Unit Tests - Function submitMember", () => { }; }), }); - const subNode = new ZoweDatasetNode("dataset", vscode.TreeItemCollapsibleState.Collapsed, blockMocks.datasetSessionNode, null); + const subNode = new ZoweDatasetNode("dataset", vscode.TreeItemCollapsibleState.Collapsed, blockMocks.datasetSessionNode, null as any); subNode.contextValue = globals.DS_PDS_CONTEXT; - const member = new ZoweDatasetNode("member", vscode.TreeItemCollapsibleState.None, subNode, null); + const member = new ZoweDatasetNode("member", vscode.TreeItemCollapsibleState.None, subNode, null as any); member.contextValue = globals.DS_MEMBER_CONTEXT; const submitJobSpy = jest.spyOn(blockMocks.jesApi, "submitJob"); submitJobSpy.mockResolvedValueOnce(blockMocks.iJob); @@ -681,7 +764,7 @@ describe("Jobs Actions Unit Tests - Function submitMember", () => { createGlobalMocks(); const blockMocks = createBlockMocks(); mocked(Profiles.getInstance).mockReturnValue(blockMocks.profileInstance); - const dataset = new ZoweDatasetNode("dataset", vscode.TreeItemCollapsibleState.Collapsed, blockMocks.datasetSessionNode, null); + const dataset = new ZoweDatasetNode("dataset", vscode.TreeItemCollapsibleState.Collapsed, blockMocks.datasetSessionNode, null as any); dataset.contextValue = globals.DS_DS_CONTEXT; const submitJobSpy = jest.spyOn(blockMocks.jesApi, "submitJob"); submitJobSpy.mockClear(); @@ -699,11 +782,11 @@ describe("Jobs Actions Unit Tests - Function submitMember", () => { createGlobalMocks(); const blockMocks = createBlockMocks(); mocked(Profiles.getInstance).mockReturnValue(blockMocks.profileInstance); - const favProfileNode = new ZoweDatasetNode("test", vscode.TreeItemCollapsibleState.Collapsed, blockMocks.datasetSessionNode, null); + const favProfileNode = new ZoweDatasetNode("test", vscode.TreeItemCollapsibleState.Collapsed, blockMocks.datasetSessionNode, null as any); favProfileNode.contextValue = globals.FAV_PROFILE_CONTEXT; - const favoriteSubNode = new ZoweDatasetNode("TEST.JCL", vscode.TreeItemCollapsibleState.Collapsed, favProfileNode, null); + const favoriteSubNode = new ZoweDatasetNode("TEST.JCL", vscode.TreeItemCollapsibleState.Collapsed, favProfileNode, null as any); favoriteSubNode.contextValue = globals.DS_PDS_CONTEXT + globals.FAV_SUFFIX; - const favoriteMember = new ZoweDatasetNode(globals.DS_PDS_CONTEXT, vscode.TreeItemCollapsibleState.Collapsed, favoriteSubNode, null); + const favoriteMember = new ZoweDatasetNode(globals.DS_PDS_CONTEXT, vscode.TreeItemCollapsibleState.Collapsed, favoriteSubNode, null as any); favoriteMember.contextValue = globals.DS_MEMBER_CONTEXT; const submitJobSpy = jest.spyOn(blockMocks.jesApi, "submitJob"); submitJobSpy.mockClear(); @@ -721,9 +804,9 @@ describe("Jobs Actions Unit Tests - Function submitMember", () => { createGlobalMocks(); const blockMocks = createBlockMocks(); mocked(Profiles.getInstance).mockReturnValue(blockMocks.profileInstance); - const favProfileNode = new ZoweDatasetNode("test", vscode.TreeItemCollapsibleState.Collapsed, blockMocks.datasetSessionNode, null); + const favProfileNode = new ZoweDatasetNode("test", vscode.TreeItemCollapsibleState.Collapsed, blockMocks.datasetSessionNode, null as any); favProfileNode.contextValue = globals.FAV_PROFILE_CONTEXT; - const favoriteDataset = new ZoweDatasetNode("TEST.JCL", vscode.TreeItemCollapsibleState.Collapsed, favProfileNode, null); + const favoriteDataset = new ZoweDatasetNode("TEST.JCL", vscode.TreeItemCollapsibleState.Collapsed, favProfileNode, null as any); favoriteDataset.contextValue = globals.DS_DS_CONTEXT + globals.FAV_SUFFIX; const submitJobSpy = jest.spyOn(blockMocks.jesApi, "submitJob"); submitJobSpy.mockClear(); @@ -741,9 +824,9 @@ describe("Jobs Actions Unit Tests - Function submitMember", () => { createGlobalMocks(); const blockMocks = createBlockMocks(); mocked(Profiles.getInstance).mockReturnValue(blockMocks.profileInstance); - const corruptedNode = new ZoweDatasetNode("gibberish", vscode.TreeItemCollapsibleState.Collapsed, blockMocks.datasetSessionNode, null); + const corruptedNode = new ZoweDatasetNode("gibberish", vscode.TreeItemCollapsibleState.Collapsed, blockMocks.datasetSessionNode, null as any); corruptedNode.contextValue = "gibberish"; - const corruptedSubNode = new ZoweDatasetNode("gibberishmember", vscode.TreeItemCollapsibleState.Collapsed, corruptedNode, null); + const corruptedSubNode = new ZoweDatasetNode("gibberishmember", vscode.TreeItemCollapsibleState.Collapsed, corruptedNode, null as any); const submitJobSpy = jest.spyOn(blockMocks.jesApi, "submitJob"); submitJobSpy.mockClear(); submitJobSpy.mockResolvedValueOnce(blockMocks.iJob); @@ -764,7 +847,12 @@ describe("Jobs Actions Unit Tests - Function submitMember", () => { const blockMocks = createBlockMocks(); mocked(Profiles.getInstance).mockReturnValue(blockMocks.profileInstance); - const dataset = new ZoweDatasetNode("TESTUSER.DATASET", vscode.TreeItemCollapsibleState.Collapsed, blockMocks.datasetSessionNode, null); + const dataset = new ZoweDatasetNode( + "TESTUSER.DATASET", + vscode.TreeItemCollapsibleState.Collapsed, + blockMocks.datasetSessionNode, + null as any + ); dataset.contextValue = globals.DS_DS_CONTEXT; for (let o = 0; o < sharedUtils.JOB_SUBMIT_DIALOG_OPTS.length; o++) { @@ -801,7 +889,7 @@ describe("Jobs Actions Unit Tests - Function submitMember", () => { } // Test for "Cancel" or closing the dialog - mocked(Gui.warningMessage).mockReturnValueOnce(undefined); + mocked(Gui.warningMessage).mockReturnValueOnce(undefined as any); await dsActions.submitMember(dataset); expect(mocked(Gui.warningMessage)).toBeCalledWith("Are you sure you want to submit the following job?\n\n" + dataset.getLabel(), { items: [{ title: "Submit" }], @@ -933,7 +1021,7 @@ describe("Jobs Actions Unit Tests - Function getSpoolContent", () => { vscode.TreeItemCollapsibleState.None, createJobFavoritesNode(), createISessionWithoutCredentials(), - null, + null as any, createIProfile() ); jest.spyOn(Spool.prototype, "getProfile").mockReturnValue({ @@ -1086,7 +1174,7 @@ describe("Jobs Actions Unit Tests - Function refreshJobsServer", () => { const job = new Job( "jobtest", vscode.TreeItemCollapsibleState.Expanded, - null, + null as any, blockMocks.session, blockMocks.iJob, blockMocks.imperativeProfile @@ -1103,7 +1191,7 @@ describe("Jobs Actions Unit Tests - Function refreshJobsServer", () => { const job = new Job( "jobtest", vscode.TreeItemCollapsibleState.Expanded, - null, + null as any, blockMocks.session, blockMocks.iJob, blockMocks.imperativeProfile @@ -1239,7 +1327,7 @@ describe("job deletion command", () => { const jobsProvider = createJobsTree(session, job, profile, createTreeView()); jobsProvider.delete.mockResolvedValueOnce(Promise.resolve()); - const jobNode = new Job("jobtest", vscode.TreeItemCollapsibleState.Expanded, null, session, job, profile); + const jobNode = new Job("jobtest", vscode.TreeItemCollapsibleState.Expanded, null as any, session, job, profile); await jobActions.deleteCommand(jobsProvider, jobNode); @@ -1253,8 +1341,8 @@ describe("job deletion command", () => { const jobsProvider = createJobsTree(session, job, profile, createTreeView()); jobsProvider.mSessionNodes.push(job2); jobsProvider.delete.mockResolvedValue(Promise.resolve()); - const jobNode1 = new Job("jobtest1", vscode.TreeItemCollapsibleState.Expanded, null, session, job, profile); - const jobNode2 = new Job("jobtest2", vscode.TreeItemCollapsibleState.Expanded, null, session, job2, profile); + const jobNode1 = new Job("jobtest1", vscode.TreeItemCollapsibleState.Expanded, null as any, session, job, profile); + const jobNode2 = new Job("jobtest2", vscode.TreeItemCollapsibleState.Expanded, null as any, session, job2, profile); const jobs = [jobNode1, jobNode2]; // act await jobActions.deleteCommand(jobsProvider, undefined, jobs); @@ -1268,7 +1356,7 @@ describe("job deletion command", () => { const jobsProvider = createJobsTree(session, job, profile, createTreeView()); jobsProvider.delete.mockResolvedValueOnce(Promise.resolve()); - const jobNode = new Job("jobtest", vscode.TreeItemCollapsibleState.Expanded, null, session, job, profile); + const jobNode = new Job("jobtest", vscode.TreeItemCollapsibleState.Expanded, null as any, session, job, profile); await jobActions.deleteCommand(jobsProvider, jobNode); expect(mocked(jobsProvider.delete)).not.toBeCalled(); @@ -1279,7 +1367,7 @@ describe("job deletion command", () => { const jobsProvider = createJobsTree(session, job, profile, createTreeView()); jobsProvider.delete.mockResolvedValueOnce(Promise.reject(new Error("something went wrong!"))); - const jobNode = new Job("jobtest", vscode.TreeItemCollapsibleState.Expanded, null, session, job, profile); + const jobNode = new Job("jobtest", vscode.TreeItemCollapsibleState.Expanded, null as any, session, job, profile); // act await jobActions.deleteCommand(jobsProvider, jobNode); // assert @@ -1292,7 +1380,7 @@ describe("job deletion command", () => { const jobsProvider = createJobsTree(session, job, profile, createTreeView()); jobsProvider.delete.mockResolvedValueOnce(Promise.resolve()); - const jobNode = new Job("jobtest", vscode.TreeItemCollapsibleState.Expanded, null, session, job, profile); + const jobNode = new Job("jobtest", vscode.TreeItemCollapsibleState.Expanded, null as any, session, job, profile); jobsProvider.getTreeView.mockReturnValueOnce({ ...jobsProvider.getTreeView(), selection: [jobNode] }); // act await jobActions.deleteCommand(jobsProvider, undefined); @@ -1307,7 +1395,7 @@ describe("Job Actions Unit Tests - Misc. functions", () => { const session = createISession(); const profile = createIProfile(); const job = createIJobObject(); - const jobNode = new Job("job", vscode.TreeItemCollapsibleState.None, null, session, job, profile); + const jobNode = new Job("job", vscode.TreeItemCollapsibleState.None, null as any, session, job, profile); it("refreshJob works as intended", () => { const jobsProvider = createJobsTree(session, job, profile, createTreeView()); @@ -1363,8 +1451,8 @@ describe("sortjobsby function", () => { const globalMocks = createGlobalMocks(); const testtree = new ZosJobsProvider(); const expected = new ZosJobsProvider(); - testtree.mSessionNodes[0].children = [...[globalMocks()[2], globalMocks()[1], globalMocks()[0]]]; - expected.mSessionNodes[0].children = [...[globalMocks()[1], globalMocks()[0], globalMocks()[2]]]; + testtree.mSessionNodes[0].children = [...[globalMocks.mockJobArray[2], globalMocks.mockJobArray[1], globalMocks.mockJobArray[0]]]; + expected.mSessionNodes[0].children = [...[globalMocks.mockJobArray[1], globalMocks.mockJobArray[0], globalMocks.mockJobArray[2]]]; const sortbynamespy = jest.spyOn(jobActions, "sortJobsBy"); //act await jobActions.sortJobsBy(testtree.mSessionNodes[0], testtree, "jobname"); @@ -1377,8 +1465,8 @@ describe("sortjobsby function", () => { const globalMocks = createGlobalMocks(); const testtree = new ZosJobsProvider(); const expected = new ZosJobsProvider(); - testtree.mSessionNodes[0].children = [...[globalMocks()[2], globalMocks()[1], globalMocks()[0]]]; - expected.mSessionNodes[0].children = [...[globalMocks()[1], globalMocks()[0], globalMocks()[2]]]; + testtree.mSessionNodes[0].children = [...[globalMocks.mockJobArray[2], globalMocks.mockJobArray[1], globalMocks.mockJobArray[0]]]; + expected.mSessionNodes[0].children = [...[globalMocks.mockJobArray[1], globalMocks.mockJobArray[0], globalMocks.mockJobArray[2]]]; const sortbyidspy = jest.spyOn(jobActions, "sortJobsBy"); //act await jobActions.sortJobsBy(testtree.mSessionNodes[0], testtree, "jobid"); @@ -1391,8 +1479,8 @@ describe("sortjobsby function", () => { const globalMocks = createGlobalMocks(); const testtree = new ZosJobsProvider(); const expected = new ZosJobsProvider(); - testtree.mSessionNodes[0].children = [...[globalMocks()[2], globalMocks()[1], globalMocks()[0]]]; - expected.mSessionNodes[0].children = [...[globalMocks()[0], globalMocks()[1], globalMocks()[2]]]; + testtree.mSessionNodes[0].children = [...[globalMocks.mockJobArray[2], globalMocks.mockJobArray[1], globalMocks.mockJobArray[0]]]; + expected.mSessionNodes[0].children = [...[globalMocks.mockJobArray[0], globalMocks.mockJobArray[1], globalMocks.mockJobArray[2]]]; const sortbyretcodespy = jest.spyOn(jobActions, "sortJobsBy"); //act await jobActions.sortJobsBy(testtree.mSessionNodes[0], testtree, "retcode"); diff --git a/packages/zowe-explorer/package.json b/packages/zowe-explorer/package.json index b79b9c3b1d..e4d81203f0 100644 --- a/packages/zowe-explorer/package.json +++ b/packages/zowe-explorer/package.json @@ -824,14 +824,14 @@ ], "editor/context": [ { - "when": "resourceLangId == jcl", + "when": "resourceLangId =~ /^.*jcl.*/i", "command": "zowe.ds.submitJcl", "group": "000_zowe_dsMainframeInteraction@1" } ], "explorer/context": [ { - "when": "resourceLangId == jcl", + "when": "resourceLangId =~ /^.*jcl.*/i", "command": "zowe.ds.submitJcl", "group": "000_zowe_dsMainframeInteraction@1" } diff --git a/packages/zowe-explorer/src/dataset/actions.ts b/packages/zowe-explorer/src/dataset/actions.ts index aa7d712e40..d555694ead 100644 --- a/packages/zowe-explorer/src/dataset/actions.ts +++ b/packages/zowe-explorer/src/dataset/actions.ts @@ -967,15 +967,15 @@ export async function showAttributes(node: api.IZoweDatasetTreeNode, datasetProv } /** - * Submit the contents of the editor as JCL. + * Submit the contents of the editor or file as JCL. * * @export * @param {DatasetTree} datasetProvider - our DatasetTree object */ // This function does not appear to currently be made available in the UI -export async function submitJcl(datasetProvider: api.IZoweTree): Promise { +export async function submitJcl(datasetProvider: api.IZoweTree, file?: vscode.Uri): Promise { ZoweLogger.trace("dataset.actions.submitJcl called."); - if (!vscode.window.activeTextEditor) { + if (!vscode.window.activeTextEditor && !file) { const notActiveEditorMsg = localize( "submitJcl.notActiveEditorMsg", "No editor with a document that could be submitted as JCL is currently open." @@ -984,8 +984,14 @@ export async function submitJcl(datasetProvider: api.IZoweTree datasetProvider.removeFavProfile(node.label, true)) ); - context.subscriptions.push(vscode.commands.registerCommand("zowe.ds.submitJcl", async () => dsActions.submitJcl(datasetProvider))); + context.subscriptions.push(vscode.commands.registerCommand("zowe.ds.submitJcl", async (file) => dsActions.submitJcl(datasetProvider, file))); context.subscriptions.push(vscode.commands.registerCommand("zowe.ds.submitMember", async (node) => dsActions.submitMember(node))); context.subscriptions.push( vscode.commands.registerCommand("zowe.ds.showAttributes", async (node, nodeList) => { From fb9eb13c85147a1700d3fe4d387b8fdd49c4a1ce Mon Sep 17 00:00:00 2001 From: Billie Simmons <49491949+JillieBeanSim@users.noreply.github.com> Date: Wed, 11 Oct 2023 15:53:01 -0400 Subject: [PATCH 07/11] clean up some duplication in test file Signed-off-by: Billie Simmons <49491949+JillieBeanSim@users.noreply.github.com> --- .../__unit__/job/actions.unit.test.ts | 139 +++--------------- 1 file changed, 20 insertions(+), 119 deletions(-) diff --git a/packages/zowe-explorer/__tests__/__unit__/job/actions.unit.test.ts b/packages/zowe-explorer/__tests__/__unit__/job/actions.unit.test.ts index 3f99de5765..5ec985c41f 100644 --- a/packages/zowe-explorer/__tests__/__unit__/job/actions.unit.test.ts +++ b/packages/zowe-explorer/__tests__/__unit__/job/actions.unit.test.ts @@ -11,7 +11,7 @@ import * as vscode from "vscode"; import * as zowe from "@zowe/cli"; -import { Gui, IZoweJobTreeNode, ValidProfileEnum } from "@zowe/zowe-explorer-api"; +import { Gui, IZoweJobTreeNode, IZoweTree, ValidProfileEnum } from "@zowe/zowe-explorer-api"; import { Job, Spool } from "../../../src/job/ZoweJobNode"; import { createISession, @@ -47,6 +47,10 @@ const activeTextEditorDocument = jest.fn(); function createGlobalMocks() { const newMocks = { + session: createISession(), + treeView: createTreeView(), + iJob: createIJobObject(), + imperativeProfile: createIProfile(), JobNode1: new Job( "testProfile", vscode.TreeItemCollapsibleState.None, @@ -72,8 +76,13 @@ function createGlobalMocks() { createIProfile() ), mockJobArray: [], + testJobsTree: null as any, + jesApi: null as any, }; + newMocks.testJobsTree = createJobsTree(newMocks.session, newMocks.iJob, newMocks.imperativeProfile, newMocks.treeView); newMocks.mockJobArray = [newMocks.JobNode1, newMocks.JobNode2, newMocks.JobNode3] as any; + newMocks.jesApi = createJesApi(newMocks.imperativeProfile); + bindJesApi(newMocks.jesApi); Object.defineProperty(vscode.workspace, "getConfiguration", { value: jest.fn().mockImplementation(() => new Map([["zowe.jobs.confirmSubmission", false]])), configurable: true, @@ -133,24 +142,8 @@ afterEach(() => { }); describe("Jobs Actions Unit Tests - Function setPrefix", () => { - function createBlockMocks() { - const session = createISession(); - const treeView = createTreeView(); - const iJob = createIJobObject(); - const imperativeProfile = createIProfile(); - - return { - session, - treeView, - iJob, - imperativeProfile, - testJobsTree: createJobsTree(session, iJob, imperativeProfile, treeView), - }; - } - it("Checking that the prefix is set correctly on the job", async () => { - createGlobalMocks(); - const blockMocks = createBlockMocks(); + const blockMocks = createGlobalMocks(); const node = new Job("job", vscode.TreeItemCollapsibleState.None, null as any, blockMocks.session, null as any, null as any); const mySpy = mocked(vscode.window.showInputBox).mockResolvedValue("*"); @@ -168,24 +161,8 @@ describe("Jobs Actions Unit Tests - Function setPrefix", () => { }); describe("Jobs Actions Unit Tests - Function setOwner", () => { - function createBlockMocks() { - const session = createISession(); - const treeView = createTreeView(); - const iJob = createIJobObject(); - const imperativeProfile = createIProfile(); - - return { - session, - treeView, - iJob, - imperativeProfile, - testJobsTree: createJobsTree(session, iJob, imperativeProfile, treeView), - }; - } - it("Checking that the owner is set correctly on the job", async () => { - createGlobalMocks(); - const blockMocks = createBlockMocks(); + const blockMocks = createGlobalMocks(); const node = new Job( "job", vscode.TreeItemCollapsibleState.None, @@ -210,21 +187,8 @@ describe("Jobs Actions Unit Tests - Function setOwner", () => { }); describe("Jobs Actions Unit Tests - Function stopCommand", () => { - function createBlockMocks() { - const session = createISession(); - const iJob = createIJobObject(); - const imperativeProfile = createIProfile(); - - return { - session, - iJob, - imperativeProfile, - }; - } - it("Checking that stop command of Job Node is executed properly", async () => { - createGlobalMocks(); - const blockMocks = createBlockMocks(); + const blockMocks = createGlobalMocks(); const node = new Job( "job", vscode.TreeItemCollapsibleState.None, @@ -244,8 +208,7 @@ describe("Jobs Actions Unit Tests - Function stopCommand", () => { expect(mocked(Gui.showMessage).mock.calls[0][0]).toEqual("Command response: fake response"); }); it("Checking failed attempt to issue stop command for Job Node.", async () => { - createGlobalMocks(); - const blockMocks = createBlockMocks(); + const blockMocks = createGlobalMocks(); const node = new Job( "job", vscode.TreeItemCollapsibleState.None, @@ -265,21 +228,8 @@ describe("Jobs Actions Unit Tests - Function stopCommand", () => { }); describe("Jobs Actions Unit Tests - Function modifyCommand", () => { - function createBlockMocks() { - const session = createISession(); - const iJob = createIJobObject(); - const imperativeProfile = createIProfile(); - - return { - session, - iJob, - imperativeProfile, - }; - } - it("Checking modification of Job Node", async () => { - createGlobalMocks(); - const blockMocks = createBlockMocks(); + const blockMocks = createGlobalMocks(); const node = new Job( "job", vscode.TreeItemCollapsibleState.None, @@ -300,8 +250,7 @@ describe("Jobs Actions Unit Tests - Function modifyCommand", () => { expect(mocked(Gui.showMessage).mock.calls[0][0]).toEqual("Command response: fake response"); }); it("Checking failed attempt to modify Job Node", async () => { - createGlobalMocks(); - const blockMocks = createBlockMocks(); + const blockMocks = createGlobalMocks(); const node = new Job( "job", vscode.TreeItemCollapsibleState.None, @@ -322,24 +271,8 @@ describe("Jobs Actions Unit Tests - Function modifyCommand", () => { }); describe("Jobs Actions Unit Tests - Function downloadSpool", () => { - function createBlockMocks() { - const session = createISession(); - const iJob = createIJobObject(); - const imperativeProfile = createIProfile(); - const jesApi = createJesApi(imperativeProfile); - bindJesApi(jesApi); - - return { - session, - iJob, - imperativeProfile, - jesApi, - }; - } - it("Checking download of Job Spool", async () => { - createGlobalMocks(); - const blockMocks = createBlockMocks(); + const blockMocks = createGlobalMocks(); const jobs: Job[] = []; const node = new Job( "job", @@ -372,7 +305,6 @@ describe("Jobs Actions Unit Tests - Function downloadSpool", () => { }); it("Checking failed attempt to download Job Spool", async () => { createGlobalMocks(); - const blockMocks = createBlockMocks(); const fileUri = { fsPath: "/tmp/foo", scheme: "", @@ -388,24 +320,8 @@ describe("Jobs Actions Unit Tests - Function downloadSpool", () => { }); describe("Jobs Actions Unit Tests - Function downloadSingleSpool", () => { - function createBlockMocks() { - const session = createISession(); - const iJob = createIJobObject(); - const imperativeProfile = createIProfile(); - const jesApi = createJesApi(imperativeProfile); - bindJesApi(jesApi); - - return { - session, - iJob, - imperativeProfile, - jesApi, - }; - } - it("Checking download of Job Spool", async () => { - createGlobalMocks(); - const blockMocks = createBlockMocks(); + const blockMocks = createGlobalMocks(); const iJobFile = createIJobFile(); const jobs: Job[] = []; const node = new Job( @@ -442,8 +358,7 @@ describe("Jobs Actions Unit Tests - Function downloadSingleSpool", () => { }); it("should fail to download single spool files if the extender has not implemented the operation", async () => { - createGlobalMocks(); - const blockMocks = createBlockMocks(); + const blockMocks = createGlobalMocks(); const iJobFile = createIJobFile(); const jobs: Job[] = []; const node = new Job( @@ -477,21 +392,8 @@ describe("Jobs Actions Unit Tests - Function downloadSingleSpool", () => { }); describe("Jobs Actions Unit Tests - Function downloadJcl", () => { - function createBlockMocks() { - const session = createISession(); - const iJob = createIJobObject(); - const imperativeProfile = createIProfile(); - - return { - session, - iJob, - imperativeProfile, - }; - } - it("Checking download of Job JCL", async () => { - createGlobalMocks(); - const blockMocks = createBlockMocks(); + const blockMocks = createGlobalMocks(); const node = new Job( "job", vscode.TreeItemCollapsibleState.None, @@ -507,7 +409,6 @@ describe("Jobs Actions Unit Tests - Function downloadJcl", () => { }); it("Checking failed attempt to download Job JCL", async () => { createGlobalMocks(); - const blockMocks = createBlockMocks(); await jobActions.downloadJcl(undefined as any); expect(mocked(Gui.errorMessage)).toBeCalled(); }); From 0838214229a50d2e0cd892346de9ccefb8a777e7 Mon Sep 17 00:00:00 2001 From: Billie Simmons <49491949+JillieBeanSim@users.noreply.github.com> Date: Tue, 17 Oct 2023 14:34:24 -0400 Subject: [PATCH 08/11] add coverage Signed-off-by: Billie Simmons <49491949+JillieBeanSim@users.noreply.github.com> --- .../__unit__/job/actions.unit.test.ts | 63 ++++++++++++++----- 1 file changed, 48 insertions(+), 15 deletions(-) diff --git a/packages/zowe-explorer/__tests__/__unit__/job/actions.unit.test.ts b/packages/zowe-explorer/__tests__/__unit__/job/actions.unit.test.ts index 5ec985c41f..262b6b2d46 100644 --- a/packages/zowe-explorer/__tests__/__unit__/job/actions.unit.test.ts +++ b/packages/zowe-explorer/__tests__/__unit__/job/actions.unit.test.ts @@ -11,7 +11,7 @@ import * as vscode from "vscode"; import * as zowe from "@zowe/cli"; -import { Gui, IZoweJobTreeNode, IZoweTree, ValidProfileEnum } from "@zowe/zowe-explorer-api"; +import { Gui, IZoweJobTreeNode, ValidProfileEnum } from "@zowe/zowe-explorer-api"; import { Job, Spool } from "../../../src/job/ZoweJobNode"; import { createISession, @@ -451,6 +451,39 @@ describe("Jobs Actions Unit Tests - Function submitJcl", () => { } it("Checking submit of active text editor content as JCL", async () => { + createGlobalMocks(); + const blockMocks: any = createBlockMocks(); + mocked(zowe.ZosmfSession.createSessCfgFromArgs).mockReturnValue(blockMocks.session); + mocked(Profiles.getInstance).mockReturnValue(blockMocks.profileInstance); + mocked(vscode.window.showQuickPick).mockReturnValueOnce( + new Promise((resolve) => { + resolve(blockMocks.datasetSessionNode.label); + }) + ); + const mockFile = { + path: "/fake/path/file.txt", + } as vscode.Uri; + blockMocks.testDatasetTree.getChildren.mockResolvedValueOnce([ + new ZoweDatasetNode("node", vscode.TreeItemCollapsibleState.None, blockMocks.datasetSessionNode, null as any), + blockMocks.datasetSessionNode, + ]); + const commandSpy = jest.spyOn(vscode.commands, "executeCommand"); + activeTextEditorDocument.mockReturnValue(blockMocks.textDocument); + const submitJclSpy = jest.spyOn(blockMocks.jesApi, "submitJcl"); + submitJclSpy.mockClear(); + submitJclSpy.mockResolvedValueOnce(blockMocks.iJob); + await dsActions.submitJcl(blockMocks.testDatasetTree, mockFile); + + expect(commandSpy).toBeCalled(); + expect(submitJclSpy).toBeCalled(); + expect(mocked(Gui.showMessage)).toBeCalled(); + expect(mocked(Gui.showMessage).mock.calls.length).toBe(1); + expect(mocked(Gui.showMessage).mock.calls[0][0]).toEqual( + "Job submitted [JOB1234](command:zowe.jobs.setJobSpool?%5B%22sestest%22%2C%22JOB1234%22%5D)" + ); + commandSpy.mockClear(); + }); + it("Checking submit of JCL file from VSC explorer tree", async () => { createGlobalMocks(); const blockMocks: any = createBlockMocks(); mocked(zowe.ZosmfSession.createSessCfgFromArgs).mockReturnValue(blockMocks.session); @@ -527,20 +560,20 @@ describe("Jobs Actions Unit Tests - Function submitJcl", () => { expect(blockMocks.errorLogSpy).toBeCalledWith(errorMsg); expect(blockMocks.errorGuiMsgSpy).toBeCalledWith(errorMsg); }); - // it("Checking failure of submitting JCL via command palette if not active text editor", async () => { - // createGlobalMocks(); - // Object.defineProperty(vscode.workspace, "activeTextEditor", { - // value: jest.fn().mockReturnValue(undefined), - // configurable: true, - // }); - // const blockMocks = createBlockMocks(); - - // await dsActions.submitJcl(blockMocks.testDatasetTree, undefined); - - // const errorMsg = "No editor with a document that could be submitted as JCL is currently open."; - // expect(blockMocks.errorLogSpy).toBeCalledWith(errorMsg); - // expect(blockMocks.errorGuiMsgSpy).toBeCalledWith(errorMsg); - // }); + it("Checking failure of submitting JCL via command palette if not active text editor", async () => { + createGlobalMocks(); + const blockMocks = createBlockMocks(); + Object.defineProperty(vscode.window, "activeTextEditor", { + value: undefined, + configurable: true, + }); + + await dsActions.submitJcl(blockMocks.testDatasetTree, undefined); + + const errorMsg = "No editor with a document that could be submitted as JCL is currently open."; + expect(blockMocks.errorLogSpy).toBeCalledWith(errorMsg); + expect(blockMocks.errorGuiMsgSpy).toBeCalledWith(errorMsg); + }); it("Checking failed attempt to submit of active text editor content as JCL without profile chosen from quickpick", async () => { createGlobalMocks(); From f46f05650cd12a3c3ae32fbf71f5948ac53eaa01 Mon Sep 17 00:00:00 2001 From: Billie Simmons <49491949+JillieBeanSim@users.noreply.github.com> Date: Wed, 18 Oct 2023 09:03:45 -0400 Subject: [PATCH 09/11] address code smells Signed-off-by: Billie Simmons <49491949+JillieBeanSim@users.noreply.github.com> --- .../__tests__/__unit__/job/actions.unit.test.ts | 12 ++---------- packages/zowe-explorer/src/dataset/actions.ts | 1 - 2 files changed, 2 insertions(+), 11 deletions(-) diff --git a/packages/zowe-explorer/__tests__/__unit__/job/actions.unit.test.ts b/packages/zowe-explorer/__tests__/__unit__/job/actions.unit.test.ts index 87a0ab588e..81256609a4 100644 --- a/packages/zowe-explorer/__tests__/__unit__/job/actions.unit.test.ts +++ b/packages/zowe-explorer/__tests__/__unit__/job/actions.unit.test.ts @@ -488,11 +488,7 @@ describe("Jobs Actions Unit Tests - Function submitJcl", () => { const blockMocks: any = createBlockMocks(); mocked(zowe.ZosmfSession.createSessCfgFromArgs).mockReturnValue(blockMocks.session); mocked(Profiles.getInstance).mockReturnValue(blockMocks.profileInstance); - mocked(vscode.window.showQuickPick).mockReturnValueOnce( - new Promise((resolve) => { - resolve(blockMocks.datasetSessionNode.label); - }) - ); + mocked(vscode.window.showQuickPick).mockReturnValueOnce(Promise.resolve(blockMocks.datasetSessionNode.label)); blockMocks.testDatasetTree.getChildren.mockResolvedValueOnce([ new ZoweDatasetNode("node", vscode.TreeItemCollapsibleState.None, blockMocks.datasetSessionNode, null as any), blockMocks.datasetSessionNode, @@ -543,11 +539,7 @@ describe("Jobs Actions Unit Tests - Function submitJcl", () => { const blockMocks: any = createBlockMocks(); mocked(zowe.ZosmfSession.createSessCfgFromArgs).mockReturnValue(blockMocks.session); mocked(Profiles.getInstance).mockReturnValue(blockMocks.profileInstance); - mocked(vscode.window.showQuickPick).mockReturnValueOnce( - new Promise((resolve) => { - resolve(blockMocks.datasetSessionNode.label); - }) - ); + mocked(vscode.window.showQuickPick).mockReturnValueOnce(Promise.resolve(blockMocks.datasetSessionNode.label)); blockMocks.testDatasetTree.getChildren.mockResolvedValueOnce([ new ZoweDatasetNode("node", vscode.TreeItemCollapsibleState.None, blockMocks.datasetSessionNode, null as any), blockMocks.datasetSessionNode, diff --git a/packages/zowe-explorer/src/dataset/actions.ts b/packages/zowe-explorer/src/dataset/actions.ts index d555694ead..cd034a4fec 100644 --- a/packages/zowe-explorer/src/dataset/actions.ts +++ b/packages/zowe-explorer/src/dataset/actions.ts @@ -991,7 +991,6 @@ export async function submitJcl(datasetProvider: api.IZoweTree Date: Tue, 24 Oct 2023 09:36:14 -0400 Subject: [PATCH 10/11] address comment and remove check for langID including JCL Signed-off-by: Billie Simmons <49491949+JillieBeanSim@users.noreply.github.com> --- packages/zowe-explorer/CHANGELOG.md | 2 +- .../__unit__/job/actions.unit.test.ts | 18 ------------ .../i18n/sample/package.i18n.json | 2 +- .../i18n/sample/src/dataset/actions.i18n.json | 3 +- packages/zowe-explorer/package.json | 28 +++++++++---------- packages/zowe-explorer/package.nls.json | 2 +- packages/zowe-explorer/src/dataset/actions.ts | 10 +------ 7 files changed, 19 insertions(+), 46 deletions(-) diff --git a/packages/zowe-explorer/CHANGELOG.md b/packages/zowe-explorer/CHANGELOG.md index d39707c7e3..a051013a40 100644 --- a/packages/zowe-explorer/CHANGELOG.md +++ b/packages/zowe-explorer/CHANGELOG.md @@ -10,7 +10,7 @@ All notable changes to the "vscode-extension-for-zowe" extension will be documen - Introduce a new user interface for managing profiles via right-click action "Manage Profile". - Added new edit feature on `Edit Attributes` view for changing file tags on USS [#2113](https://github.com/zowe/vscode-extension-for-zowe/issues/2113) - Added new API {ZE Extender MetaData} to allow extenders to have the metadata of registered extenders to aid in team configuration file creation from a view that isn't Zowe Explorer's. [#2394](https://github.com/zowe/vscode-extension-for-zowe/issues/2394) -- Added new right-click action for `Submit JCL` to local JCL files in VS Code file explorer as well as JCL opened in the VS Code text editor. [#2475](https://github.com/zowe/vscode-extension-for-zowe/issues/2475) +- Added new right-click action for `Submit as JCL` for local files in the VS Code file explorer as well as files opened in the VS Code text editor. [#2475](https://github.com/zowe/vscode-extension-for-zowe/issues/2475) - Added "Sort PDS members" feature in Data Sets tree view: accessible via sort icon on session node, or by right-clicking a PDS or session. [#2420](https://github.com/zowe/vscode-extension-for-zowe/issues/2420) - Added "Filter PDS members" feature in Data Sets tree view: accessible via filter icon on session node, or by right-clicking a PDS or session. [#2420](https://github.com/zowe/vscode-extension-for-zowe/issues/2420) - Added descriptions to data set nodes if filtering and/or sorting is enabled (where applicable). diff --git a/packages/zowe-explorer/__tests__/__unit__/job/actions.unit.test.ts b/packages/zowe-explorer/__tests__/__unit__/job/actions.unit.test.ts index 39ceab19ce..dd91a263b2 100644 --- a/packages/zowe-explorer/__tests__/__unit__/job/actions.unit.test.ts +++ b/packages/zowe-explorer/__tests__/__unit__/job/actions.unit.test.ts @@ -535,24 +535,6 @@ describe("Jobs Actions Unit Tests - Function submitJcl", () => { "Job submitted [JOB1234](command:zowe.jobs.setJobSpool?%5B%22sestest%22%2C%22JOB1234%22%5D)" ); }); - it("Checking failure of submitting of active text editor content not JCL", async () => { - createGlobalMocks(); - const blockMocks: any = createBlockMocks(); - mocked(zowe.ZosmfSession.createSessCfgFromArgs).mockReturnValue(blockMocks.session); - mocked(Profiles.getInstance).mockReturnValue(blockMocks.profileInstance); - mocked(vscode.window.showQuickPick).mockReturnValueOnce(Promise.resolve(blockMocks.datasetSessionNode.label)); - blockMocks.testDatasetTree.getChildren.mockResolvedValueOnce([ - new ZoweDatasetNode("node", vscode.TreeItemCollapsibleState.None, blockMocks.datasetSessionNode, null as any), - blockMocks.datasetSessionNode, - ]); - activeTextEditorDocument.mockReturnValue(blockMocks.textDocument); - (blockMocks.textDocument.languageId as string) = "java"; - await dsActions.submitJcl(blockMocks.testDatasetTree, undefined); - - const errorMsg = "The document being submitted is not a JCL, submission cancelled."; - expect(blockMocks.errorLogSpy).toBeCalledWith(errorMsg); - expect(blockMocks.errorGuiMsgSpy).toBeCalledWith(errorMsg); - }); it("Checking failure of submitting JCL via command palette if not active text editor", async () => { createGlobalMocks(); const blockMocks = createBlockMocks(); diff --git a/packages/zowe-explorer/i18n/sample/package.i18n.json b/packages/zowe-explorer/i18n/sample/package.i18n.json index a5a3599fe6..e3c8819b8b 100644 --- a/packages/zowe-explorer/i18n/sample/package.i18n.json +++ b/packages/zowe-explorer/i18n/sample/package.i18n.json @@ -40,7 +40,7 @@ "removeSavedSearch": "Remove Search", "removeSession": "Hide Profile", "saveSearch": "Add to Favorites", - "submitJcl": "Submit JCL", + "submitJcl": "Submit as JCL", "submitMember": "Submit Job", "uss.addSession": "Add Profile to USS View", "uss.copyPath": "Copy Path", diff --git a/packages/zowe-explorer/i18n/sample/src/dataset/actions.i18n.json b/packages/zowe-explorer/i18n/sample/src/dataset/actions.i18n.json index 114e621ffc..209867b8c6 100644 --- a/packages/zowe-explorer/i18n/sample/src/dataset/actions.i18n.json +++ b/packages/zowe-explorer/i18n/sample/src/dataset/actions.i18n.json @@ -43,8 +43,7 @@ "showAttributes.error": "Unable to list attributes.", "attributes.title": "Attributes", "submitJcl.notActiveEditorMsg": "No editor with a document that could be submitted as JCL is currently open.", - "submitJcl.notJclMsg": "The document being submitted is not a JCL, submission cancelled.", - "submitJcl.submitting": "Submitting JCL in document {0}", + "submitJcl.submitting": "Submitting as JCL in document {0}", "submitJcl.qp.placeholder": "Select the Profile to use to submit the job", "submitJcl.noProfile": "No profiles available", "submitJcl.nullSession.error": "Session for submitting JCL was null or undefined!", diff --git a/packages/zowe-explorer/package.json b/packages/zowe-explorer/package.json index 21d4f95437..001a2b6772 100644 --- a/packages/zowe-explorer/package.json +++ b/packages/zowe-explorer/package.json @@ -807,6 +807,20 @@ } ], "menus": { + "editor/context": [ + { + "when": "editorFocus", + "command": "zowe.ds.submitJcl", + "group": "000_zowe_dsMainframeInteraction@1" + } + ], + "explorer/context": [ + { + "when": "!explorerResourceIsFolder", + "command": "zowe.ds.submitJcl", + "group": "000_zowe_dsMainframeInteraction@1" + } + ], "view/title": [ { "when": "view == zowe.ds.explorer", @@ -839,20 +853,6 @@ "group": "navigation" } ], - "editor/context": [ - { - "when": "resourceLangId =~ /^.*jcl.*/i", - "command": "zowe.ds.submitJcl", - "group": "000_zowe_dsMainframeInteraction@1" - } - ], - "explorer/context": [ - { - "when": "resourceLangId =~ /^.*jcl.*/i", - "command": "zowe.ds.submitJcl", - "group": "000_zowe_dsMainframeInteraction@1" - } - ], "view/item/context": [ { "when": "viewItem =~ /^(?!.*_fav.*)ussSession.*/ && !listMultiSelection", diff --git a/packages/zowe-explorer/package.nls.json b/packages/zowe-explorer/package.nls.json index a5a3599fe6..e3c8819b8b 100644 --- a/packages/zowe-explorer/package.nls.json +++ b/packages/zowe-explorer/package.nls.json @@ -40,7 +40,7 @@ "removeSavedSearch": "Remove Search", "removeSession": "Hide Profile", "saveSearch": "Add to Favorites", - "submitJcl": "Submit JCL", + "submitJcl": "Submit as JCL", "submitMember": "Submit Job", "uss.addSession": "Add Profile to USS View", "uss.copyPath": "Copy Path", diff --git a/packages/zowe-explorer/src/dataset/actions.ts b/packages/zowe-explorer/src/dataset/actions.ts index cd034a4fec..b7e6c9e6c0 100644 --- a/packages/zowe-explorer/src/dataset/actions.ts +++ b/packages/zowe-explorer/src/dataset/actions.ts @@ -988,15 +988,7 @@ export async function submitJcl(datasetProvider: api.IZoweTree Date: Tue, 24 Oct 2023 09:42:09 -0400 Subject: [PATCH 11/11] update bug fix changelog for this item Signed-off-by: Billie Simmons <49491949+JillieBeanSim@users.noreply.github.com> --- packages/zowe-explorer/CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/zowe-explorer/CHANGELOG.md b/packages/zowe-explorer/CHANGELOG.md index a051013a40..f14cec82e9 100644 --- a/packages/zowe-explorer/CHANGELOG.md +++ b/packages/zowe-explorer/CHANGELOG.md @@ -18,7 +18,7 @@ All notable changes to the "vscode-extension-for-zowe" extension will be documen ### Bug fixes -- Fixed submitting local JCL using command pallet option `Zowe Explorer: Submit JCL` by adding a check for chosen profile returned to continue the action and added check on the language id for JCL. [#1625](https://github.com/zowe/vscode-extension-for-zowe/issues/1625) +- Fixed submitting local JCL using command pallet option `Zowe Explorer: Submit as JCL` by adding a check for chosen profile returned to continue the action. [#1625](https://github.com/zowe/vscode-extension-for-zowe/issues/1625) - Fixed conflict resolution being skipped if local and remote file have different contents but are the same size. [#2496](https://github.com/zowe/vscode-extension-for-zowe/issues/2496) ## `2.11.2`