Skip to content

Commit

Permalink
tests(node/ds): Verify migration & recall in getChildren
Browse files Browse the repository at this point in the history
Signed-off-by: Trae Yelovich <[email protected]>
  • Loading branch information
traeok committed Feb 24, 2025
1 parent abfbace commit c58c1f0
Showing 1 changed file with 108 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import { DatasetFSProvider } from "../../../../src/trees/dataset/DatasetFSProvid
import { ZoweDatasetNode } from "../../../../src/trees/dataset/ZoweDatasetNode";
import { IconUtils } from "../../../../src/icons/IconUtils";
import { IconGenerator } from "../../../../src/icons/IconGenerator";
import { SharedTreeProviders } from "../../../../src/trees/shared/SharedTreeProviders";

// Missing the definition of path module, because I need the original logic for tests
jest.mock("fs");
Expand Down Expand Up @@ -925,3 +926,110 @@ describe("ZoweDatasetNode Unit Tests - function datasetMigrated", () => {
expect(dsNode.iconPath).toBe(IconGenerator.getIconById(IconUtils.IconId.migrated).path);
});
});

describe("ZoweDatasetNode Unit Tests - getChildren() migration scenarios", () => {
const session = createISession();
const profileOne: imperative.IProfileLoaded = createIProfile();

beforeEach(() => {
jest.resetAllMocks();
});

it("should handle a dataset that was migrated", async () => {
const sessionNode = new ZoweDatasetNode({
label: "sestest",
collapsibleState: vscode.TreeItemCollapsibleState.Collapsed,
session,
profile: profileOne,
contextOverride: Constants.DS_SESSION_CONTEXT,
});

const pdsNode = new ZoweDatasetNode({
label: "TEST.PDS",
collapsibleState: vscode.TreeItemCollapsibleState.Collapsed,
parentNode: sessionNode,
profile: profileOne,
contextOverride: Constants.DS_PDS_CONTEXT,
});

sessionNode.pattern = "TEST.*";
sessionNode.children = [pdsNode];

jest.spyOn(SharedTreeProviders, "ds", "get").mockReturnValueOnce({
applyPatternsToChildren: jest.fn(),
} as any);
jest.spyOn(Profiles, "getInstance").mockReturnValueOnce({
loadNamedProfile: jest.fn().mockReturnValueOnce(profileOne),
} as any);
jest.spyOn(sessionNode as any, "getDatasets").mockResolvedValueOnce([
{
success: true,
apiResponse: {
items: [
{
dsname: "TEST.PDS",
migr: "YES",
dsorg: "PO",
},
],
},
},
]);

await sessionNode.getChildren();

expect(pdsNode.contextValue).toBe(Constants.DS_MIGRATED_FILE_CONTEXT);
expect(pdsNode.collapsibleState).toBe(vscode.TreeItemCollapsibleState.None);
expect(pdsNode.resourceUri).toBeUndefined();
expect(pdsNode.command).toBeUndefined();
});

it("should handle a dataset that was recalled", async () => {
const sessionNode = new ZoweDatasetNode({
label: "sestest",
collapsibleState: vscode.TreeItemCollapsibleState.Collapsed,
session,
profile: profileOne,
contextOverride: Constants.DS_SESSION_CONTEXT,
});

const dsNode = new ZoweDatasetNode({
label: "TEST.DS",
collapsibleState: vscode.TreeItemCollapsibleState.None,
parentNode: sessionNode,
profile: profileOne,
contextOverride: Constants.DS_MIGRATED_FILE_CONTEXT,
});

sessionNode.pattern = "TEST.*";
sessionNode.children = [dsNode];

jest.spyOn(SharedTreeProviders, "ds", "get").mockReturnValueOnce({
applyPatternsToChildren: jest.fn(),
} as any);
jest.spyOn(Profiles, "getInstance").mockReturnValueOnce({
loadNamedProfile: jest.fn().mockReturnValueOnce(profileOne),
} as any);
jest.spyOn(sessionNode as any, "getDatasets").mockResolvedValueOnce([
{
success: true,
apiResponse: {
items: [
{
dsname: "TEST.DS",
migr: "NO",
dsorg: "PS",
},
],
},
},
]);

await sessionNode.getChildren();

expect(dsNode.contextValue).toBe(Constants.DS_DS_CONTEXT);
expect(dsNode.collapsibleState).toBe(vscode.TreeItemCollapsibleState.None);
expect(dsNode.resourceUri).toBeDefined();
expect(dsNode.command).toBeDefined();
});
});

0 comments on commit c58c1f0

Please sign in to comment.