Skip to content

Commit

Permalink
tests: patch coverage for DatasetTree, USSTree
Browse files Browse the repository at this point in the history
Signed-off-by: Trae Yelovich <[email protected]>
  • Loading branch information
traeok committed Nov 18, 2024
1 parent 979e637 commit 6a723d1
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ import { Sorting } from "../../../../../zowe-explorer-api/src/tree";
import { IconUtils } from "../../../../src/icons/IconUtils";
import { SharedContext } from "../../../../src/trees/shared/SharedContext";
import { ZoweTreeProvider } from "../../../../src/trees/ZoweTreeProvider";
import { TreeViewUtils } from "../../../../src/utils/TreeViewUtils";

jest.mock("fs");
jest.mock("util");
Expand Down Expand Up @@ -2264,6 +2265,31 @@ describe("Dataset Tree Unit Tests - Function rename", () => {
};
}

it("returns early if promptedForUnsavedResource was true", async () => {
createGlobalMocks();
const blockMocks = createBlockMocks();
mocked(Profiles.getInstance).mockReturnValue(blockMocks.profileInstance);
mocked(vscode.window.createTreeView).mockReturnValueOnce(blockMocks.treeView);
const testTree = new DatasetTree();
testTree.mSessionNodes.push(blockMocks.datasetSessionNode);
const node = new ZoweDatasetNode({
label: "HLQ.TEST.RENAME.NODE",
collapsibleState: vscode.TreeItemCollapsibleState.None,
parentNode: testTree.mSessionNodes[1],
session: blockMocks.session,
profile: testTree.mSessionNodes[1].getProfile(),
});
blockMocks.rename.mockClear();
const promptedForUnsavedResource = jest.spyOn(TreeViewUtils, "promptedForUnsavedResource").mockResolvedValueOnce(true);
await testTree.rename(node);
expect(promptedForUnsavedResource).toHaveBeenCalled();
expect(blockMocks.rename).not.toHaveBeenLastCalledWith(
{ path: "/sestest/HLQ.TEST.RENAME.NODE", scheme: ZoweScheme.DS },
{ path: "/sestest/HLQ.TEST.RENAME.NODE.NEW", scheme: ZoweScheme.DS },
{ overwrite: false }
);
});

it("Tests that rename() renames a node", async () => {
createGlobalMocks();
const blockMocks = createBlockMocks();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ import { AuthUtils } from "../../../../src/utils/AuthUtils";
import { Icon } from "../../../../src/icons/Icon";
import { ZoweTreeProvider } from "../../../../src/trees/ZoweTreeProvider";
import { TreeViewUtils } from "../../../../src/utils/TreeViewUtils";
import { SharedContext } from "../../../../src/trees/shared/SharedContext";

function createGlobalMocks() {
const globalMocks = {
Expand Down Expand Up @@ -935,7 +936,7 @@ describe("USSTree Unit Tests - Function rename", () => {
globalMocks.FileSystemProvider.rename.mockClear();

const newMocks = {
promptedForUnsavedResource: jest.spyOn(TreeViewUtils, "promptedForUnsavedResource").mockResolvedValue(false),
promptedForUnsavedResource: jest.spyOn(TreeViewUtils, "promptedForUnsavedResource").mockResolvedValueOnce(false),
ussFavNode,
ussFavNodeParent,
setAttributes: jest.spyOn(ZoweUSSNode.prototype, "setAttributes").mockImplementation(),
Expand All @@ -950,6 +951,23 @@ describe("USSTree Unit Tests - Function rename", () => {
getEncodingForFileMock.mockRestore();
});

it("returns early if promptedForUnsavedResource was true", async () => {
const globalMocks = createGlobalMocks();
const blockMocks = createBlockMocks(globalMocks);
blockMocks.promptedForUnsavedResource.mockReset();
blockMocks.promptedForUnsavedResource.mockResolvedValueOnce(true);
const testUSSDir = new ZoweUSSNode({
label: "test",
collapsibleState: vscode.TreeItemCollapsibleState.Expanded,
session: globalMocks.testSession,
profile: globalMocks.testProfile,
parentPath: "/",
});
const isFolderMock = jest.spyOn(SharedContext, "isFolder");
await globalMocks.testTree.rename(testUSSDir);
expect(isFolderMock).not.toHaveBeenCalled();
});

it("Tests that USSTree.rename() shows no error if an open dirty file's fullpath includes that of the node being renamed", async () => {
// Open dirty file defined by globalMocks.mockTextDocumentDirty, with filepath including "sestest/test/node"
const globalMocks = createGlobalMocks();
Expand Down

0 comments on commit 6a723d1

Please sign in to comment.