Skip to content

Commit

Permalink
sdd tests for DatasetTree
Browse files Browse the repository at this point in the history
Signed-off-by: Billie Simmons <[email protected]>
  • Loading branch information
JillieBeanSim committed Jul 12, 2023
1 parent d2b337a commit 782547c
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -548,6 +548,22 @@ describe("Dataset Tree Unit Tests - Function getChildren", () => {

expect(children).toEqual(sampleChildren);
});
it("Checking function for return if element.getChildren is undefined", async () => {
createGlobalMocks();
const blockMocks = createBlockMocks();

mocked(Profiles.getInstance).mockReturnValue(blockMocks.profile);
mocked(vscode.window.createTreeView).mockReturnValueOnce(blockMocks.treeView);
const testTree = new DatasetTree();
testTree.mSessionNodes.push(blockMocks.datasetSessionNode);
const parent = new ZoweDatasetNode("BRTVS99.PUBLIC", vscode.TreeItemCollapsibleState.Collapsed, testTree.mSessionNodes[1], null);
parent.dirty = true;
jest.spyOn(parent, "getChildren").mockResolvedValueOnce(undefined as any);

const children = await testTree.getChildren(parent);

expect(children).not.toBeDefined();
});
});
describe("Dataset Tree Unit Tests - Function loadProfilesForFavorites", () => {
function createBlockMocks() {
Expand Down Expand Up @@ -1628,6 +1644,7 @@ describe("Dataset Tree Unit Tests - Function datasetFilterPrompt", () => {
value: jest.fn(() => {
throw new Error("test error");
}),
configurable: true,
});
const errorSpy = jest.spyOn(utils, "errorHandling");

Expand All @@ -1636,6 +1653,28 @@ describe("Dataset Tree Unit Tests - Function datasetFilterPrompt", () => {
expect(errorSpy).toBeCalled();
errorSpy.mockClear();
});
it("Checking function for return if getChildren is undefined", async () => {
const globalMocks = await createGlobalMocks();
const blockMocks = await createBlockMocks(globalMocks);

mocked(vscode.window.showQuickPick).mockResolvedValueOnce(new utils.FilterDescriptor("\uFF0B " + "Create a new filter"));
mocked(vscode.window.showInputBox).mockResolvedValueOnce("HLQ.PROD1.STUFF");
mocked(vscode.window.createTreeView).mockReturnValueOnce(blockMocks.treeView);
const testTree = new DatasetTree();
testTree.mSessionNodes.push(blockMocks.datasetSessionNode);
Object.defineProperty(testTree.mSessionNodes[1], "getChildren", {
value: jest.fn(() => {
return;
}),
configurable: true,
});
const errorSpy = jest.spyOn(utils, "errorHandling");

expect(await testTree.datasetFilterPrompt(testTree.mSessionNodes[1])).not.toBeDefined();

expect(errorSpy).not.toBeCalled();
errorSpy.mockClear();
});
});
describe("Dataset Tree Unit Tests - Function editSession", () => {
async function createBlockMocks() {
Expand Down
2 changes: 1 addition & 1 deletion packages/zowe-explorer/src/dataset/DatasetTree.ts
Original file line number Diff line number Diff line change
Expand Up @@ -988,7 +988,7 @@ export class DatasetTree extends ZoweTreeProvider implements IZoweTree<IZoweData
} catch (err) {
return void errorHandling(err, String(node.label));
}
if (!response || response.length === 0) {
if (!response) {
return;
}
// reset and remove previous search patterns for each child of getChildren
Expand Down

0 comments on commit 782547c

Please sign in to comment.