Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue #563 More flexible way of node renaming #817

Merged
merged 13 commits into from
Jun 26, 2020
Merged
Show file tree
Hide file tree
Changes from 12 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions __tests__/__unit__/dataset/DatasetTree.unit.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import {
} from "../../../__mocks__/mockCreators/shared";
import { createDatasetSessionNode } from "../../../__mocks__/mockCreators/datasets";
import { bindMvsApi, createMvsApi } from "../../../__mocks__/mockCreators/api";
import * as workspaceUtils from "../../../src/utils/workspace";

jest.mock("fs");
jest.mock("util");
Expand All @@ -46,6 +47,8 @@ function createGlobalMocks() {
Object.defineProperty(globals, "ISTHEIA", { get: isTheia, configurable: true });
Object.defineProperty(fs, "unlinkSync", { value: jest.fn(), configurable: true });
Object.defineProperty(fs, "existsSync", { value: jest.fn(), configurable: true });
Object.defineProperty(vscode.commands, "executeCommand", { value: jest.fn(), configurable: true });
Object.defineProperty(workspaceUtils, "closeOpenedTextFile", { value: jest.fn(), configurable: true });
Object.defineProperty(vscode, "ProgressLocation", {
value: jest.fn().mockImplementation(() => {
return {
Expand Down Expand Up @@ -1056,6 +1059,7 @@ describe("Dataset Tree Unit Tests - Function rename", () => {
createGlobalMocks();
const blockMocks = createBlockMocks();

mocked(workspaceUtils.closeOpenedTextFile).mockResolvedValueOnce(false);
mocked(vscode.window.showInputBox).mockResolvedValueOnce("HLQ.TEST.RENAME.NODE.NEW");
mocked(vscode.window.createTreeView).mockReturnValueOnce(blockMocks.treeView);
const testTree = new DatasetTree();
Expand All @@ -1072,6 +1076,7 @@ describe("Dataset Tree Unit Tests - Function rename", () => {
createGlobalMocks();
const blockMocks = createBlockMocks();

mocked(workspaceUtils.closeOpenedTextFile).mockResolvedValueOnce(false);
mocked(vscode.window.showInputBox).mockResolvedValueOnce("HLQ.TEST.RENAME.NODE.NEW");
mocked(vscode.window.createTreeView).mockReturnValueOnce(blockMocks.treeView);
const testTree = new DatasetTree();
Expand All @@ -1091,6 +1096,7 @@ describe("Dataset Tree Unit Tests - Function rename", () => {
const blockMocks = createBlockMocks();
const defaultError = new Error("Default error message");

mocked(workspaceUtils.closeOpenedTextFile).mockResolvedValueOnce(false);
mocked(zowe.Rename.dataSet).mockImplementation(() => {
throw defaultError;
});
Expand All @@ -1116,6 +1122,7 @@ describe("Dataset Tree Unit Tests - Function rename", () => {
createGlobalMocks();
const blockMocks = createBlockMocks();

mocked(workspaceUtils.closeOpenedTextFile).mockResolvedValueOnce(false);
mocked(vscode.window.showInputBox).mockResolvedValueOnce("mem2");
mocked(vscode.window.createTreeView).mockReturnValueOnce(blockMocks.treeView);
const testTree = new DatasetTree();
Expand All @@ -1135,6 +1142,7 @@ describe("Dataset Tree Unit Tests - Function rename", () => {
createGlobalMocks();
const blockMocks = createBlockMocks();

mocked(workspaceUtils.closeOpenedTextFile).mockResolvedValueOnce(false);
mocked(vscode.window.showInputBox).mockResolvedValueOnce("mem2");
mocked(vscode.window.createTreeView).mockReturnValueOnce(blockMocks.treeView);
const testTree = new DatasetTree();
Expand All @@ -1156,6 +1164,7 @@ describe("Dataset Tree Unit Tests - Function rename", () => {
const blockMocks = createBlockMocks();
const defaultError = new Error("Default error message");

mocked(workspaceUtils.closeOpenedTextFile).mockResolvedValueOnce(false);
mocked(zowe.Rename.dataSetMember).mockImplementation(() => {
throw defaultError;
});
Expand Down
63 changes: 45 additions & 18 deletions __tests__/__unit__/uss/USSTree.unit.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,18 @@ import { createUSSTree, USSTree } from "../../../src/uss/USSTree";
import { ZoweUSSNode } from "../../../src/uss/ZoweUSSNode";
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks like all changes in this file are related to formatting. Perhaps it is time, that we implement prettier #815

import { Logger, IProfileLoaded } from "@zowe/imperative";
import * as utils from "../../../src/utils";
import { createIProfile, createISession, createISessionWithoutCredentials, createFileResponse } from "../../../__mocks__/mockCreators/shared";
import {
createIProfile,
createISession,
createISessionWithoutCredentials,
createFileResponse
} from "../../../__mocks__/mockCreators/shared";
import * as globals from "../../../src/globals";
import * as vscode from "vscode";
import * as zowe from "@zowe/cli";
import { createUSSNode, createFavoriteUSSNode, createUSSSessionNode } from "../../../__mocks__/mockCreators/uss";
import { getIconByNode } from "../../../src/generators/icons";
import * as workspaceUtils from "../../../src/utils/workspace";

async function createGlobalMocks() {
const globalMocks = {
Expand All @@ -40,32 +46,49 @@ async function createGlobalMocks() {
ZosmfSession: jest.fn(),
createBasicZosmfSession: jest.fn(),
withProgress: jest.fn(),
closeOpenedTextFile: jest.fn(),
ProgressLocation: jest.fn().mockImplementation(() => {
return {
Notification: 15
};
}),
testProfile: createIProfile(),
testSession: createISession(),
testResponse: createFileResponse({items: []}),
testResponse: createFileResponse({ items: [] }),
testUSSNode: null,
testTree: null,
profilesForValidation: {status: "active", name: "fake"},
};

Object.defineProperty(workspaceUtils, "closeOpenedTextFile", {
value: globalMocks.closeOpenedTextFile,
configurable: true
});
Object.defineProperty(vscode.window, "createTreeView", { value: globalMocks.createTreeView, configurable: true });
Object.defineProperty(vscode.commands, "executeCommand", { value: globalMocks.executeCommand, configurable: true });
Object.defineProperty(globalMocks.Utilities, "renameUSSFile", { value: globalMocks.renameUSSFile, configurable: true });
Object.defineProperty(globalMocks.Utilities, "renameUSSFile", {
value: globalMocks.renameUSSFile,
configurable: true
});
Object.defineProperty(vscode.window, "showQuickPick", { value: globalMocks.showQuickPick, configurable: true });
Object.defineProperty(vscode.window, "showInformationMessage", { value: globalMocks.showInformationMessage, configurable: true });
Object.defineProperty(vscode.window, "showInformationMessage", {
value: globalMocks.showInformationMessage,
configurable: true
});
Object.defineProperty(globalMocks.ZosmfSession, "createBasicZosmfSession",
{ value: globalMocks.createBasicZosmfSession, configurable: true });
Object.defineProperty(zowe, "ZosmfSession", { value: globalMocks.ZosmfSession, configurable: true });
Object.defineProperty(globalMocks.filters, "getFilters", { value: globalMocks.getFilters, configurable: true });
Object.defineProperty(vscode.window, "createQuickPick", { value: globalMocks.createQuickPick, configurable: true });
Object.defineProperty(zowe, "Utilities", { value: globalMocks.Utilities, configurable: true });
Object.defineProperty(vscode.window, "showErrorMessage", { value: globalMocks.showErrorMessage, configurable: true });
Object.defineProperty(vscode.workspace, "getConfiguration", { value: globalMocks.getConfiguration, configurable: true });
Object.defineProperty(vscode.window, "showErrorMessage", {
value: globalMocks.showErrorMessage,
configurable: true
});
Object.defineProperty(vscode.workspace, "getConfiguration", {
value: globalMocks.getConfiguration,
configurable: true
});
Object.defineProperty(vscode.window, "showInputBox", { value: globalMocks.showInputBox, configurable: true });
Object.defineProperty(vscode, "ProgressLocation", { value: globalMocks.ProgressLocation, configurable: true });
Object.defineProperty(vscode.window, "withProgress", { value: globalMocks.withProgress, configurable: true });
Expand Down Expand Up @@ -96,7 +119,7 @@ async function createGlobalMocks() {
"[test]: /u/aDir{directory}",
"[test]: /u/myFile.txt{textFile}",
],
update: jest.fn(()=>{
update: jest.fn(() => {
return {};
})
});
Expand Down Expand Up @@ -198,7 +221,8 @@ describe("USSTree Unit Tests - Function USSTree.rename()", () => {
try {
await globalMocks.testTree.rename(globalMocks.testUSSNode);
// tslint:disable-next-line:no-empty
} catch (err) { }
} catch (err) {
}
expect(globalMocks.showErrorMessage.mock.calls.length).toBe(1);
});

Expand Down Expand Up @@ -282,7 +306,7 @@ describe("USSTree Unit Tests - Function USSTree.removeFavorite()", () => {
async function createBlockMocks(globalMocks) {
const newMocks = {
testDir: new ZoweUSSNode("testDir", vscode.TreeItemCollapsibleState.Collapsed,
globalMocks.testTree.mSessionNodes[1], null, "/")
globalMocks.testTree.mSessionNodes[1], null, "/")
};
globalMocks.testTree.mFavorites = [newMocks.testDir];

Expand Down Expand Up @@ -330,7 +354,7 @@ describe("USSTree Unit Tests - Function USSTree.addSession()", () => {
const globalMocks = await createGlobalMocks();

const testSessionNode = new ZoweUSSNode("testSessionNode", vscode.TreeItemCollapsibleState.Collapsed,
null, globalMocks.testSession, null);
null, globalMocks.testSession, null);
globalMocks.testTree.mSessionNodes.push(testSessionNode);
globalMocks.testTree.addSession("testSessionNode");

Expand Down Expand Up @@ -382,13 +406,13 @@ describe("USSTree Unit Tests - Function USSTree.filterPrompt()", () => {
ignoreFocusOut: true,
items: [newMocks.qpItem],
value: newMocks.qpValue,
show: jest.fn(()=>{
show: jest.fn(() => {
return {};
}),
hide: jest.fn(()=>{
hide: jest.fn(() => {
return {};
}),
onDidAccept: jest.fn(()=>{
onDidAccept: jest.fn(() => {
return {};
})
});
Expand Down Expand Up @@ -509,7 +533,9 @@ describe("USSTree Unit Tests - Function USSTree.filterPrompt()", () => {

await globalMocks.testTree.filterPrompt(dsNode);
globalMocks.testTree.mSessionNodes.forEach((sessionNode) => {
if (sessionNode === dsNode) { expect(sessionNode.fullPath).toEqual("/u/myFile.txt"); }
if (sessionNode === dsNode) {
expect(sessionNode.fullPath).toEqual("/u/myFile.txt");
}
});
});
});
Expand Down Expand Up @@ -617,7 +643,8 @@ describe("USSTree Unit Tests - Function USSTree.getChildren()", () => {
try {
await globalMocks.testTree.rename(globalMocks.testUSSNode);
// tslint:disable-next-line:no-empty
} catch (err) { }
} catch (err) {
}
expect(globalMocks.showErrorMessage.mock.calls.length).toBe(1);
});

Expand Down Expand Up @@ -744,7 +771,7 @@ describe("USSTree Unit Tests - Function USSTree.addSession()", () => {
const globalMocks = await createGlobalMocks();

const testSessionNode = new ZoweUSSNode("testSessionNode", vscode.TreeItemCollapsibleState.Collapsed,
null, globalMocks.testSession, null);
null, globalMocks.testSession, null);
globalMocks.testTree.mSessionNodes.push(testSessionNode);
globalMocks.testTree.addSession("testSessionNode");

Expand Down Expand Up @@ -786,7 +813,7 @@ describe("USSTree Unit Tests - Function USSTree.deleteSession()", () => {
const globalMocks = await createGlobalMocks();

const testDir = new ZoweUSSNode("testDir", vscode.TreeItemCollapsibleState.Collapsed,
globalMocks.testTree.mSessionNodes[1], null, "test");
globalMocks.testTree.mSessionNodes[1], null, "test");
globalMocks.testTree.mSessionNodes[1].children.push(testDir);
const mockApiResponseItems = {
items: [{
Expand All @@ -807,7 +834,7 @@ describe("USSTree Unit Tests - Function USSTree.deleteSession()", () => {
const globalMocks = await createGlobalMocks();

globalMocks.testTree.mFavorites.push(new ZoweUSSNode("/u/myUser", vscode.TreeItemCollapsibleState.None,
globalMocks.testTree.mSessionNodes[0], null, null));
globalMocks.testTree.mSessionNodes[0], null, null));
const favChildren = await globalMocks.testTree.getChildren(globalMocks.testTree.mSessionNodes[0]);
const sampleChildren: ZoweUSSNode[] = [
new ZoweUSSNode("/u/myUser", vscode.TreeItemCollapsibleState.None, globalMocks.testTree.mSessionNodes[0], null, null)
Expand Down
Loading