Skip to content

Commit

Permalink
updated with filter jobs
Browse files Browse the repository at this point in the history
Signed-off-by: SanthoshiBoyina <[email protected]>
  • Loading branch information
SanthoshiBoyina1 committed Oct 10, 2023
1 parent ab0c271 commit bd05209
Show file tree
Hide file tree
Showing 7 changed files with 29 additions and 192 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,6 @@ async function createGlobalMocks() {
"zowe.jobs.sortbyid",
"zowe.jobs.sortbyreturncode",
"zowe.jobs.filterJobs",
"zowe.jobs.filterSpools",
"zowe.manualPoll",
"zowe.updateSecureCredentials",
"zowe.promptCredentials",
Expand Down
124 changes: 16 additions & 108 deletions packages/zowe-explorer/__tests__/__unit__/job/actions.unit.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1469,133 +1469,41 @@ describe("Job Actions Unit Tests - Filter Jobs", () => {
setJobObjects(createIJobObject(), "ZOWEUSR2", "JOB05037", "CC 0000"),
null
);
const node3 = new Job(
"jobnew",
vscode.TreeItemCollapsibleState.None,
null,
null,
setJobObjects(createIJobObject(), "ZOWEUSR3", "TSU07707", "ABEND S222"),
null
);

it("To show showInformationMessage", async () => {
const testTree = new ZosJobsProvider();
testTree.mSessionNodes[0].label = "zosmf";
testTree.mSessionNodes[0].collapsibleState = 1;
node1.collapsibleState = vscode.TreeItemCollapsibleState.Collapsed;

await jobActions.filterJobs(testTree);
await jobActions.filterJobs(testTree, node1);

expect(mocked(Gui.infoMessage)).toHaveBeenCalled();
});

it("To filter jobs based on a combination of JobName, JobId and Return code", async () => {
const testTree = new ZosJobsProvider();
testTree.mSessionNodes[0].label = "zosmf";
testTree.mSessionNodes[0].collapsibleState = 2;
testTree.mSessionNodes[0].children = [node1, node2];
node1.collapsibleState = vscode.TreeItemCollapsibleState.Expanded;
node1.children = [node2, node3];

const createInputBoxSpy = jest.spyOn(vscode.window, "createInputBox");
mockInputBox.value = "ZOWEUSR1(JOB04945) - CC 0000";
mockInputBox.value = "ZOWEUSR2(JOB05037) - CC 0000";
createInputBoxSpy.mockReturnValue(mockInputBox);
const filterJobsSpy = jest.spyOn(jobActions, "filterJobs");
await jobActions.filterJobs(testTree);
testTree.mSessionNodes[0].children = [node1];
await jobActions.filterJobs(testTree, node1);
testTree.mSessionNodes[0].children = [node2];

expect(createInputBoxSpy).toHaveBeenCalled();
expect(filterJobsSpy).toHaveBeenCalled();
expect(filterJobsSpy).toBeCalledWith(testTree);
expect(filterJobsSpy).toBeCalledWith(testTree, node1);
expect(filterJobsSpy.mock.calls[0][0].mSessionNodes[0].children).toBe(testTree.mSessionNodes[0].children);
});
});

describe("Job Actions Unit Tests - Filter Spools", () => {
function createBlockMocks() {
const session = createISession();
const treeView = createTreeView();
const iJob = createIJobObject();
const imperativeProfile = createIProfile();
const testJobTree = createJobsTree(session, iJob, imperativeProfile, treeView);

return {
session,
treeView,
iJob,
imperativeProfile,
testJobTree,
testJobsTree: createJobsTree(session, iJob, imperativeProfile, treeView),
};
}
const blockMocks = createBlockMocks();

function setSpoolObjects(spool: zowe.IJobFile, newStepName: string, newDdName: string, newRecordCount: number) {
spool.stepname = newStepName;
spool.ddname = newDdName;
spool["record-count"] = newRecordCount;
return spool;
}

const node2 = new Job(
"jobnew",
vscode.TreeItemCollapsibleState.None,
null,
null,
setJobObjects(createIJobObject(), "ZOWEUSR2", "JOB05037", "CC 0000"),
null
);

const node1 = new Job(
"jobnew",
vscode.TreeItemCollapsibleState.None,
node2,
blockMocks.session,
setJobObjects(createIJobObject(), "ZOWEUSR1", "JOB04945", "CC 0000"),
createIProfile()
);

const spoolNode1 = new Spool(
"JES2:JESMSGLG - 21",
vscode.TreeItemCollapsibleState.None,
node1,
null,
setSpoolObjects(createIJobFile(), "JES2", "JESMSGLG", 21),
createIJobObject(),
node1
);
const spoolNode2 = new Spool(
"DELETE:SYSPRINT - 7",
vscode.TreeItemCollapsibleState.None,
node1,
null,
setSpoolObjects(createIJobFile(), "DELETE", "SYSPRINT", 7),
createIJobObject(),
node1
);

it("To check a job is expanded or not when filter spools option is choosen", async () => {
const testTree = blockMocks.testJobTree;
node1.collapsibleState = 1;
const filterSpoolsSpy = jest.spyOn(jobActions, "filterSpools");
const createInputBoxSpy = jest.spyOn(vscode.window, "createInputBox");
mockInputBox.value = "DELETE:SYSPRINT - 7";
createInputBoxSpy.mockReturnValue(mockInputBox);

await jobActions.filterSpools(testTree, node1);

expect(createInputBoxSpy).toHaveBeenCalled();
expect(filterSpoolsSpy).toHaveBeenCalled();
expect(filterSpoolsSpy).toBeCalledWith(testTree, node1);
expect(filterSpoolsSpy.mock.calls[0][1].collapsibleState).toBe(vscode.TreeItemCollapsibleState.Expanded);
});

it("To filter spools based on a combination of stepname, ddname and record-count", async () => {
const testTree = blockMocks.testJobTree;
node1.collapsibleState = 1;
node1.children = [spoolNode1, spoolNode2];
testTree.mSessionNodes[0].children = [node1];
const createInputBoxSpy = jest.spyOn(vscode.window, "createInputBox");
mockInputBox.value = "JES2:JESMSGLG - 21";
createInputBoxSpy.mockReturnValue(mockInputBox);
const filterSpoolsSpy = jest.spyOn(jobActions, "filterSpools");

await jobActions.filterSpools(testTree, node1);
node1.children = [spoolNode1];
testTree.mSessionNodes[0].children = [node1];

expect(createInputBoxSpy).toHaveBeenCalled();
expect(filterSpoolsSpy).toHaveBeenCalled();
expect(filterSpoolsSpy).toBeCalledWith(testTree, node1);
expect(filterSpoolsSpy.mock.calls[0][0].mSessionNodes[0].children).toBe(testTree.mSessionNodes[0].children);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -223,11 +223,7 @@ describe("Test src/jobs/extension", () => {
},
{
name: "zowe.jobs.filterJobs",
mock: [{ spy: jest.spyOn(jobActions, "filterJobs"), arg: [jobsProvider] }],
},
{
name: "zowe.jobs.filterSpools",
mock: [{ spy: jest.spyOn(jobActions, "filterSpools"), arg: [jobsProvider, test.value] }],
mock: [{ spy: jest.spyOn(jobActions, "filterJobs"), arg: [jobsProvider, test.value] }],
},
];

Expand Down
10 changes: 0 additions & 10 deletions packages/zowe-explorer/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -753,11 +753,6 @@
"dark": "./resources/dark/filter-dark.svg"
}
},
{
"command": "zowe.jobs.filterSpools",
"title": "Filter Spools",
"category": "Zowe Explorer"
},
{
"command": "zowe.jobs.search",
"title": "%jobs.search%",
Expand Down Expand Up @@ -1357,11 +1352,6 @@
"command": "zowe.jobs.cancelJob",
"group": "099_zowe_jobsModification"
},
{
"when": "view == zowe.jobs.explorer && viewItem =~ /^job.*/",
"command": "zowe.jobs.filterSpools",
"group": "099_zowe_jobsModification"
},
{
"when": "view == zowe.jobs.explorer && viewItem =~ /_validate/ && !listMultiSelection",
"command": "zowe.jobs.disableValidation",
Expand Down
2 changes: 1 addition & 1 deletion packages/zowe-explorer/src/globals.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ export let DS_DIR: string;
export let CONFIG_PATH; // set during activate
export let ISTHEIA = false; // set during activate
export let LOG: imperative.Logger;
export const COMMAND_COUNT = 115;
export const COMMAND_COUNT = 114;
export const MAX_SEARCH_HISTORY = 5;
export const MAX_FILE_HISTORY = 10;
export const MS_PER_SEC = 1000;
Expand Down
69 changes: 9 additions & 60 deletions packages/zowe-explorer/src/job/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import * as nls from "vscode-nls";
import SpoolProvider, { encodeJobFile, getSpoolFiles, matchSpool } from "../SpoolProvider";
import { ZoweLogger } from "../utils/LoggerUtils";
import { getDefaultUri } from "../shared/utils";
import { TreeViewUtils } from "../utils/TreeViewUtils";

// Set up localization
nls.config({
Expand Down Expand Up @@ -543,72 +542,22 @@ export async function sortJobsBy(jobs: IZoweJobTreeNode, jobsProvider: IZoweTree
jobsProvider.refresh();
}

export async function filterJobs(jobsProvider: IZoweTree<IZoweJobTreeNode>): Promise<vscode.InputBox> {
let acutal_jobs;
let flag = false;
for (const level of jobsProvider.mSessionNodes) {
if (level.label === "zosmf") {
acutal_jobs = level.children;
if (level.collapsibleState === vscode.TreeItemCollapsibleState.Collapsed) {
Gui.infoMessage(localize("filterJobs.message", "Use the search button to display jobs"));
flag = true;
}
}
export async function filterJobs(jobsProvider: IZoweTree<IZoweJobTreeNode>, job: IZoweJobTreeNode): Promise<vscode.InputBox> {
if (job.collapsibleState === vscode.TreeItemCollapsibleState.Collapsed) {
Gui.infoMessage(localize("filterJobs.message", "Use the search button to display jobs"));
return;
}
if (flag) return;

const acutal_jobs = job["children"];
const inputBox = await vscode.window.createInputBox();
inputBox.placeholder = localize("filterJobs.prompt.message", "Enter local filter...");
inputBox.onDidChangeValue((query) => {
query = query.toUpperCase();
for (const level of jobsProvider.mSessionNodes) {
if (level.label === "zosmf") {
level.children = acutal_jobs.filter((item) =>
`${item["job"].jobname as string}(${item["job"].jobid as string}) - ${item["job"].retcode as string}`.includes(query)
);
}
}
job["children"] = acutal_jobs.filter((item) => `${item["job"].jobname}(${item["job"].jobid}) - ${item["job"].retcode}`.includes(query));
jobsProvider.refresh();
});
inputBox.onDidAccept(() => {
inputBox.hide();
});
inputBox.show();
return inputBox;
}

export async function filterSpools(jobsProvider: IZoweTree<IZoweJobTreeNode>, job: IZoweJobTreeNode): Promise<vscode.InputBox> {
try {
if (job["collapsibleState"] == vscode.TreeItemCollapsibleState.Collapsed) {
const Spools = (await getSpoolFiles(job)).map((spool) => {
const spoolNode = new Spool(
`${spool.stepname}:${spool.ddname} - ${spool["record-count"]}`,
vscode.TreeItemCollapsibleState.None,
job.getParent(),
job.getSession(),
spool,
job.job,
job.getParent()
);
return spoolNode;
});
job.children = Spools;

await TreeViewUtils.expandNode(job, jobsProvider);
job.collapsibleState = vscode.TreeItemCollapsibleState.Expanded;
jobsProvider.refresh();
}

const actual_spools = job.children;
const inputBox = vscode.window.createInputBox();
inputBox.placeholder = localize("filterJobs.prompt.message", "Enter local filter...");
inputBox.onDidChangeValue((query) => {
query = query.toUpperCase();
job["children"] = actual_spools.filter((item) =>
`${item["spool"].stepname as string}:${item["spool"].ddname as string} - ${item["spool"]["record-count"] as string}`.includes(query)
);
jobsProvider.refresh();
});
inputBox.show();
return inputBox;
} catch (error) {
await errorHandling(error);
}
}
9 changes: 2 additions & 7 deletions packages/zowe-explorer/src/job/init.ts
Original file line number Diff line number Diff line change
Expand Up @@ -175,13 +175,8 @@ export async function initJobsProvider(context: vscode.ExtensionContext): Promis
vscode.commands.registerCommand("zowe.jobs.sortbyreturncode", (job) => jobActions.sortJobsBy(job, jobsProvider, "retcode"))
);
context.subscriptions.push(
vscode.commands.registerCommand("zowe.jobs.filterJobs", async () => {
await jobActions.filterJobs(jobsProvider);
})
);
context.subscriptions.push(
vscode.commands.registerCommand("zowe.jobs.filterSpools", async (job) => {
await jobActions.filterSpools(jobsProvider, job);
vscode.commands.registerCommand("zowe.jobs.filterJobs", async (job) => {
await jobActions.filterJobs(jobsProvider, job);
})
);

Expand Down

0 comments on commit bd05209

Please sign in to comment.