Skip to content

Commit 74014a1

Browse files
committed
add tests for library and util treeitems
Signed-off-by: Andrew Twydell <[email protected]>
1 parent 86c8e53 commit 74014a1

File tree

2 files changed

+182
-0
lines changed

2 files changed

+182
-0
lines changed
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
/**
2+
* This program and the accompanying materials are made available under the terms of the
3+
* Eclipse Public License v2.0 which accompanies this distribution, and is available at
4+
* https://www.eclipse.org/legal/epl-v20.html
5+
*
6+
* SPDX-License-Identifier: EPL-2.0
7+
*
8+
* Copyright Contributors to the Zowe Project.
9+
*
10+
*/
11+
12+
import { expect, test } from "@playwright/test";
13+
import { constants, findAndClickText, findAndClickTreeItem, getTreeItem, prepareZoweExplorerView, resetWiremock, resetZoweExplorerView } from "../utils/helpers";
14+
15+
test.beforeEach(async ({ page, request }) => {
16+
await resetWiremock(request);
17+
await prepareZoweExplorerView(page);
18+
});
19+
20+
test.afterEach(async ({ page }) => {
21+
await resetZoweExplorerView(page);
22+
});
23+
24+
test.describe("Library tests", () => {
25+
test("should expand libraries tree to reveal libraries", async ({ page }) => {
26+
await findAndClickTreeItem(page, constants.PROFILE_NAME);
27+
await findAndClickTreeItem(page, constants.CICSPLEX_NAME);
28+
await findAndClickTreeItem(page, constants.REGION_NAME);
29+
await findAndClickTreeItem(page, "Libraries");
30+
31+
await expect(getTreeItem(page, constants.LIBRARY_1_NAME)).toBeVisible();
32+
await expect(getTreeItem(page, constants.LIBRARY_1_NAME)).toHaveText(constants.LIBRARY_1_NAME);
33+
});
34+
35+
test("should enable and disable a library", async ({ page }) => {
36+
await findAndClickTreeItem(page, constants.PROFILE_NAME);
37+
await findAndClickTreeItem(page, constants.CICSPLEX_NAME);
38+
await findAndClickTreeItem(page, constants.REGION_NAME);
39+
await findAndClickTreeItem(page, "Libraries");
40+
41+
await expect(getTreeItem(page, constants.LIBRARY_1_NAME)).toHaveText(constants.LIBRARY_1_NAME);
42+
await expect(getTreeItem(page, constants.LIBRARY_1_NAME)).toBeVisible();
43+
44+
await findAndClickTreeItem(page, constants.LIBRARY_1_NAME, "right");
45+
46+
await page.waitForTimeout(200);
47+
await findAndClickText(page, "Disable Library");
48+
49+
await expect(getTreeItem(page, `${constants.LIBRARY_1_NAME} (Disabled)`)).toHaveText(`${constants.LIBRARY_1_NAME} (Disabled)`);
50+
51+
await findAndClickTreeItem(page, `${constants.LIBRARY_1_NAME} (Disabled)`, "right");
52+
53+
await page.waitForTimeout(200);
54+
await findAndClickText(page, "Enable Library");
55+
56+
await expect(getTreeItem(page, constants.LIBRARY_1_NAME)).toBeVisible();
57+
await expect(getTreeItem(page, constants.LIBRARY_1_NAME)).toHaveText(constants.LIBRARY_1_NAME);
58+
});
59+
});
Lines changed: 123 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,123 @@
1+
/**
2+
* This program and the accompanying materials are made available under the terms of the
3+
* Eclipse Public License v2.0 which accompanies this distribution, and is available at
4+
* https://www.eclipse.org/legal/epl-v20.html
5+
*
6+
* SPDX-License-Identifier: EPL-2.0
7+
*
8+
* Copyright Contributors to the Zowe Project.
9+
*
10+
*/
11+
12+
import { CICSRegionTree, CICSResourceContainerNode, CICSSessionTree, CICSTree } from "../../../src/trees";
13+
import { evaluateTreeNodes } from "../../../src/utils/treeUtils";
14+
import { ProgramMeta } from "../../../src/doc";
15+
import { IProfileLoaded } from "@zowe/imperative";
16+
import { ICMCIApiResponse } from "@zowe/cics-for-zowe-sdk";
17+
import PersistentStorage from "../../../src/utils/PersistentStorage";
18+
import { ResourceContainer } from "../../../src/resources";
19+
import { IProgram } from "@zowe/cics-for-zowe-explorer-api";
20+
21+
jest.mock("../../../src/utils/profileManagement", () => ({
22+
ProfileManagement: {},
23+
}));
24+
jest.spyOn(PersistentStorage, "getNumberOfResourcesToFetch").mockReturnValue(250);
25+
jest.spyOn(PersistentStorage, "getDefaultResourceFilter").mockReturnValue("Program=A*");
26+
27+
const CICSProfileMock = {
28+
host: "hostname",
29+
port: "123",
30+
user: "a",
31+
password: "b",
32+
rejectUnauthorized: false,
33+
protocol: "http",
34+
};
35+
const profile: IProfileLoaded = { profile: CICSProfileMock, failNotFound: false, message: "", type: "cics", name: "MYPROF" };
36+
37+
const cicsTree = { _onDidChangeTreeData: { fire: () => jest.fn() }, refresh: () => { } } as unknown as CICSTree;
38+
39+
const sessionTree = new CICSSessionTree(profile, cicsTree);
40+
const regionTree = new CICSRegionTree("REG", {}, sessionTree, undefined, sessionTree);
41+
const parentNode = new CICSResourceContainerNode(
42+
"Programs",
43+
{
44+
parentNode: regionTree,
45+
profile,
46+
regionName: "REG",
47+
cicsplexName: ""
48+
},
49+
undefined,
50+
{
51+
meta: ProgramMeta,
52+
resources: new ResourceContainer(ProgramMeta),
53+
}
54+
);
55+
const prog: IProgram = {
56+
eyu_cicsname: "REG",
57+
library: "",
58+
librarydsn: "",
59+
newcopycnt: "1",
60+
program: "APROG",
61+
progtype: "",
62+
status: "ENABLED"
63+
};
64+
65+
describe("Tree Utils tests", () => {
66+
67+
let resourceNode: CICSResourceContainerNode<IProgram>;
68+
69+
beforeEach(() => {
70+
resourceNode = new CICSResourceContainerNode(
71+
"APROG1",
72+
{
73+
parentNode,
74+
profile,
75+
regionName: "REG",
76+
cicsplexName: ""
77+
},
78+
{
79+
meta: ProgramMeta,
80+
resource: { attributes: prog }
81+
},
82+
{
83+
meta: ProgramMeta,
84+
resources: new ResourceContainer(ProgramMeta),
85+
}
86+
);
87+
88+
jest.resetAllMocks();
89+
});
90+
91+
it("should do nothing if no record is returned", () => {
92+
93+
const apiResp: ICMCIApiResponse = {
94+
response: {
95+
records: [],
96+
resultsummary: { api_response1: "", api_response2: "", displayed_recordcount: "0", recordcount: "0" }
97+
}
98+
};
99+
const updateItemSpy = jest.spyOn(CICSResourceContainerNode.prototype, "setContainedResource");
100+
evaluateTreeNodes(resourceNode, cicsTree, apiResp, ProgramMeta);
101+
102+
expect(updateItemSpy).not.toHaveBeenCalled();
103+
});
104+
105+
it("should update the record in the resource node", () => {
106+
107+
const updatedProgram = { ...prog, newcopycnt: 2 };
108+
const apiResp: ICMCIApiResponse = {
109+
response: {
110+
records: {
111+
cicsprogram: updatedProgram
112+
},
113+
resultsummary: { api_response1: "", api_response2: "", displayed_recordcount: "0", recordcount: "0" }
114+
}
115+
};
116+
const updateItemSpy = jest.spyOn(CICSResourceContainerNode.prototype, "setContainedResource");
117+
evaluateTreeNodes(resourceNode, cicsTree, apiResp, ProgramMeta);
118+
119+
expect(updateItemSpy).toHaveBeenCalledTimes(1);
120+
expect(updateItemSpy).toHaveBeenCalledWith({ attributes: updatedProgram });
121+
});
122+
123+
});

0 commit comments

Comments
 (0)