Skip to content

Commit

Permalink
Merge branch 'master' into theia-v1.1.0-update-fix
Browse files Browse the repository at this point in the history
  • Loading branch information
zFernand0 authored Sep 11, 2020
2 parents 64a6d2d + 027db5e commit 99dfe31
Show file tree
Hide file tree
Showing 54 changed files with 4,678 additions and 1,134 deletions.
9 changes: 9 additions & 0 deletions __mocks__/mockCreators/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,12 @@ export function bindMvsApi(api: ZoweExplorerApi.IMvs) {
getMvsApiMock.mockReturnValue(api);
ZoweExplorerApiRegister.getMvsApi = getMvsApiMock.bind(ZoweExplorerApiRegister);
}

export function createUssApi(profile: imperative.IProfileLoaded) {
return ZoweExplorerApiRegister.getUssApi(profile);
}
export function bindUssApi(api: ZoweExplorerApi.IUss) {
const getUssApiMock = jest.fn();
getUssApiMock.mockReturnValue(api);
ZoweExplorerApiRegister.getUssApi = getUssApiMock.bind(ZoweExplorerApiRegister);
}
23 changes: 18 additions & 5 deletions __mocks__/mockCreators/datasets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,19 @@ export function createDatasetSessionNode(session: imperative.Session, profile: i
return datasetNode;
}

export function createDatasetTree(sessionNode: ZoweDatasetNode, treeView: any): any {
export function createDatasetFavoritesNode() {
const datasetNode = new ZoweDatasetNode("Favorites", vscode.TreeItemCollapsibleState.Collapsed, null, null, null);
datasetNode.contextValue = globals.FAVORITE_CONTEXT;

return datasetNode;
}

export function createDatasetTree(sessionNode: ZoweDatasetNode, treeView: any, favoritesNode?: ZoweDatasetNode): any {
const testDatasetTree = {
mSessionNodes: [sessionNode],
mFavorites: [],
mFileHistory: [],
mHistory: [],
treeView,
addSession: jest.fn(),
addSearchHistory: jest.fn(),
Expand All @@ -44,7 +52,7 @@ export function createDatasetTree(sessionNode: ZoweDatasetNode, treeView: any):
createFilterString: jest.fn(),
setItem: jest.fn(),
getTreeView: jest.fn().mockImplementation(() => treeView),
searchInLoadedItems: jest.fn(),
getAllLoadedItems: jest.fn(),
removeFavorite: jest.fn(),
deleteSession: jest.fn(),
removeFileHistory: jest.fn(),
Expand All @@ -62,11 +70,16 @@ export function createDatasetTree(sessionNode: ZoweDatasetNode, treeView: any):
};
testDatasetTree.addFavorite.mockImplementation((newFavorite) => testDatasetTree.mFavorites.push(newFavorite));
testDatasetTree.addFileHistory.mockImplementation((newFile) => testDatasetTree.mFileHistory.push(newFile));
testDatasetTree.removeFileHistory.mockImplementation((badFile) => testDatasetTree.mFileHistory.splice(testDatasetTree.mFileHistory.indexOf(badFile), 1));
testDatasetTree.getFileHistory.mockImplementation(() => { return testDatasetTree.mFileHistory });
testDatasetTree.removeFileHistory.mockImplementation((badFile) => testDatasetTree.mFileHistory.splice(
testDatasetTree.mFileHistory.indexOf(badFile), 1
));
testDatasetTree.getFileHistory.mockImplementation(() => testDatasetTree.mFileHistory);
testDatasetTree.deleteSession.mockImplementation((badSession) => removeNodeFromArray(badSession, testDatasetTree.mSessionNodes));
testDatasetTree.removeFavorite.mockImplementation((badFavorite) => removeNodeFromArray(badFavorite, testDatasetTree.mFavorites));

if (!favoritesNode) {
return testDatasetTree;
}
testDatasetTree.mSessionNodes.push(favoritesNode);
return testDatasetTree;
}

Expand Down
38 changes: 38 additions & 0 deletions __mocks__/mockCreators/jobs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,3 +95,41 @@ export function createJobsTree(session: imperative.Session, iJob: zowe.IJob, pro

return testJobsTree;
}

export function createJobSessionNode(session: imperative.Session, profile: imperative.IProfileLoaded) {
const jobSessionNode = new Job("sestest", vscode.TreeItemCollapsibleState.Collapsed,
null, session, null, profile);
jobSessionNode.contextValue = globals.JOBS_SESSION_CONTEXT;

return jobSessionNode;
}

export function createJobFavoritesNode() {
const jobFavoritesNode = new Job("Favorites", vscode.TreeItemCollapsibleState.Collapsed, null, null, null, null);
jobFavoritesNode.contextValue = globals.FAVORITE_CONTEXT;

return jobFavoritesNode;
}

// Because the JobDetail class in ZosJobsProvider.ts is not exported:
export class MockJobDetail implements zowe.IJob {
public jobid: string;
public jobname: string;
public subsystem: string;
public owner: string;
public status: string;
public type: string;
public class: string;
public retcode: string;
public url: string;
public "files-url": string;
public "job-correlator": string;
public phase: number;
public "phase-name": string;
public "reason-not-running"?: string;

constructor(combined: string) {
this.jobname = combined.substring(0, combined.indexOf("("));
this.jobid = combined.substring(combined.indexOf("(") + 1, combined.indexOf(")"));
}
}
14 changes: 8 additions & 6 deletions __mocks__/mockCreators/uss.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,9 @@ export function createUSSTree(favoriteNodes: ZoweUSSNode[], sessionNodes: ZoweUS
newTree.removeFavorite = jest.fn().mockImplementation((badFavorite) => removeNodeFromArray(badFavorite, newTree.mFavorites));
newTree.openItemFromPath = jest.fn();
newTree.deleteSession = jest.fn().mockImplementation((badSession) => removeNodeFromArray(badSession, newTree.mSessionNodes));
newTree.searchInLoadedItems = jest.fn();
newTree.getAllLoadedItems = jest.fn();
newTree.getTreeView = jest.fn().mockImplementation(() => treeView);
newTree.getTreeItem = jest.fn().mockImplementation(() => new vscode.TreeItem('test'));
newTree.getTreeItem = jest.fn().mockImplementation(() => new vscode.TreeItem("test"));
newTree.getTreeType = jest.fn().mockImplementation(() => globals.PersistenceSchemaEnum.USS);
newTree.setItem = jest.fn();
newTree.addSearchHistory = jest.fn();
Expand Down Expand Up @@ -62,12 +62,14 @@ export function createUSSSessionNode(session: imperative.Session, profile: imper
return zoweUSSNode;
}

// This is NOT a favorite equivalent of the node created by createdUSSNode.
// This is a favorited textfile node. createUSSNode creates a USS session node.
export function createFavoriteUSSNode(session, profile) {
const ussNodeF = new ZoweUSSNode("[sestest]: usstest", vscode.TreeItemCollapsibleState.Expanded, null, session, null, false, profile.name);
const mParent = new ZoweUSSNode("Favorites", vscode.TreeItemCollapsibleState.Expanded, null, session, null, false, profile.name);
mParent.contextValue = globals.FAVORITE_CONTEXT;
const ussNodeF = new ZoweUSSNode("usstest", vscode.TreeItemCollapsibleState.Expanded, null, session, null, false, profile.name);
const mParent = new ZoweUSSNode("sestest", vscode.TreeItemCollapsibleState.Expanded, null, session, null, false, profile.name);
mParent.contextValue = globals.FAV_PROFILE_CONTEXT;
ussNodeF.contextValue = globals.DS_TEXT_FILE_CONTEXT + globals.FAV_SUFFIX;
ussNodeF.fullPath = "/u/myuser/usstest";
ussNodeF.tooltip = "/u/myuser/usstest";
return ussNodeF;
}
}
58 changes: 39 additions & 19 deletions __tests__/__integration__/DatasetTree.integration.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import * as testConst from "../../resources/testProfileData";
import * as sinon from "sinon";
import * as chai from "chai";
import * as chaiAsPromised from "chai-as-promised";
import { DS_SESSION_CONTEXT } from "../../src/globals";
import { DS_SESSION_CONTEXT, FAV_PROFILE_CONTEXT } from "../../src/globals";

declare var it: any;

Expand Down Expand Up @@ -176,14 +176,16 @@ describe("DatasetTree Integration Tests", async () => {
* Tests the deleteSession() function
*************************************************************************************************************/
it("Tests the addSession() function by adding the default history, deleting, then adding a passed session then deleting", async () => {
let len: number;
for (const sess of testTree.mSessionNodes) {
if (sess.contextValue === DS_SESSION_CONTEXT) {
testTree.deleteSession(sess);
}
}
const len = testTree.mSessionNodes.length;
len = testTree.mSessionNodes.length;
await testTree.addSession();
expect(testTree.mSessionNodes.length).toBeGreaterThan(len);
len = testTree.mSessionNodes.length;
for (const sess of testTree.mSessionNodes) {
if (sess.contextValue === DS_SESSION_CONTEXT) {
testTree.deleteSession(sess);
Expand All @@ -194,42 +196,54 @@ describe("DatasetTree Integration Tests", async () => {
}).timeout(TIMEOUT);

describe("addFavorite()", () => {
beforeEach(() => {
const favProfileNode = new ZoweDatasetNode(testConst.profile.name, vscode.TreeItemCollapsibleState.Expanded, null,
session, FAV_PROFILE_CONTEXT, undefined, testProfile);
testTree.mFavorites.push(favProfileNode);
});
afterEach(() => {
testTree.mFavorites = [];
});
it("should add the selected data set to the treeView", async () => {
const favoriteNode = new ZoweDatasetNode(pattern + ".TPDS", vscode.TreeItemCollapsibleState.Collapsed, sessNode, null);
const len = testTree.mFavorites.length;
await testTree.addFavorite(favoriteNode);
const filtered = testTree.mFavorites.filter((temp) => temp.label ===
`[${favoriteNode.getSessionNode().label}]: ${favoriteNode.label}`);
const filtered = testTree.mFavorites[0].children.filter((temp) => temp.label === `${favoriteNode.label}`);
expect(filtered.length).toEqual(1);
expect(filtered[0].label).toContain(pattern + ".TPDS");
// TODO confirm in settings.json too
testTree.mFavorites = [];
});

it("should add a favorite search", async () => {
await testTree.addFavorite(sessNode);
const filtered = testTree.mFavorites.filter((temp) => temp.label === `[${sessNode.label}]: ${sessNode.pattern}`);
const filtered = testTree.mFavorites[0].children.filter((temp) => temp.label === `${sessNode.pattern}`);
expect(filtered.length).toEqual(1);
expect(filtered[0].label).toContain(`[${sessNode.label}]: ${sessNode.pattern}`);
testTree.mFavorites = [];
expect(filtered[0].label).toContain(`${sessNode.pattern}`);
});
});

describe("removeFavorite()", () => {
it("should remove the selected favorite data set from the treeView", () => {
beforeEach(() => {
const favProfileNode = new ZoweDatasetNode(testConst.profile.name, vscode.TreeItemCollapsibleState.Expanded, null,
session, FAV_PROFILE_CONTEXT, undefined, testProfile);
testTree.mFavorites.push(favProfileNode);
});
afterEach(() => {
testTree.mFavorites = [];
});
it("should remove the selected favorite data set from the treeView", async () => {
const favoriteNode = new ZoweDatasetNode(pattern + ".TPDS",
vscode.TreeItemCollapsibleState.Collapsed, sessNode, null);
testTree.addFavorite(favoriteNode);
const len = testTree.mFavorites.length;
testTree.removeFavorite(testTree.mFavorites[len - 1]);
expect(testTree.mFavorites.length).toEqual(len - 1);
await testTree.addFavorite(favoriteNode);
const len = testTree.mFavorites[0].children.length;
await testTree.removeFavorite(testTree.mFavorites[0].children[len - 1]);
expect(testTree.mFavorites[0].children.length).toEqual(len - 1);
});

it("should remove the selected favorite search from the treeView", () => {
testTree.addFavorite(sessNode);
const len = testTree.mFavorites.length;
testTree.removeFavorite(testTree.mFavorites[len - 1]);
expect(testTree.mFavorites.length).toEqual(len - 1);
it("should remove the selected favorite search from the treeView", async () => {
await testTree.addFavorite(sessNode);
const len = testTree.mFavorites[0].children.length;
await testTree.removeFavorite(testTree.mFavorites[0].children[len - 1]);
expect(testTree.mFavorites[0].children.length).toEqual(len - 1);
});
});

Expand Down Expand Up @@ -328,6 +342,12 @@ describe("DatasetTree Integration Tests", async () => {
new Buffer("abc"),
`${beforeDataSetName}(mem1)`
);
const favProfileNode = new ZoweDatasetNode(testConst.profile.name, vscode.TreeItemCollapsibleState.Expanded, null,
session, FAV_PROFILE_CONTEXT, undefined, testProfile);
testTree.mFavorites.push(favProfileNode);
});
afterEach(() => {
testTree.mFavorites = [];
});
it("should rename a data set member", async () => {
let error;
Expand Down
31 changes: 16 additions & 15 deletions __tests__/__integration__/USSTree.integration.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import * as vscode from "vscode";
import * as testConst from "../../resources/testProfileData";
import { USSTree } from "../../src/uss/USSTree";
import { ZoweUSSNode } from "../../src/uss/ZoweUSSNode";
import { USS_SESSION_CONTEXT } from "../../src/globals";
import { USS_SESSION_CONTEXT, FAV_PROFILE_CONTEXT } from "../../src/globals";

declare var it: any;

Expand Down Expand Up @@ -205,28 +205,29 @@ describe("USSTree Integration Tests", async () => {
}).timeout(TIMEOUT);

describe("add USS Favorite for a file and a search", () => {
it("should add the selected data set to the treeView", async () => {
const log = new Logger(undefined);
await testTree.addSession();
const favoriteNode = new ZoweUSSNode("file.txt", vscode.TreeItemCollapsibleState.Collapsed,
beforeEach(() => {
const favProfileNode = new ZoweUSSNode(testConst.profile.name, vscode.TreeItemCollapsibleState.Expanded, null,
session, null, null);
favProfileNode.contextValue = FAV_PROFILE_CONTEXT;
testTree.mFavorites.push(favProfileNode);
});
afterEach(() => {
testTree.mFavorites = [];
});
it("should add the selected file to the treeView", async () => {
const favoriteNode = new ZoweUSSNode("file.txt", vscode.TreeItemCollapsibleState.None,
sessNode, null, sessNode.fullPath, testConst.profile.name);
await testTree.addFavorite(favoriteNode);
const filtered = testTree.mFavorites.filter((temp) => temp.label ===
`[${favoriteNode.getSessionNode().label}]: ${favoriteNode.label}`);
const filtered = testTree.mFavorites[0].children.filter((temp) => temp.label === `${favoriteNode.label}`);
expect(filtered.length).toEqual(1);
expect(filtered[0].label).toContain("file.txt");
testTree.mFavorites = [];
}).timeout(TIMEOUT);

it("should add a favorite search", async () => {
const log = new Logger(undefined);
await testTree.addSession();
await testTree.saveSearch(sessNode);
const filtered = testTree.mFavorites.filter((temp) =>
temp.label === `[${sessNode.label}]: ${sessNode.fullPath}`);
await testTree.addFavorite(sessNode);
const filtered = testTree.mFavorites[0].children.filter((temp) => temp.label === `${sessNode.fullPath}`);
expect(filtered.length).toEqual(1);
expect(filtered[0].label).toContain(`[${sessNode.label}]: ${sessNode.fullPath}`);
testTree.mFavorites = [];
expect(filtered[0].label).toContain(`${sessNode.fullPath}`);
}).timeout(TIMEOUT);
});
});
Loading

0 comments on commit 99dfe31

Please sign in to comment.