Skip to content

Commit

Permalink
fix: Pass TreeView selection when node is undefined (#3417)
Browse files Browse the repository at this point in the history
* fix: pass TreeView selection when node is undefined

Signed-off-by: Richelle Craw <[email protected]>

* fix: move node processing to USSActions

Signed-off-by: Richelle Craw <[email protected]>

---------

Signed-off-by: Richelle Craw <[email protected]>
  • Loading branch information
crawr authored Jan 31, 2025
1 parent 5c58c2e commit 96370ae
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 24 deletions.
1 change: 1 addition & 0 deletions packages/zowe-explorer/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ All notable changes to the "vscode-extension-for-zowe" extension will be documen
- Resolved user interface bug with tables that caused an inconsistent table height within the VS Code Panel. [#3389](https://github.com/zowe/zowe-explorer-vscode/pull/3389)
- Fixed an issue where opening a data set with the same starting pattern as an archived data set caused a REST API error (code 500) to appear in the editor. [#3407](https://github.com/zowe/zowe-explorer-vscode/pull/3407)
- Fixed an issue where registering new profile types from a Zowe Explorer extender could cause an internal API error on startup. [#3412](https://github.com/zowe/zowe-explorer-vscode/pull/3412)
- Fixed issue where the 'Delete' key binding for the USS tree returns a 'contextValue' error. [#2796](https://github.com/zowe/zowe-explorer-vscode/issues/2796)

## `3.0.3`

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -816,10 +816,35 @@ describe("USS Action Unit Tests - copy file / directory", () => {
});

describe("USS Action Unit Tests - function deleteUSSFilesPrompt", () => {
it("should return true", async () => {
const globalMocks = createGlobalMocks();
const testUSSTree = createUSSTree(
[createFavoriteUSSNode(globalMocks.testSession, globalMocks.testProfile)],
[createUSSNode(globalMocks.testSession, createIProfile())],
createTreeView()
);
it("should call deleteUSSNode with false if confirmed", async () => {
const testNode = createUSSNode(createISession(), createIProfile());
const nodes = [createUSSNode(createISession(), createIProfile())];
const deleteUSSNodeSpy = jest.spyOn(ZoweUSSNode.prototype, "deleteUSSNode");
jest.spyOn(Gui, "warningMessage").mockReturnValue(Promise.resolve("Delete"));
await USSActions.deleteUSSFilesPrompt(testNode, nodes, testUSSTree);
expect(deleteUSSNodeSpy).toHaveBeenCalledWith(testUSSTree,"",false);
});
it("should call deleteUSSNode with true if cancelled", async () => {
const testNode = createUSSNode(createISession(), createIProfile());
const nodes = [createUSSNode(createISession(), createIProfile())];
const deleteUSSNodeSpy = jest.spyOn(ZoweUSSNode.prototype, "deleteUSSNode");
jest.spyOn(Gui, "warningMessage").mockReturnValue(Promise.resolve("Cancel"));
await expect(USSActions.deleteUSSFilesPrompt(nodes)).resolves.toEqual(true);
await USSActions.deleteUSSFilesPrompt(testNode, nodes, testUSSTree);
expect(deleteUSSNodeSpy).toHaveBeenCalledWith(testUSSTree,"",true);
});
it("should call getTreeView if nodes are empty", async () => {
const getTreeViewSpy = jest.spyOn(testUSSTree, "getTreeView");
const deleteUSSNodeSpy = jest.spyOn(ZoweUSSNode.prototype, "deleteUSSNode");
jest.spyOn(Gui, "warningMessage").mockReturnValue(Promise.resolve("Delete"));
await USSActions.deleteUSSFilesPrompt(null, null, testUSSTree);
expect(getTreeViewSpy).toHaveBeenCalled();
expect(deleteUSSNodeSpy).toHaveBeenCalledWith(testUSSTree,"",false);
});
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,12 +83,7 @@ describe("Test src/uss/extension", () => {
},
{
name: "zowe.uss.deleteNode",
mock: [
{ spy: jest.spyOn(SharedContext, "isDocument"), arg: [test.value], ret: true },
{ spy: jest.spyOn(SharedContext, "isUssDirectory"), arg: [test.value], ret: true },
{ spy: jest.spyOn(USSActions, "deleteUSSFilesPrompt"), arg: [[test.value]], ret: false },
{ spy: jest.spyOn(test.value, "deleteUSSNode"), arg: [ussFileProvider, ""], ret: true },
],
mock: [{ spy: jest.spyOn(USSActions, "deleteUSSFilesPrompt"), arg: [test.value, undefined, ussFileProvider] }],
},
{
name: "zowe.uss.renameNode",
Expand Down
17 changes: 14 additions & 3 deletions packages/zowe-explorer/src/trees/uss/USSActions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -235,9 +235,18 @@ export class USSActions {
vscode.env.clipboard.writeText(node.fullPath);
}

public static async deleteUSSFilesPrompt(nodes: IZoweUSSTreeNode[]): Promise<boolean> {
public static async deleteUSSFilesPrompt(node: IZoweUSSTreeNode, nodeList: IZoweUSSTreeNode[], ussFileProvider: Types.IZoweUSSTreeType): Promise<void> {
ZoweLogger.trace("uss.actions.deleteUSSFilesPrompt called.");
const fileNames = nodes.reduce((label, currentVal) => {
let selectedNodes;
if (node || nodeList) {
selectedNodes = SharedUtils.getSelectedNodeList(node, nodeList) as IZoweUSSTreeNode[];
} else {
selectedNodes = ussFileProvider.getTreeView().selection;
}
selectedNodes = selectedNodes.filter(
(x) => SharedContext.isDocument(x) || SharedContext.isUssDirectory(x) || SharedContext.isBinary(x)
);
const fileNames = selectedNodes.reduce((label, currentVal) => {
return `${label}${currentVal.label.toString()}\n`;
}, "");

Expand All @@ -258,7 +267,9 @@ export class USSActions {
cancelled = true;
}
});
return cancelled;
for (const item of selectedNodes) {
await item.deleteUSSNode(ussFileProvider, "", cancelled);
}
}

/**
Expand Down
15 changes: 2 additions & 13 deletions packages/zowe-explorer/src/trees/uss/USSInit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,19 +103,8 @@ export class USSInit {
)
);
context.subscriptions.push(
vscode.commands.registerCommand("zowe.uss.deleteNode", async (node, nodeList) => {
let selectedNodes = SharedUtils.getSelectedNodeList(node, nodeList) as IZoweUSSTreeNode[];
selectedNodes = selectedNodes.filter(
(x) => SharedContext.isDocument(x) || SharedContext.isUssDirectory(x) || SharedContext.isBinary(x)
);
const cancelled = await USSActions.deleteUSSFilesPrompt(selectedNodes);
if (cancelled) {
return;
}

for (const item of selectedNodes) {
await item.deleteUSSNode(ussFileProvider, "");
}
vscode.commands.registerCommand("zowe.uss.deleteNode", async (node: IZoweUSSTreeNode, nodeList: IZoweUSSTreeNode[]) => {
await USSActions.deleteUSSFilesPrompt(node, nodeList, ussFileProvider);
})
);
context.subscriptions.push(
Expand Down

0 comments on commit 96370ae

Please sign in to comment.