Skip to content

Commit

Permalink
Add option for hiding profile from all trees
Browse files Browse the repository at this point in the history
Signed-off-by: Rudy Flores <[email protected]>
  • Loading branch information
rudyflores committed Nov 10, 2023
1 parent c2fc8c9 commit a8f06e2
Show file tree
Hide file tree
Showing 21 changed files with 228 additions and 70 deletions.
8 changes: 7 additions & 1 deletion packages/zowe-explorer-api/src/tree/IZoweTree.ts
Original file line number Diff line number Diff line change
Expand Up @@ -206,8 +206,9 @@ export interface IZoweTree<T> extends vscode.TreeDataProvider<T> {
/**
* Deletes a root node from the tree.
* @param node: A root node representing a session
* @param hideFromAllTrees: <optional> whether to hide from all trees or just the single tree
*/
deleteSession(node: IZoweTreeNode);
deleteSession(node: IZoweTreeNode, hideFromAllTrees?: boolean);
/**
* Lets the user open a dataset by filtering the currently-loaded list
*/
Expand Down Expand Up @@ -268,6 +269,11 @@ export interface IZoweTree<T> extends vscode.TreeDataProvider<T> {
* @param {string} name the member to remove
*/
removeFileHistory?(name: string);
/**
* Removes session from the session array
* @param {string} name the sessions to remove
*/
removeSession?(name: string): void;
/**
* Returns a new dataset filter string, from an old filter and a new string
*
Expand Down
41 changes: 40 additions & 1 deletion packages/zowe-explorer/__mocks__/mockCreators/shared.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import { ZoweTreeProvider } from "../../src/abstract/ZoweTreeProvider";
import { ZoweDatasetNode } from "../../src/dataset/ZoweDatasetNode";
import { ZoweUSSNode } from "../../src/uss/ZoweUSSNode";
import * as vscode from "vscode";
import { ValidProfileEnum } from "@zowe/zowe-explorer-api";
import { ValidProfileEnum, IZoweTreeNode } from "@zowe/zowe-explorer-api";
import { FilterDescriptor } from "../../src/utils/ProfilesUtils";
import { imperative, ZosmfSession } from "@zowe/cli";
import { SettingsConfig } from "../../src/utils/SettingsConfig";
Expand Down Expand Up @@ -548,3 +548,42 @@ export function createOutputChannel() {
replace: jest.fn(),
} as vscode.OutputChannel;
}

export function createMockNode(name: string): IZoweTreeNode {
return {
dirty: false,
getLabel: jest.fn(() => name),
getChildren: jest.fn(),
getParent: jest.fn(),
getProfile: jest.fn(),
getProfileName: jest.fn(),
getSession: jest.fn(),
getSessionNode: jest.fn(),
setProfileToChoice: jest.fn(),
setSessionToChoice: jest.fn(),
label: name,
};
}

export function createTreeProviders() {
return {
ds: {
mSessionNodes: [createMockNode("zosmf"), createMockNode("zosmf2")],
deleteSession: jest.fn(),
removeSession: jest.fn(),
refresh: jest.fn(),
} as any,
uss: {
mSessionNodes: [createMockNode("zosmf"), createMockNode("zosmf2")],
deleteSession: jest.fn(),
removeSession: jest.fn(),
refresh: jest.fn(),
} as any,
job: {
mSessionNodes: [createMockNode("zosmf"), createMockNode("zosmf2")],
removeSession: jest.fn(),
deleteSession: jest.fn(),
refresh: jest.fn(),
} as any,
};
}
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ import {
createValidIProfile,
createInstanceOfProfileInfo,
createGetConfigMock,
createTreeProviders,
} from "../../../__mocks__/mockCreators/shared";
import { createDatasetSessionNode, createDatasetTree, createDatasetFavoritesNode } from "../../../__mocks__/mockCreators/datasets";
import { bindMvsApi, createMvsApi } from "../../../__mocks__/mockCreators/api";
Expand All @@ -49,6 +50,7 @@ import * as dsUtils from "../../../src/dataset/utils";
import { SettingsConfig } from "../../../src/utils/SettingsConfig";
import * as sharedActions from "../../../src/shared/actions";
import { ZoweLogger } from "../../../src/utils/LoggerUtils";
import { TreeProviders } from "../../../src/shared/TreeProviders";

jest.mock("fs");
jest.mock("util");
Expand All @@ -63,6 +65,7 @@ function createGlobalMocks() {
mockShowWarningMessage: jest.fn(),
mockProfileInfo: createInstanceOfProfileInfo(),
mockProfilesCache: new ProfilesCache(zowe.imperative.Logger.getAppLogger()),
mockTreeProviders: createTreeProviders(),
};

globalMocks.mockProfileInstance = createInstanceOfProfile(globalMocks.testProfileLoaded);
Expand Down Expand Up @@ -1327,7 +1330,7 @@ describe("Dataset Tree Unit Tests - Function deleteSession", () => {
};
}

it("Checking common run of function", async () => {
it("Checking common run of function", () => {
createGlobalMocks();
const blockMocks = createBlockMocks();

Expand All @@ -1339,6 +1342,20 @@ describe("Dataset Tree Unit Tests - Function deleteSession", () => {

expect(testTree.mSessionNodes.map((node) => node.label)).toEqual(["Favorites"]);
});

it("Checking case profile needs to be hidden for all trees", async () => {
const globalMocks = createGlobalMocks();
const blockMocks = createBlockMocks();

jest.spyOn(TreeProviders, "providers", "get").mockReturnValue(globalMocks.mockTreeProviders);
mocked(vscode.window.createTreeView).mockReturnValueOnce(blockMocks.treeView);
const testTree = new DatasetTree();
testTree.mSessionNodes.push(blockMocks.datasetSessionNode);

testTree.deleteSession(testTree.mSessionNodes[1], true);

expect(testTree.mSessionNodes.map((node) => node.label)).toEqual(["Favorites"]);
});
});
describe("Dataset Tree Unit Tests - Function flipState", () => {
function createBlockMocks() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ describe("Test src/dataset/extension", () => {
name: "zowe.ds.removeSession",
mock: [
{ spy: jest.spyOn(contextuals, "isDsSession"), arg: [test.value], ret: true },
{ spy: jest.spyOn(dsProvider, "deleteSession"), arg: [test.value] },
{ spy: jest.spyOn(dsProvider, "deleteSession"), arg: [test.value, undefined] },
],
},
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -546,10 +546,12 @@ describe("Extension Unit Tests", () => {
getProfile: jest.fn(),
getParent: jest.fn().mockReturnValue({ getLabel: jest.fn() }),
label: "TestNode",
getLabel: jest.fn(() => "TestNode"),
};

const deleteSessionSpy = jest.spyOn(providerObject.prototype, "deleteSession");
const commandFunction = allCommands.find((cmd) => command === cmd.cmd);
await (commandFunction as any).fun(testNode, [testNode]);
await (commandFunction as any).fun(testNode, [testNode], true);
expect(deleteSessionSpy).toHaveBeenCalled();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,12 @@ import {
createInstanceOfProfile,
createISessionWithoutCredentials,
createInstanceOfProfileInfo,
createTreeProviders,
} from "../../../__mocks__/mockCreators/shared";
import * as contextually from "../../../src/shared/context";
import { ZoweLogger } from "../../../src/utils/LoggerUtils";
import { bindJesApi, createJesApi } from "../../../__mocks__/mockCreators/api";
import { TreeProviders } from "../../../src/shared/TreeProviders";

async function createGlobalMocks() {
const globalMocks = {
Expand Down Expand Up @@ -86,6 +88,7 @@ async function createGlobalMocks() {
}),
mockProfileInfo: createInstanceOfProfileInfo(),
mockProfilesCache: new ProfilesCache(zowe.imperative.Logger.getAppLogger()),
mockTreeProviders: createTreeProviders(),
};

Object.defineProperty(globals, "LOG", { value: jest.fn(), configurable: true });
Expand Down Expand Up @@ -237,10 +240,12 @@ describe("ZoweJobNode unit tests - Function addSession", () => {
describe("ZoweJobNode unit tests - Function deleteSession", () => {
it("Tests that deleteSession removes the session from the tree", async () => {
const globalMocks = await createGlobalMocks();

jest.spyOn(TreeProviders, "providers", "get").mockReturnValue(globalMocks.mockTreeProviders);
globalMocks.testJobsProvider.mSessionNodes = globalMocks.mockTreeProviders.ds.mSessionNodes;
await globalMocks.testJobsProvider.deleteSession(globalMocks.testJobsProvider.mSessionNodes[1]);

expect(globalMocks.testJobsProvider.mSessionNodes.length).toBe(1);
expect(globalMocks.mockTreeProviders.ds.mSessionNodes.length).toEqual(2);
expect(globalMocks.mockTreeProviders.uss.mSessionNodes.length).toEqual(2);
expect(globalMocks.mockTreeProviders.job.mSessionNodes.length).toEqual(2);
});
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ describe("Test src/jobs/extension", () => {
name: "zowe.jobs.removeJobsSession",
mock: [
{ spy: jest.spyOn(contextuals, "isJobsSession"), arg: [test.value], ret: true },
{ spy: jest.spyOn(jobsProvider, "deleteSession"), arg: [test.value] },
{ spy: jest.spyOn(jobsProvider, "deleteSession"), arg: [test.value, undefined] },
],
},
{
Expand Down
14 changes: 11 additions & 3 deletions packages/zowe-explorer/__tests__/__unit__/uss/USSTree.unit.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import {
createInstanceOfProfile,
createValidIProfile,
createTreeView,
createTreeProviders,
} from "../../../__mocks__/mockCreators/shared";
import * as globals from "../../../src/globals";
import * as vscode from "vscode";
Expand All @@ -32,6 +33,7 @@ import { getIconByNode } from "../../../src/generators/icons";
import * as workspaceUtils from "../../../src/utils/workspace";
import { createUssApi, bindUssApi } from "../../../__mocks__/mockCreators/api";
import { ZoweLogger } from "../../../src/utils/LoggerUtils";
import { TreeProviders } from "../../../src/shared/TreeProviders";

async function createGlobalMocks() {
const globalMocks = {
Expand Down Expand Up @@ -76,6 +78,7 @@ async function createGlobalMocks() {
testTree: null,
profilesForValidation: { status: "active", name: "fake" },
mockProfilesCache: new ProfilesCache(zowe.imperative.Logger.getAppLogger()),
mockTreeProviders: createTreeProviders(),
};

globalMocks.mockTextDocuments.push(globalMocks.mockTextDocumentDirty);
Expand Down Expand Up @@ -503,7 +506,7 @@ describe("USSTree Unit Tests - Function USSTree.deleteSession()", () => {
const newMocks = {
testTree2: new USSTree(),
testSessionNode: new ZoweUSSNode("testSessionNode", vscode.TreeItemCollapsibleState.Collapsed, null, globalMocks.testSession, null),
startLength: null,
startLength: 0,
};
const ussSessionTestNode = createUSSSessionNode(globalMocks.testSession, globalMocks.testProfile);
newMocks.testTree2.mSessionNodes.push(ussSessionTestNode);
Expand All @@ -517,8 +520,13 @@ describe("USSTree Unit Tests - Function USSTree.deleteSession()", () => {
const globalMocks = await createGlobalMocks();
const blockMocks = await createBlockMocks(globalMocks);

blockMocks.testTree2.deleteSession(blockMocks.testTree2.mSessionNodes[blockMocks.startLength - 1]);
expect(blockMocks.testTree2.mSessionNodes.length).toEqual(blockMocks.startLength - 1);
jest.spyOn(TreeProviders, "providers", "get").mockReturnValue(globalMocks.mockTreeProviders);

blockMocks.testTree2.mSessionNodes = globalMocks.mockTreeProviders.ds.mSessionNodes;
blockMocks.testTree2.deleteSession(globalMocks.mockTreeProviders.ds.mSessionNodes[1]);
expect(globalMocks.mockTreeProviders.ds.mSessionNodes.length).toEqual(2);
expect(globalMocks.mockTreeProviders.uss.mSessionNodes.length).toEqual(2);
expect(globalMocks.mockTreeProviders.job.mSessionNodes.length).toEqual(2);
});
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ describe("Test src/dataset/extension", () => {
name: "zowe.uss.removeSession",
mock: [
{ spy: jest.spyOn(contextuals, "isUssSession"), arg: [test.value], ret: true },
{ spy: jest.spyOn(ussFileProvider, "deleteSession"), arg: [test.value] },
{ spy: jest.spyOn(ussFileProvider, "deleteSession"), arg: [test.value, undefined] },
],
},
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,9 +140,10 @@ describe("ProfileManagement unit tests", () => {
configurable: true,
});
mocks.mockResolveQp.mockResolvedValueOnce(mocks.mockHideProfChosen);
mocks.mockResolveQp.mockResolvedValueOnce(ProfileManagement["getPromptHideFromAllTreesQpItems"]()[0]);
await ProfileManagement.manageProfile(mocks.mockDsSessionNode);
expect(mocks.debugLogSpy).toBeCalledWith(mocks.logMsg);
expect(mocks.commandSpy).toHaveBeenLastCalledWith("zowe.ds.removeSession", mocks.mockDsSessionNode);
expect(mocks.commandSpy).toHaveBeenLastCalledWith("zowe.ds.removeSession", mocks.mockDsSessionNode, null, true);
});
it("profile using basic authentication should see delete commands called when Delete Profile chosen with v1 profile", async () => {
const mocks = createBlockMocks(createGlobalMocks());
Expand Down Expand Up @@ -187,9 +188,10 @@ describe("ProfileManagement unit tests", () => {
it("profile using token authentication should see correct command called for hiding a unix tree session node", async () => {
const mocks = createBlockMocks(createGlobalMocks());
mocks.mockResolveQp.mockResolvedValueOnce(mocks.mockHideProfChosen);
mocks.mockResolveQp.mockResolvedValueOnce(ProfileManagement["getPromptHideFromAllTreesQpItems"]()[1]);
await ProfileManagement.manageProfile(mocks.mockUnixSessionNode);
expect(mocks.debugLogSpy).toBeCalledWith(mocks.logMsg);
expect(mocks.commandSpy).toHaveBeenLastCalledWith("zowe.uss.removeSession", mocks.mockUnixSessionNode);
expect(mocks.commandSpy).toHaveBeenLastCalledWith("zowe.uss.removeSession", mocks.mockUnixSessionNode, null, false);
});
it("profile using token authentication should see correct command called for enabling validation a unix tree session node", async () => {
const mocks = createBlockMocks(createGlobalMocks());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,12 @@
"qpPlaceholders.qp.basic": "Profile {0} is using basic authentication. Choose a profile action.",
"qpPlaceholders.qp.token": "Profile {0} is using token authentication. Choose a profile action.",
"qpPlaceholders.qp.choose": "Profile {0} doesn't specify an authentication method. Choose a profile action.",
"ProfileManagement.promptHideFromAllTrees.allLbl": "Yes",
"ProfileManagement.promptHideFromAllTrees.allDesc": "Hide for all trees",
"ProfileManagement.promptHideFromAllTrees.currentLbl": "No",
"ProfileManagement.promptHideFromAllTrees.currentDesc": "Hide for current tree selected",
"ProfileManagement.promptHideFromAllTrees.howToHide": "Do you wish to hide this profile from all trees?",
"ProfileManagement.handleHideProfiles.cancelled": "Operation Cancelled",
"addBasicAuthQpItem.addCredentials.qpLabel": "$(plus) Add Credentials",
"addBasicAuthQpItem.addCredentials.qpDetail": "Add username and password for basic authentication",
"updateBasicAuthQpItem.updateCredentials.qpLabel": "$(refresh) Update Credentials",
Expand Down
20 changes: 14 additions & 6 deletions packages/zowe-explorer/src/abstract/ZoweTreeProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ import { setProfile, setSession, errorHandling } from "../utils/ProfilesUtils";
import * as nls from "vscode-nls";
import { SettingsConfig } from "../utils/SettingsConfig";
import { ZoweLogger } from "../utils/LoggerUtils";
import { TreeProviders } from "../shared/TreeProviders";
import { IZoweProviders } from "../shared/init";

// Set up localization
nls.config({
Expand Down Expand Up @@ -182,6 +184,18 @@ export class ZoweTreeProvider {
return undefined;
}

public deleteSession(node: IZoweTreeNode): void {
ZoweLogger.trace("ZoweTreeProvider.deleteSession called.");
for (const key of Object.keys(TreeProviders.providers) as Array<keyof IZoweProviders>) {
const provider = TreeProviders.providers[key];
provider.mSessionNodes = (provider.mSessionNodes as IZoweTreeNode[]).filter(
(mSessionNode: IZoweTreeNode) => mSessionNode.getLabel() !== node.getLabel()
);
provider.removeSession(node.getLabel() as string);
provider.refresh();
}
}

public async editSession(node: IZoweTreeNode, zoweFileProvider: IZoweTree<IZoweNodeType>): Promise<void> {
ZoweLogger.trace("ZoweTreeProvider.editSession called.");
const profile = node.getProfile();
Expand Down Expand Up @@ -289,10 +303,4 @@ export class ZoweTreeProvider {
ZoweLogger.trace("ZoweTreeProvider.createZoweSession called.");
await Profiles.getInstance().createZoweSession(zoweFileProvider);
}

protected deleteSessionByLabel(revisedLabel: string): void {
ZoweLogger.trace("ZoweTreeProvider.deleteSessionByLabel called.");
this.mHistory.removeSession(revisedLabel);
this.refresh();
}
}
14 changes: 11 additions & 3 deletions packages/zowe-explorer/src/dataset/DatasetTree.ts
Original file line number Diff line number Diff line change
Expand Up @@ -482,10 +482,13 @@ export class DatasetTree extends ZoweTreeProvider implements IZoweTree<IZoweData
*
* @param node
*/
public deleteSession(node: IZoweDatasetTreeNode): void {
public deleteSession(node: IZoweDatasetTreeNode, hideFromAllTrees?: boolean): void {
ZoweLogger.trace("DatasetTree.deleteSession called.");
this.mSessionNodes = this.mSessionNodes.filter((tempNode) => tempNode.label.toString() !== node.label.toString());
this.mHistory.removeSession(node.label as string);
if (hideFromAllTrees) {
super.deleteSession(node);
}
this.mSessionNodes = this.mSessionNodes.filter((mSessionNode: IZoweDatasetTreeNode) => mSessionNode.getLabel() !== node.getLabel());
this.removeSession(node.getLabel() as string);
this.refresh();
}

Expand Down Expand Up @@ -769,6 +772,11 @@ export class DatasetTree extends ZoweTreeProvider implements IZoweTree<IZoweData
this.mHistory.removeSearchHistory(name);
}

public removeSession(name: string): void {
ZoweLogger.trace("DatasetTree.removeSession called.");
this.mHistory.removeSession(name);
}

public resetSearchHistory(): void {
ZoweLogger.trace("DatasetTree.resetSearchHistory called.");
this.mHistory.resetSearchHistory();
Expand Down
Loading

0 comments on commit a8f06e2

Please sign in to comment.