Skip to content

Commit

Permalink
Merge branch 'master' of github.com:zowe/vscode-extension-for-zowe
Browse files Browse the repository at this point in the history
  • Loading branch information
lauren-li committed Jun 25, 2019
2 parents 1cd17e9 + ef7ed1f commit 4a0f4eb
Show file tree
Hide file tree
Showing 3 changed files with 122 additions and 24 deletions.
91 changes: 68 additions & 23 deletions __tests__/extension.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -389,7 +389,7 @@ describe("Extension Unit Tests", () => {
getChildren: mockGetUSSChildren,
}
});
expect(registerCommand.mock.calls.length).toBe(47);
expect(registerCommand.mock.calls.length).toBe(48);
expect(registerCommand.mock.calls[0][0]).toBe("zowe.addSession");
expect(registerCommand.mock.calls[0][1]).toBeInstanceOf(Function);
expect(registerCommand.mock.calls[1][0]).toBe("zowe.addFavorite");
Expand Down Expand Up @@ -440,50 +440,52 @@ describe("Extension Unit Tests", () => {
expect(registerCommand.mock.calls[23][1]).toBeInstanceOf(Function);
expect(registerCommand.mock.calls[24][0]).toBe("zowe.uss.refreshUSS");
expect(registerCommand.mock.calls[24][1]).toBeInstanceOf(Function);
expect(registerCommand.mock.calls[25][0]).toBe("zowe.uss.fullPath");
expect(registerCommand.mock.calls[25][0]).toBe("zowe.uss.safeSaveUSS");
expect(registerCommand.mock.calls[25][1]).toBeInstanceOf(Function);
expect(registerCommand.mock.calls[26][0]).toBe("zowe.uss.ZoweUSSNode.open");
expect(registerCommand.mock.calls[26][0]).toBe("zowe.uss.fullPath");
expect(registerCommand.mock.calls[26][1]).toBeInstanceOf(Function);
expect(registerCommand.mock.calls[27][0]).toBe("zowe.uss.removeSession");
expect(registerCommand.mock.calls[27][0]).toBe("zowe.uss.ZoweUSSNode.open");
expect(registerCommand.mock.calls[27][1]).toBeInstanceOf(Function);
expect(registerCommand.mock.calls[28][0]).toBe("zowe.uss.createFile");
expect(registerCommand.mock.calls[28][0]).toBe("zowe.uss.removeSession");
expect(registerCommand.mock.calls[28][1]).toBeInstanceOf(Function);
expect(registerCommand.mock.calls[29][0]).toBe("zowe.uss.createFolder");
expect(registerCommand.mock.calls[29][0]).toBe("zowe.uss.createFile");
expect(registerCommand.mock.calls[29][1]).toBeInstanceOf(Function);
expect(registerCommand.mock.calls[30][0]).toBe("zowe.uss.deleteNode");
expect(registerCommand.mock.calls[30][0]).toBe("zowe.uss.createFolder");
expect(registerCommand.mock.calls[30][1]).toBeInstanceOf(Function);
expect(registerCommand.mock.calls[31][0]).toBe("zowe.uss.binary");
expect(registerCommand.mock.calls[31][0]).toBe("zowe.uss.deleteNode");
expect(registerCommand.mock.calls[31][1]).toBeInstanceOf(Function);
expect(registerCommand.mock.calls[32][0]).toBe("zowe.uss.text");
expect(registerCommand.mock.calls[32][0]).toBe("zowe.uss.binary");
expect(registerCommand.mock.calls[32][1]).toBeInstanceOf(Function);
expect(registerCommand.mock.calls[33][0]).toBe("zowe.uss.renameNode");
expect(registerCommand.mock.calls[33][0]).toBe("zowe.uss.text");
expect(registerCommand.mock.calls[33][1]).toBeInstanceOf(Function);
expect(registerCommand.mock.calls[34][0]).toBe("zowe.zosJobsOpenspool");
expect(registerCommand.mock.calls[34][0]).toBe("zowe.uss.renameNode");
expect(registerCommand.mock.calls[34][1]).toBeInstanceOf(Function);
expect(registerCommand.mock.calls[35][0]).toBe("zowe.deleteJob");
expect(registerCommand.mock.calls[35][0]).toBe("zowe.zosJobsOpenspool");
expect(registerCommand.mock.calls[35][1]).toBeInstanceOf(Function);
expect(registerCommand.mock.calls[36][0]).toBe("zowe.runModifyCommand");
expect(registerCommand.mock.calls[36][0]).toBe("zowe.deleteJob");
expect(registerCommand.mock.calls[36][1]).toBeInstanceOf(Function);
expect(registerCommand.mock.calls[37][0]).toBe("zowe.runStopCommand");
expect(registerCommand.mock.calls[37][0]).toBe("zowe.runModifyCommand");
expect(registerCommand.mock.calls[37][1]).toBeInstanceOf(Function);
expect(registerCommand.mock.calls[38][0]).toBe("zowe.refreshJobsServer");
expect(registerCommand.mock.calls[38][0]).toBe("zowe.runStopCommand");
expect(registerCommand.mock.calls[38][1]).toBeInstanceOf(Function);
expect(registerCommand.mock.calls[39][0]).toBe("zowe.refreshAllJobs");
expect(registerCommand.mock.calls[39][0]).toBe("zowe.refreshJobsServer");
expect(registerCommand.mock.calls[39][1]).toBeInstanceOf(Function);
expect(registerCommand.mock.calls[40][0]).toBe("zowe.addJobsSession");
expect(registerCommand.mock.calls[40][0]).toBe("zowe.refreshAllJobs");
expect(registerCommand.mock.calls[40][1]).toBeInstanceOf(Function);
expect(registerCommand.mock.calls[41][0]).toBe("zowe.setOwner");
expect(registerCommand.mock.calls[41][0]).toBe("zowe.addJobsSession");
expect(registerCommand.mock.calls[41][1]).toBeInstanceOf(Function);
expect(registerCommand.mock.calls[42][0]).toBe("zowe.setPrefix");
expect(registerCommand.mock.calls[42][0]).toBe("zowe.setOwner");
expect(registerCommand.mock.calls[42][1]).toBeInstanceOf(Function);
expect(registerCommand.mock.calls[43][0]).toBe("zowe.removeJobsSession");
expect(registerCommand.mock.calls[43][0]).toBe("zowe.setPrefix");
expect(registerCommand.mock.calls[43][1]).toBeInstanceOf(Function);
expect(registerCommand.mock.calls[44][0]).toBe("zowe.downloadSpool");
expect(registerCommand.mock.calls[44][0]).toBe("zowe.removeJobsSession");
expect(registerCommand.mock.calls[44][1]).toBeInstanceOf(Function);
expect(registerCommand.mock.calls[45][0]).toBe("zowe.getJobJcl");
expect(registerCommand.mock.calls[45][0]).toBe("zowe.downloadSpool");
expect(registerCommand.mock.calls[45][1]).toBeInstanceOf(Function);
expect(registerCommand.mock.calls[46][0]).toBe("zowe.setJobSpool");
expect(registerCommand.mock.calls[46][0]).toBe("zowe.getJobJcl");
expect(registerCommand.mock.calls[46][1]).toBeInstanceOf(Function);
expect(registerCommand.mock.calls[47][0]).toBe("zowe.setJobSpool");
expect(registerCommand.mock.calls[47][1]).toBeInstanceOf(Function);
expect(onDidSaveTextDocument.mock.calls.length).toBe(1);
expect(existsSync.mock.calls.length).toBe(3);
expect(existsSync.mock.calls[0][0]).toBe(extension.BRIGHTTEMPFOLDER);
Expand Down Expand Up @@ -1249,6 +1251,49 @@ describe("Extension Unit Tests", () => {
expect(showErrorMessage.mock.calls[0][0]).toEqual("safeSave() called from invalid node.");
});

it("Testing that safeSaveUSS is executed successfully", async () => {
ussFile.mockReset();
openTextDocument.mockReset();
showTextDocument.mockReset();
showInformationMessage.mockReset();
save.mockReset();

const node = new ZoweUSSNode("node", vscode.TreeItemCollapsibleState.None, ussNode, null, null);
const parent = new ZoweUSSNode("parent", vscode.TreeItemCollapsibleState.Collapsed, ussNode, null, null);
const child = new ZoweUSSNode("child", vscode.TreeItemCollapsibleState.None, parent, null, null);

openTextDocument.mockResolvedValueOnce("test");

await extension.safeSaveUSS(node);

expect(ussFile.mock.calls.length).toBe(1);
expect(ussFile.mock.calls[0][0]).toBe(node.getSession());
expect(ussFile.mock.calls[0][1]).toBe(node.fullPath);
expect(ussFile.mock.calls[0][2]).toEqual({file: extension.getUSSDocumentFilePath(node)});
expect(openTextDocument.mock.calls.length).toBe(1);
expect(openTextDocument.mock.calls[0][0]).toBe(path.join(extension.getUSSDocumentFilePath(node)));
expect(showTextDocument.mock.calls.length).toBe(1);
expect(showTextDocument.mock.calls[0][0]).toBe("test");
expect(save.mock.calls.length).toBe(1);

ussFile.mockReset();
ussFile.mockRejectedValueOnce(Error("not found"));

await extension.safeSaveUSS(node);

expect(showInformationMessage.mock.calls.length).toBe(1);
expect(showInformationMessage.mock.calls[0][0]).toBe("Unable to find file: " + node.fullPath + " was probably deleted.");

ussFile.mockReset();
showErrorMessage.mockReset();
ussFile.mockRejectedValueOnce(Error(""));

await extension.safeSaveUSS(child);

expect(showErrorMessage.mock.calls.length).toBe(1);
expect(showErrorMessage.mock.calls[0][0]).toEqual("");
});

it("Testing that refreshUSS correctly executes with and without error", async () => {
const node = new ZoweUSSNode("node", vscode.TreeItemCollapsibleState.None, ussNode, null, null);
const parent = new ZoweUSSNode("parent", vscode.TreeItemCollapsibleState.Collapsed, ussNode, null, null);
Expand Down
22 changes: 22 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,14 @@
"command": "zowe.uss.removeSession",
"title": "Remove Profile"
},
{
"command": "zowe.uss.safeSaveUSS",
"title": "Safe Save - Merge if Necessary",
"icon": {
"light": "./resources/light/upload.svg",
"dark": "./resources/dark/upload.svg"
}
},
{
"command": "zowe.uss.binary",
"title": "Toggle Binary"
Expand Down Expand Up @@ -365,6 +373,16 @@
"command": "zowe.uss.removeFavorite",
"group": "navigation"
},
{
"when": "view == zowe.uss.explorer && viewItem != favorite && viewItem != uss_session && viewItem != directory && viewItem != directoryf",
"command": "zowe.uss.refreshUSS",
"group": "inline"
},
{
"when": "view == zowe.uss.explorer && viewItem != favorite && viewItem != uss_session && viewItem != directory && viewItem != directoryf",
"command": "zowe.uss.safeSaveUSS",
"group": "inline"
},
{
"when": "view == zowe.uss.explorer && viewItem != uss_session && viewItem != favorite && viewItem != textFilef && viewItem != binaryFilef && viewItem != directoryf",
"command": "zowe.uss.deleteNode",
Expand Down Expand Up @@ -663,6 +681,10 @@
"command": "zowe.uss.refreshUSS",
"when": "never"
},
{
"command": "zowe.uss.safeSaveUSS",
"when": "never"
},
{
"command": "zowe.uss.removeSession",
"when": "never"
Expand Down
33 changes: 32 additions & 1 deletion src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@ export async function activate(context: vscode.ExtensionContext) {
vscode.commands.registerCommand("zowe.uss.addSession", async () => addUSSSession(ussFileProvider));
vscode.commands.registerCommand("zowe.uss.refreshAll", () => refreshAllUSS(ussFileProvider));
vscode.commands.registerCommand("zowe.uss.refreshUSS", (node) => refreshUSS(node));
vscode.commands.registerCommand("zowe.uss.safeSaveUSS", async (node) => safeSaveUSS(node));
vscode.commands.registerCommand("zowe.uss.fullPath", (node) => enterUSSPattern(node, ussFileProvider));
vscode.commands.registerCommand("zowe.uss.ZoweUSSNode.open", (node) => openUSS(node));
vscode.commands.registerCommand("zowe.uss.removeSession", async (node) => ussFileProvider.deleteSession(node));
Expand Down Expand Up @@ -1043,6 +1044,9 @@ export async function refreshPS(node: ZoweNode) {
export async function refreshUSS(node: ZoweUSSNode) {
let label;
switch (node.mParent.contextValue) {
case ("directoryf"):
label = node.fullPath;
break;
case ("directory"):
label = node.fullPath;
break;
Expand Down Expand Up @@ -1077,7 +1081,7 @@ export async function refreshUSS(node: ZoweUSSNode) {
* Checks if there are changes on the mainframe before pushing changes
*
* @export
* @param {ZoweNode} node
* @param {ZoweNode} node The node which represents the dataset
*/
export async function safeSave(node: ZoweNode) {

Expand Down Expand Up @@ -1116,6 +1120,33 @@ export async function safeSave(node: ZoweNode) {
}
}

/**
* Checks if there are changes on the mainframe before pushing changes
*
* @export
* @param {ZoweUSSNode} node The node which represents the file
*/
export async function safeSaveUSS(node: ZoweUSSNode) {

log.debug("safe save requested for node: " + node.mLabel);
try {
// Switch case from `safeSave` not needed, as we will only ever receive a file
log.debug("Invoking safesave for USS file " + node.fullPath);
await zowe.Download.ussFile(node.getSession(), node.fullPath, {
file: getUSSDocumentFilePath(node)
});
const document = await vscode.workspace.openTextDocument(getUSSDocumentFilePath(node));
await vscode.window.showTextDocument(document);
await vscode.window.activeTextEditor.document.save();
} catch (err) {
if (err.message.includes("not found")) {
vscode.window.showInformationMessage(`Unable to find file: ${node.fullPath} was probably deleted.`);
} else {
vscode.window.showErrorMessage(err.message);
}
}
}

/**
* Uploads the file to the mainframe
*
Expand Down

0 comments on commit 4a0f4eb

Please sign in to comment.