Skip to content

Commit

Permalink
Fix openItemFromPath test and remove extra mock
Browse files Browse the repository at this point in the history
Signed-off-by: Timothy Johnson <[email protected]>
  • Loading branch information
t1m0thyj committed Dec 19, 2023
1 parent 9b344aa commit f859b5a
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1158,19 +1158,21 @@ describe("USSTree Unit Tests - Function openItemFromPath", () => {
const file = new ZoweUSSNode({
label: "c.txt",
collapsibleState: vscode.TreeItemCollapsibleState.Collapsed,
parentNode: globalMocks.testTree.mSessionNodes[0],
parentNode: globalMocks.testTree.mSessionNodes[1],
parentPath: "/a/b",
});
jest.spyOn(globalMocks.testTree, "getChildren").mockReturnValue(Promise.resolve([file]));
jest.spyOn(globalMocks.testTree.mSessionNodes[1], "getChildren").mockResolvedValue([file]);
const openNodeSpy = jest.spyOn(file, "openUSS").mockImplementation();

await globalMocks.testTree.openItemFromPath("/a/b/c.txt", globalMocks.testTree.mSessionNodes[1]);
expect(openNodeSpy).toHaveBeenCalledWith(false, true, globalMocks.testTree);
expect(globalMocks.testTree.getSearchHistory().includes("[sestest]: /a/b/c.txt")).toBe(true);
});

it("Tests that openItemFromPath fails when the node no longer exists", async () => {
const globalMocks = await createGlobalMocks();

jest.spyOn(globalMocks.testTree, "getChildren").mockReturnValue(Promise.resolve([]));
jest.spyOn(globalMocks.testTree.mSessionNodes[1], "getChildren").mockResolvedValue([]);
const fileHistorySpy = jest.spyOn(globalMocks.testTree, "removeFileHistory");

await globalMocks.testTree.openItemFromPath("/d.txt", globalMocks.testTree.mSessionNodes[1]);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ import {
createFileResponse,
createValidIProfile,
createInstanceOfProfile,
createTreeProviders,
} from "../../../__mocks__/mockCreators/shared";
import { ZoweExplorerApiRegister } from "../../../src/ZoweExplorerApiRegister";
import { Profiles } from "../../../src/Profiles";
Expand All @@ -40,7 +39,6 @@ import { createUssApi, bindUssApi } from "../../../__mocks__/mockCreators/api";
import * as refreshActions from "../../../src/shared/refresh";
import { ZoweLogger } from "../../../src/utils/LoggerUtils";
import { AttributeView } from "../../../src/uss/AttributeView";
import { TreeProviders } from "../../../src/shared/TreeProviders";

function createGlobalMocks() {
const globalMocks = {
Expand Down Expand Up @@ -122,7 +120,6 @@ function createGlobalMocks() {
value: globalMocks.isFileTagBinOrAscii,
configurable: true,
});
Object.defineProperty(TreeProviders, "uss", { value: createTreeProviders().uss, configurable: true });
Object.defineProperty(vscode.window, "showErrorMessage", {
value: globalMocks.showErrorMessage,
configurable: true,
Expand Down
4 changes: 2 additions & 2 deletions packages/zowe-explorer/src/uss/USSTree.ts
Original file line number Diff line number Diff line change
Expand Up @@ -908,10 +908,10 @@ export class USSTree extends ZoweTreeProvider implements IZoweTree<IZoweUSSTreeN
sessionNode.label = `${sessionNode.getProfileName()} [/${nodePath.join("/")}]`;
sessionNode.dirty = true;
this.addSearchHistory(`[${sessionNode.getProfileName()}]: /${nodePath.join("/")}`);
await sessionNode.getChildren();
const children = await sessionNode.getChildren();

// Reveal the searched item in the tree
const selectedNode: IZoweUSSTreeNode = sessionNode.children.find((elt) => elt.label === selectedNodeName);
const selectedNode: IZoweUSSTreeNode = children.find((elt) => elt.label === selectedNodeName);
if (selectedNode) {
await selectedNode.openUSS(false, true, this);
} else {
Expand Down

0 comments on commit f859b5a

Please sign in to comment.