Skip to content

Commit

Permalink
fix: handle trailing slashes and dismissing prompt
Browse files Browse the repository at this point in the history
Signed-off-by: Trae Yelovich <trae.yelovich@broadcom.com>
  • Loading branch information
traeok committed Oct 4, 2024
1 parent d090118 commit b907528
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 1 deletion.
26 changes: 26 additions & 0 deletions packages/zowe-explorer/__tests__/__unit__/uss/actions.unit.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,32 @@ describe("USS Action Unit Tests - Function createUSSNode", () => {
expect(refreshActions.refreshAll).not.toHaveBeenCalled();
});

it("returns early if a location was never provided", async () => {
const globalMocks = createGlobalMocks();
const blockMocks = await createBlockMocks(globalMocks);

globalMocks.mockShowInputBox.mockResolvedValueOnce(undefined);
const createApiMock = jest.spyOn(blockMocks.ussApi, "create").mockImplementation();
blockMocks.ussNode.getParent().fullPath = "";

await ussNodeActions.createUSSNode(blockMocks.ussNode.getParent(), blockMocks.testUSSTree, "directory");
expect(createApiMock).not.toHaveBeenCalled();
createApiMock.mockRestore();
});

it("handles trailing slashes in the location", async () => {
const globalMocks = createGlobalMocks();
const blockMocks = await createBlockMocks(globalMocks);

globalMocks.mockShowInputBox.mockResolvedValueOnce("/u/myuser/aDir/");
globalMocks.mockShowInputBox.mockResolvedValueOnce("testFile.txt");
const createApiMock = jest.spyOn(blockMocks.ussApi, "create").mockImplementation();

await ussNodeActions.createUSSNode(blockMocks.ussNode.getParent(), blockMocks.testUSSTree, "file");
expect(createApiMock).toHaveBeenCalledWith("/u/myuser/aDir/testFile.txt", "file");
createApiMock.mockRestore();
});

it("Tests that createUSSNode does not execute if node name was not entered", async () => {
const globalMocks = createGlobalMocks();
const blockMocks = await createBlockMocks(globalMocks);
Expand Down
7 changes: 6 additions & 1 deletion packages/zowe-explorer/src/uss/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,13 +64,18 @@ export async function createUSSNode(
} else {
filePath = node.fullPath;
}

if (filePath == null || filePath?.length === 0) {
return;
}

const nameOptions: vscode.InputBoxOptions = {
placeHolder: localize("createUSSNode.name", "Name of file or directory"),
};
const name = await Gui.showInputBox(nameOptions);
if (name && filePath) {
try {
filePath = `${filePath}/${name}`;
filePath = path.posix.join(filePath, name);
await ZoweExplorerApiRegister.getUssApi(node.getProfile()).create(filePath, nodeType);
if (isTopLevel) {
await refreshAll(ussFileProvider);
Expand Down

0 comments on commit b907528

Please sign in to comment.