Skip to content

Commit

Permalink
Merge pull request #492 from zowe/fix_issue_485
Browse files Browse the repository at this point in the history
Fix issue 485
  • Loading branch information
Colin-Stone committed Feb 7, 2020
2 parents 062c22f + bd3e191 commit 438e763
Show file tree
Hide file tree
Showing 10 changed files with 125 additions and 86 deletions.
46 changes: 16 additions & 30 deletions __tests__/__integration__/extension.integration.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -250,14 +250,11 @@ describe("Extension Integration Tests", () => {
expect(testTree.mSessionNodes[1].tooltip).to.equal(pattern);
expect(testTree.mSessionNodes[1].collapsibleState).to.equal(vscode.TreeItemCollapsibleState.Expanded);

const testTreeView = vscode.window.createTreeView("zowe.explorer", {treeDataProvider: testTree});

const childrenFromTree = await sessionNode.getChildren();
childrenFromTree.unshift(...(await childrenFromTree[0].getChildren()));

await testTreeView.reveal(childrenFromTree[0]);
expect(childrenFromTree[0]).to.deep.equal(testTreeView.selection[0]);

await testTree.getTreeView().reveal(childrenFromTree[0]);
expect(childrenFromTree[0]).to.deep.equal(testTree.getTreeView().selection[0]);
}).timeout(TIMEOUT);

it("should match data sets for multiple patterns", async () => {
Expand All @@ -271,14 +268,12 @@ describe("Extension Integration Tests", () => {
expect(testTree.mSessionNodes[1].tooltip).to.equal(search.toUpperCase());
expect(testTree.mSessionNodes[1].collapsibleState).to.equal(vscode.TreeItemCollapsibleState.Expanded);

const testTreeView = vscode.window.createTreeView("zowe.explorer", {treeDataProvider: testTree});

const sessionChildren = await sessionNode.getChildren();
const childrenFromTree = await getAllNodes(sessionChildren);

for (const child of childrenFromTree) {
await testTreeView.reveal(child);
expect(child).to.deep.equal(testTreeView.selection[0]);
await testTree.getTreeView().reveal(child);
expect(child).to.deep.equal(testTree.getTreeView().selection[0]);
}
}).timeout(TIMEOUT);

Expand All @@ -303,8 +298,6 @@ describe("Extension Integration Tests", () => {
expect(testTree.mSessionNodes[1].tooltip).to.equal(searchPattern.toUpperCase());
expect(testTree.mSessionNodes[1].collapsibleState).to.equal(vscode.TreeItemCollapsibleState.Expanded);

const testTreeView = vscode.window.createTreeView("zowe.explorer", {treeDataProvider: testTree});

const childrenFromTree = await sessionNode.getChildren();
expect(childrenFromTree[0].children).to.deep.equal([]);

Expand Down Expand Up @@ -920,18 +913,14 @@ describe("Extension Integration Tests - USS", () => {
// Initialize uss file provider
const ussFileProvider = new USSTree();

// Create the TreeView using ussFileProvider to create tree structure
const ussTestTreeView = vscode.window.createTreeView("zowe.uss.explorer", {treeDataProvider: ussFileProvider});

const nonFavorites = ussFileProvider.mSessionNodes.filter((node) => node.contextValue !== extension.FAVORITE_CONTEXT );
const allNodes = await getAllUSSNodes(nonFavorites);
for (const node of allNodes) {
// For each node, select that node in TreeView by calling reveal()
await ussTestTreeView.reveal(node);
await ussFileProvider.getTreeView().reveal(node);
// Test that the node is successfully selected
expect(node).to.deep.equal(ussTestTreeView.selection[0]);
expect(node).to.deep.equal(ussFileProvider.getTreeView().selection[0]);
}
ussTestTreeView.dispose();
}).timeout(TIMEOUT);
});

Expand Down Expand Up @@ -980,25 +969,25 @@ describe("Extension Integration Tests - USS", () => {

describe("Enter USS Pattern", () => {
it("should output path that match the user-provided path", async () => {
const ussTestTree1 = new USSTree();
ussTestTree1.mSessionNodes.splice(-1, 0, ussSessionNode);
const inputBoxStub2 = sandbox.stub(vscode.window, "showInputBox");
inputBoxStub2.returns(fullUSSPath);
const stubresolve = sandbox.stub(utils, "resolveQuickPickHelper");
stubresolve.returns(new utils.FilterItem(fullUSSPath));

await ussTestTree.ussFilterPrompt(ussSessionNode);

expect(ussTestTree.mSessionNodes[0].fullPath).to.equal(fullUSSPath);
expect(ussTestTree.mSessionNodes[0].tooltip).to.equal(fullUSSPath);
expect(ussTestTree.mSessionNodes[0].collapsibleState).to.equal(vscode.TreeItemCollapsibleState.Expanded);
await ussTestTree1.ussFilterPrompt(ussSessionNode);

const ussTestTreeView = vscode.window.createTreeView("zowe.uss.explorer", {treeDataProvider: ussTestTree});
expect(ussTestTree1.mSessionNodes[0].fullPath).to.equal(fullUSSPath);
expect(ussTestTree1.mSessionNodes[0].tooltip).to.equal(fullUSSPath);
expect(ussTestTree1.mSessionNodes[0].collapsibleState).to.equal(vscode.TreeItemCollapsibleState.Expanded);

const childrenFromTree = await ussSessionNode.getChildren();
childrenFromTree.unshift(...(await childrenFromTree[0].getChildren()));

for (const child of childrenFromTree) {
await ussTestTreeView.reveal(child);
expect(child).to.deep.equal(ussTestTreeView.selection[0]);
await ussTestTree1.getTreeView().reveal(child);
expect(child).to.deep.equal(ussTestTree1.getTreeView().selection[0]);
}
}).timeout(TIMEOUT);

Expand Down Expand Up @@ -1060,17 +1049,14 @@ describe("TreeView", () => {
it("should create the TreeView", async () => {
// Initialize dataset provider
const datasetProvider = new DatasetTree();
// Create the TreeView using datasetProvider to create tree structure
const testTreeView = vscode.window.createTreeView("zowe.explorer", {treeDataProvider: datasetProvider});

const allNodes = await getAllNodes(datasetProvider.mSessionNodes);
for (const node of allNodes) {
// For each node, select that node in TreeView by calling reveal()
await testTreeView.reveal(node);
await datasetProvider.getTreeView().reveal(node);
// Test that the node is successfully selected
expect(node).to.deep.equal(testTreeView.selection[0]);
expect(node).to.deep.equal(datasetProvider.getTreeView().selection[0]);
}
testTreeView.dispose();
}).timeout(TIMEOUT);
});

Expand Down
4 changes: 4 additions & 0 deletions __tests__/__unit__/DatasetTree.unit.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ describe("DatasetTree Unit Tests", () => {
const filters = jest.fn();
const getFilters = jest.fn();
const createQuickPick = jest.fn();
const createTreeView = jest.fn();
const createBasicZosmfSession = jest.fn();
const ZosmfSession = jest.fn();
Object.defineProperty(zowe, "ZosmfSession", { value: ZosmfSession });
Expand All @@ -71,11 +72,13 @@ describe("DatasetTree Unit Tests", () => {
Object.defineProperty(vscode.window, "showErrorMessage", {value: showErrorMessage});
Object.defineProperty(vscode.window, "showQuickPick", {value: showQuickPick});
Object.defineProperty(vscode.window, "showInputBox", {value: showInputBox});
Object.defineProperty(vscode.window, "createTreeView", {value: createTreeView});
Object.defineProperty(filters, "getFilters", { value: getFilters });
Object.defineProperty(vscode.window, "createQuickPick", {value: createQuickPick});
Object.defineProperty(vscode, "ProgressLocation", {value: ProgressLocation});
Object.defineProperty(vscode.window, "withProgress", {value: withProgress});
getFilters.mockReturnValue(["HLQ", "HLQ.PROD1"]);
createTreeView.mockReturnValue("testTreeView");
const getConfiguration = jest.fn();
Object.defineProperty(vscode.workspace, "getConfiguration", { value: getConfiguration });
getConfiguration.mockReturnValue({
Expand Down Expand Up @@ -141,6 +144,7 @@ describe("DatasetTree Unit Tests", () => {
*************************************************************************************************************/
it("Testing that the dataset tree is defined", async () => {
expect(testTree.mSessionNodes).toBeDefined();
expect(testTree.getTreeView()).toEqual("testTreeView");
});

/*************************************************************************************************************
Expand Down
4 changes: 4 additions & 0 deletions __tests__/__unit__/USSTree.unit.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ describe("Unit Tests (Jest)", () => {
const showInformationMessage = jest.fn();
const showInputBox = jest.fn();
const createQuickPick = jest.fn();
const createTreeView = jest.fn();
const showQuickPick = jest.fn();
const filters = jest.fn();
const getFilters = jest.fn();
Expand All @@ -79,7 +80,9 @@ describe("Unit Tests (Jest)", () => {
Object.defineProperty(filters, "getFilters", { value: getFilters });
Object.defineProperty(vscode, "ProgressLocation", {value: ProgressLocation});
Object.defineProperty(vscode.window, "withProgress", {value: withProgress});
Object.defineProperty(vscode.window, "createTreeView", {value: createTreeView});
getFilters.mockReturnValue(["/u/aDir{directory}", "/u/myFile.txt{textFile}"]);
createTreeView.mockReturnValue("testTreeView");

const testTree = new USSTree();
const profileOne: IProfileLoaded = {
Expand Down Expand Up @@ -142,6 +145,7 @@ describe("Unit Tests (Jest)", () => {
*************************************************************************************************************/
it("Testing that the uss tree is defined", async () => {
expect(testTree.mSessionNodes).toBeDefined();
expect(testTree.getTreeView()).toEqual("testTreeView");
});

/*************************************************************************************************************
Expand Down
7 changes: 7 additions & 0 deletions __tests__/__unit__/ZoweJobNode.unit.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,10 @@ describe("Zos Jobs Unit Tests", () => {
const GetJobs = jest.fn();
const getConfiguration = jest.fn();
const showErrorMessage = jest.fn();
const createTreeView = jest.fn();
Object.defineProperty(vscode.workspace, "getConfiguration", { value: getConfiguration });
Object.defineProperty(vscode.window, "showErrorMessage", {value: showErrorMessage});
Object.defineProperty(vscode.window, "createTreeView", {value: createTreeView});
getConfiguration.mockReturnValue({
get: (setting: string) => [
"[test]: Owner:stonecc Prefix:*{server}",
Expand All @@ -37,6 +39,7 @@ describe("Zos Jobs Unit Tests", () => {
return {};
})
});
createTreeView.mockReturnValue("testTreeView");

const enums = jest.fn().mockImplementation(() => {
return {
Expand Down Expand Up @@ -232,6 +235,10 @@ describe("Zos Jobs Unit Tests", () => {
expect(testJobsProvider.mSessionNodes[sessions].tooltip).toEqual("fake - owner: prefix: *");
});

it("tests that the TreeView is created successfully", async () => {
const testJobsProvider = await createJobsTree(Logger.getAppLogger());
});

it("tests that the user is informed when a job is deleted", async () => {
showInformationMessage.mockReset();
const testJobsProvider = await createJobsTree(Logger.getAppLogger());
Expand Down
41 changes: 33 additions & 8 deletions __tests__/__unit__/extension.unit.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -147,12 +147,14 @@ describe("Extension Unit Tests", () => {
const mkdirSync = jest.fn();
const moveSync = jest.fn();
const getAllProfileNames = jest.fn();
const createTreeView = jest.fn();
const reveal = jest.fn();
const mockReveal = jest.fn();
const createWebviewPanel = jest.fn();
const createTreeView = jest.fn();
const pathMock = jest.fn();
const registerCommand = jest.fn();
const onDidSaveTextDocument = jest.fn();
const onDidChangeSelection = jest.fn();
const onDidChangeVisibility = jest.fn();
const onDidCollapseElement = jest.fn();
const onDidExpandElement = jest.fn();
const existsSync = jest.fn();
Expand Down Expand Up @@ -212,6 +214,7 @@ describe("Extension Unit Tests", () => {
const isFile = jest.fn();
const load = jest.fn();
const GetJobs = jest.fn();
const getTreeView = jest.fn();
const getSpoolContentById = jest.fn();
const getJclForJob = jest.fn();
const DownloadJobs = jest.fn();
Expand Down Expand Up @@ -265,18 +268,31 @@ describe("Extension Unit Tests", () => {
};
});
const CliProfileManager = jest.fn().mockImplementation(() => {
return {getAllProfileNames, load};
return { getAllProfileNames, load };
});
const TreeView = jest.fn().mockImplementation(() => {
return {
reveal: mockReveal,
onDidExpandElement,
onDidCollapseElement,
selection: [],
onDidChangeSelection,
visible: true,
onDidChangeVisibility
};
});
const DatasetTree = jest.fn().mockImplementation(() => {
return {
mSessionNodes: [],
mFavorites: [],
treeView: new TreeView(),
addSession: mockAddZoweSession,
addHistory: mockAddHistory,
getHistory: mockGetHistory,
refresh: mockRefresh,
refreshElement: mockRefreshElement,
getChildren: mockGetChildren,
getTreeView,
removeFavorite: mockRemoveFavorite,
enterPattern: mockPattern,
initializeFavorites: mockInitialize,
Expand All @@ -295,6 +311,8 @@ describe("Extension Unit Tests", () => {
refresh: mockUSSRefresh,
addHistory: mockAddHistory,
getHistory: mockGetHistory,
getTreeView,
treeView: new TreeView(),
refreshElement: mockUSSRefreshElement,
getChildren: mockGetUSSChildren,
initializeUSSFavorites: mockInitializeUSS,
Expand All @@ -307,6 +325,8 @@ describe("Extension Unit Tests", () => {
getChildren: jest.fn(),
addSession: jest.fn(),
refresh: jest.fn(),
getTreeView,
treeView: new TreeView(),
refreshElement: jest.fn(),
getProfileName: jest.fn()
};
Expand All @@ -325,7 +345,6 @@ describe("Extension Unit Tests", () => {
testTree.mSessionNodes.push(sessNode);
Object.defineProperty(testTree, "onDidExpandElement", {value: jest.fn()});
Object.defineProperty(testTree, "onDidCollapseElement", {value: jest.fn()});
Object.defineProperty(testTree, "reveal", {value: jest.fn()});
Object.defineProperty(vscode.window, "createQuickPick", {value: createQuickPick});

const testUSSTree = USSTree();
Expand Down Expand Up @@ -357,7 +376,6 @@ describe("Extension Unit Tests", () => {
Object.defineProperty(vscode.workspace, "onDidSaveTextDocument", {value: onDidSaveTextDocument});
Object.defineProperty(vscode.window, "onDidCollapseElement", {value: onDidCollapseElement});
Object.defineProperty(vscode.window, "onDidExpandElement", {value: onDidExpandElement});
Object.defineProperty(vscode.window, "reveal", {value: reveal});
Object.defineProperty(vscode.workspace, "getConfiguration", {value: getConfiguration});
Object.defineProperty(vscode.workspace, "onDidChangeConfiguration", {value: onDidChangeConfiguration});
Object.defineProperty(fs, "readdirSync", {value: readdirSync});
Expand Down Expand Up @@ -450,7 +468,7 @@ describe("Extension Unit Tests", () => {
});

it("Testing that activate correctly executes", async () => {
createTreeView.mockReturnValue(testTree);
createTreeView.mockReturnValue(new TreeView());

existsSync.mockReturnValueOnce(true);
existsSync.mockReturnValueOnce(true);
Expand Down Expand Up @@ -1194,10 +1212,12 @@ describe("Extension Unit Tests", () => {
mockGetHistory.mockReset();

getConfiguration.mockReturnValue("FakeConfig");
createTreeView.mockReturnValue(new TreeView());
showInputBox.mockReturnValue("node");
allMembers.mockReturnValue(uploadResponse);
dataSetList.mockReturnValue(uploadResponse);
mockGetHistory.mockReturnValue([]);
testTree.getTreeView.mockReturnValue(new TreeView());

showQuickPick.mockResolvedValueOnce("Data Set Binary");
await extension.createFile(sessNode2, testTree);
Expand Down Expand Up @@ -1257,14 +1277,14 @@ describe("Extension Unit Tests", () => {
expect(showErrorMessage.mock.calls.length).toBe(0);

mockGetHistory.mockReset();
testTree.reveal.mockReset();
testTree.treeView.reveal.mockReset();

// Testing the addition of new node to tree view
mockGetHistory.mockReturnValueOnce(["NODE1"]);
showQuickPick.mockResolvedValueOnce("Data Set Sequential");
await extension.createFile(sessNode2, testTree);
expect(testTree.addHistory).toHaveBeenCalledWith("NODE1,NODE.*");
expect(testTree.reveal.mock.calls.length).toBe(1);
expect(testTree.treeView.reveal.mock.calls.length).toBe(1);

testTree.addHistory.mockReset();

Expand Down Expand Up @@ -1327,10 +1347,12 @@ describe("Extension Unit Tests", () => {
allMembers.mockReset();

getConfiguration.mockReturnValue("FakeConfig");
createTreeView.mockReturnValue(new TreeView());
showInputBox.mockReturnValue("FakeName");
mockGetHistory.mockReturnValue(["mockHistory"]);
dataSetList.mockReturnValue(uploadResponse);
allMembers.mockReturnValue(uploadResponse);
testTree.getTreeView.mockReturnValue(new TreeView());

showQuickPick.mockResolvedValueOnce("Data Set Binary");
await extension.createFile(newsessNode, testTree);
Expand Down Expand Up @@ -1411,11 +1433,13 @@ describe("Extension Unit Tests", () => {

getConfiguration.mockReturnValue("FakeConfig");
showInputBox.mockReturnValue("FakeName");
createTreeView.mockReturnValue(new TreeView());
testTree.getChildren.mockReturnValue([new ZoweDatasetNode("node", vscode.TreeItemCollapsibleState.None, sessNode,
null, undefined, undefined, profileOne), sessNode]);
allMembers.mockReturnValue(uploadResponse);
dataSet.mockReturnValue(uploadResponse);
mockGetHistory.mockReturnValue(["mockHistory1"]);
testTree.getTreeView.mockReturnValue(new TreeView());

showQuickPick.mockResolvedValueOnce("Data Set Binary");
await extension.createFile(newsessNode, testTree);
Expand Down Expand Up @@ -1496,6 +1520,7 @@ describe("Extension Unit Tests", () => {
mockGetHistory.mockReturnValueOnce(["mockHistory"]);
allMembers.mockReturnValueOnce(uploadResponse);
dataSetList.mockReturnValue(uploadResponse);
testTree.getTreeView.mockReturnValue(new TreeView());

showQuickPick.mockResolvedValueOnce("Data Set Binary");
await extension.createFile(newsessNode, testTree);
Expand Down
Loading

0 comments on commit 438e763

Please sign in to comment.