Skip to content

Commit

Permalink
basic CICSTree unit tests
Browse files Browse the repository at this point in the history
Signed-off-by: Andrew Twydell <[email protected]>
  • Loading branch information
AndrewTwydell committed Feb 5, 2025
1 parent 9b602c4 commit 6716605
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 2 deletions.
45 changes: 43 additions & 2 deletions packages/vsce/__tests__/__unit__/trees/CICSTree.unit.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,24 @@
* Copyright Contributors to the Zowe Project.
*
*/

import { CICSProfileMock } from "../../__utils__/globalMocks";
import { imperative } from "@zowe/zowe-explorer-api";

const profilesCacheRefreshMock = jest.fn();
profilesCacheRefreshMock.mockReturnValue(["prof1", "prof2"]);
const getProfilesCacheMock = jest.fn();
getProfilesCacheMock.mockReturnValue({
loadNamedProfile: (name: string, type?: string): imperative.IProfileLoaded => {
return {
failNotFound: false,
message: "",
type: "cics",
name: name,
profile: CICSProfileMock
};
}
});

import { CICSTree } from "../../../src/trees/CICSTree";

Expand All @@ -24,15 +41,39 @@ jest.mock("../../../src/utils/PersistentStorage", () => ({
jest.mock("../../../src/utils/profileManagement", () => ({
ProfileManagement: {
profilesCacheRefresh: profilesCacheRefreshMock,
getProfilesCache: getProfilesCacheMock,
},
}));

describe("Test suite for CICSTree", () => {
let sut: CICSTree;

beforeEach(() => {
sut = new CICSTree();
});
it("Should run the test", () => {
expect(true).toBeTruthy();

it("Should have children", () => {
expect(sut.loadedProfiles).toBeDefined();
expect(sut.loadedProfiles).toHaveLength(2);
});

it("Should getLoadedProfiles", () => {
const loadedProfs = sut.getLoadedProfiles();
expect(loadedProfs).toBeDefined();
expect(loadedProfs).toHaveLength(2);
});

it("Should clear profiles", () => {
const loadedProfs = sut.getLoadedProfiles();
expect(loadedProfs).toBeDefined();
expect(loadedProfs).toHaveLength(2);

sut.clearLoadedProfiles();
expect(sut.loadedProfiles).toBeDefined();
expect(sut.loadedProfiles).toHaveLength(0);
});

it("Should return the children", () => {
expect(sut.getChildren()).toHaveLength(2);
});
});
9 changes: 9 additions & 0 deletions packages/vsce/__tests__/__utils__/globalMocks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,15 @@ export const zoweSdkMock = require("@zowe/cics-for-zowe-sdk");
export const toEscapedCriteriaString = jest.spyOn(filterUtils, "toEscapedCriteriaString");
export const getResourceMock = jest.spyOn(zoweSdkMock, "getResource");

export const CICSProfileMock = {
host: "hostname",
port: "123",
user: "a",
password: "b",
rejectUnauthorized: false,
protocol: "http",
};

export const imperativeSession = new imperative.Session({
user: "user",
password: "pwd",
Expand Down

0 comments on commit 6716605

Please sign in to comment.