Skip to content

Commit

Permalink
chore: more PR feedback
Browse files Browse the repository at this point in the history
Signed-off-by: zFernand0 <[email protected]>
  • Loading branch information
zFernand0 committed Jul 29, 2024
1 parent 0ab43e4 commit a8fa88b
Show file tree
Hide file tree
Showing 7 changed files with 40 additions and 46 deletions.
5 changes: 2 additions & 3 deletions packages/zowe-explorer/__tests__/__decorators__/MockMethod.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,8 @@
*/
export function MockMethod(): (target: any, key: string, descriptor: PropertyDescriptor) => PropertyDescriptor | undefined {
return (target: any, key: string, descriptor: PropertyDescriptor | undefined) => {
if (descriptor === undefined) {
descriptor = Object.getOwnPropertyDescriptor(target, key);
}
descriptor ??= Object.getOwnPropertyDescriptor(target, key);

if (descriptor != null) {
const originalMethod = descriptor.value;
descriptor.value = jest.fn((...args) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1061,7 +1061,7 @@ describe("Profiles Unit Tests - function enableValidationContext", () => {
describe("Profiles Unit Tests - function ssoLogin", () => {
let testNode;
let globalMocks;
beforeEach(async () => {
beforeEach(() => {
globalMocks = createGlobalMocks();
testNode = new (ZoweTreeNode as any)(
"fake",
Expand Down Expand Up @@ -1127,7 +1127,7 @@ describe("Profiles Unit Tests - function ssoLogin", () => {
describe("Profiles Unit Tests - function ssoLogout", () => {
let testNode;
let globalMocks;
beforeEach(async () => {
beforeEach(() => {
globalMocks = createGlobalMocks();
testNode = new (ZoweTreeNode as any)(
"fake",
Expand Down Expand Up @@ -1208,7 +1208,7 @@ describe("Profiles Unit Tests - function updateBaseProfileFileLogout", () => {
});

describe("Profiles Unit Tests - function createNonSecureProfile", () => {
it("should create an unsecured profile by removing secure arrays and setting autoStore to false", async () => {
it("should create an unsecured profile by removing secure arrays and setting autoStore to false", () => {
const globalMocks = createGlobalMocks();
const changingConfig = globalMocks.testTeamConfigProfile;
const privateProfile = Profiles.getInstance() as any;
Expand All @@ -1222,7 +1222,7 @@ describe("Profiles Unit Tests - function createNonSecureProfile", () => {
});

describe("Profiles Unit Tests - function validationArraySetup", () => {
it("should setup the validation array", async () => {
it("should setup the validation array", () => {
const globalMocks = createGlobalMocks();
Object.defineProperty(Profiles.getInstance(), "profilesValidationSetting", {
value: [
Expand Down Expand Up @@ -1303,7 +1303,7 @@ describe("Profiles Unit Tests - function clearFilterFromAllTrees", () => {
jest.restoreAllMocks();
});

it("should fail to clear filter if no session nodes are available", async () => {
it("should fail to clear filter if no session nodes are available", () => {
const globalMocks = createGlobalMocks();
const testNode = new (ZoweTreeNode as any)(
"fake",
Expand All @@ -1330,7 +1330,7 @@ describe("Profiles Unit Tests - function clearFilterFromAllTrees", () => {
expect(refreshElementSpy).toHaveBeenCalledTimes(0);
});

it("should fail to clear filters if the session node is not listed in the tree", async () => {
it("should fail to clear filters if the session node is not listed in the tree", () => {
const globalMocks = createGlobalMocks();
const testNode = new (ZoweTreeNode as any)(
"fake",
Expand Down Expand Up @@ -1367,15 +1367,15 @@ describe("Profiles Unit Tests - function disableValidation", () => {
jest.resetAllMocks();
});

it("should disable validation for the profile on all trees", async () => {
it("should disable validation for the profile on all trees", () => {
const globalMocks = createGlobalMocks();
jest.spyOn(SharedTreeProviders, "getSessionForAllTrees").mockReturnValue([globalMocks.testNode]);
expect(globalMocks.testNode.contextValue).toEqual(Constants.DS_SESSION_CONTEXT);
expect(Profiles.getInstance().disableValidation(globalMocks.testNode)).toEqual(globalMocks.testNode);
expect(globalMocks.testNode.contextValue).toEqual(Constants.DS_SESSION_CONTEXT + Constants.VALIDATE_SUFFIX);
});

it("should disable validation for the profile on the current tree", async () => {
it("should disable validation for the profile on the current tree", () => {
const globalMocks = createGlobalMocks();
jest.spyOn(SharedTreeProviders, "getSessionForAllTrees").mockReturnValue([globalMocks.testNode]);
const disableValidationContextSpy = jest.spyOn(Profiles.getInstance(), "disableValidationContext");
Expand All @@ -1393,7 +1393,7 @@ describe("Profiles Unit Tests - function enableValidation", () => {
jest.resetAllMocks();
});

it("should enable validation for the profile on all trees", async () => {
it("should enable validation for the profile on all trees", () => {
const globalMocks = createGlobalMocks();
jest.spyOn(SharedTreeProviders, "getSessionForAllTrees").mockReturnValue([
createMockNode("test2", Constants.DS_SESSION_CONTEXT),
Expand All @@ -1404,7 +1404,7 @@ describe("Profiles Unit Tests - function enableValidation", () => {
expect(globalMocks.testNode.contextValue).toEqual(Constants.DS_SESSION_CONTEXT + Constants.VALIDATE_SUFFIX);
});

it("should enable validation for the profile on the current tree", async () => {
it("should enable validation for the profile on the current tree", () => {
const globalMocks = createGlobalMocks();
const enableValidationContextSpy = jest.spyOn(Profiles.getInstance(), "enableValidationContext");
jest.spyOn(SharedTreeProviders, "getSessionForAllTrees").mockReturnValue([globalMocks.testNode]);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -968,10 +968,10 @@ describe("Dataset Tree Unit Tests - Function addFavorite", () => {

await testTree.addFavorite(node);

expect(testTree.mFavorites[0].label).toBe(`${blockMocks.datasetSessionNode.label?.toString()}`);
expect(testTree.mFavorites[0].contextValue).toBe(`${Constants.FAV_PROFILE_CONTEXT}`);
expect(testTree.mFavorites[0].children[0].label).toBe(`${node.label?.toString()}`);
expect(testTree.mFavorites[0].children[0].contextValue).toBe(`${Constants.DS_DS_CONTEXT}${Constants.FAV_SUFFIX}`);
expect(testTree.mFavorites[0].label).toBe(blockMocks.datasetSessionNode.label?.toString());
expect(testTree.mFavorites[0].contextValue).toBe(Constants.FAV_PROFILE_CONTEXT);
expect(testTree.mFavorites[0].children[0].label).toBe(node.label?.toString());
expect(testTree.mFavorites[0].children[0].contextValue).toBe(Constants.DS_DS_CONTEXT + Constants.FAV_SUFFIX);
});
it("Checking adding of PDS Dataset node", async () => {
createGlobalMocks();
Expand All @@ -989,10 +989,10 @@ describe("Dataset Tree Unit Tests - Function addFavorite", () => {

await testTree.addFavorite(node);

expect(testTree.mFavorites[0].label).toBe(`${blockMocks.datasetSessionNode.label?.toString()}`);
expect(testTree.mFavorites[0].contextValue).toBe(`${Constants.FAV_PROFILE_CONTEXT}`);
expect(testTree.mFavorites[0].children[0].label).toBe(`${node.label?.toString()}`);
expect(testTree.mFavorites[0].children[0].contextValue).toBe(`${Constants.DS_PDS_CONTEXT}${Constants.FAV_SUFFIX}`);
expect(testTree.mFavorites[0].label).toBe(blockMocks.datasetSessionNode.label?.toString());
expect(testTree.mFavorites[0].contextValue).toBe(Constants.FAV_PROFILE_CONTEXT);
expect(testTree.mFavorites[0].children[0].label).toBe(node.label?.toString());
expect(testTree.mFavorites[0].children[0].contextValue).toBe(Constants.DS_PDS_CONTEXT + Constants.FAV_SUFFIX);
});
it("Checking adding of PDS Member node", async () => {
createGlobalMocks();
Expand All @@ -1012,10 +1012,10 @@ describe("Dataset Tree Unit Tests - Function addFavorite", () => {

await testTree.addFavorite(child);

expect(testTree.mFavorites[0].label).toBe(`${blockMocks.datasetSessionNode.label?.toString()}`);
expect(testTree.mFavorites[0].contextValue).toBe(`${Constants.FAV_PROFILE_CONTEXT}`);
expect(testTree.mFavorites[0].children[0].label).toBe(`${parent.label?.toString()}`);
expect(testTree.mFavorites[0].children[0].contextValue).toBe(`${Constants.DS_PDS_CONTEXT}${Constants.FAV_SUFFIX}`);
expect(testTree.mFavorites[0].label).toBe(blockMocks.datasetSessionNode.label?.toString());
expect(testTree.mFavorites[0].contextValue).toBe(Constants.FAV_PROFILE_CONTEXT);
expect(testTree.mFavorites[0].children[0].label).toBe(parent.label?.toString());
expect(testTree.mFavorites[0].children[0].contextValue).toBe(Constants.DS_PDS_CONTEXT + Constants.FAV_SUFFIX);
});
it("Checking adding of Session node", async () => {
createGlobalMocks();
Expand All @@ -1029,10 +1029,10 @@ describe("Dataset Tree Unit Tests - Function addFavorite", () => {

await testTree.addFavorite(testTree.mSessionNodes[1]);

expect(testTree.mFavorites[0].label).toBe(`${blockMocks.datasetSessionNode.label?.toString()}`);
expect(testTree.mFavorites[0].contextValue).toBe(`${Constants.FAV_PROFILE_CONTEXT}`);
expect(testTree.mFavorites[0].children[0].label).toBe(`${testTree.mSessionNodes[1].pattern}`);
expect(testTree.mFavorites[0].children[0].contextValue).toBe(`${Constants.DS_SESSION_CONTEXT}${Constants.FAV_SUFFIX}`);
expect(testTree.mFavorites[0].label).toBe(blockMocks.datasetSessionNode.label?.toString());
expect(testTree.mFavorites[0].contextValue).toBe(Constants.FAV_PROFILE_CONTEXT);
expect(testTree.mFavorites[0].children[0].label).toBe(testTree.mSessionNodes[1].pattern);
expect(testTree.mFavorites[0].children[0].contextValue).toBe(Constants.DS_SESSION_CONTEXT + Constants.FAV_SUFFIX);
});
it("Checking attempt to add a duplicate node", async () => {
createGlobalMocks();
Expand All @@ -1050,7 +1050,7 @@ describe("Dataset Tree Unit Tests - Function addFavorite", () => {
await testTree.addFavorite(node);
await testTree.addFavorite(node);

expect(testTree.mFavorites[0].children.map((entry) => entry.label)).toEqual([`${node.label?.toString()}`]);
expect(testTree.mFavorites[0].children.map((entry) => entry.label)).toEqual([node.label?.toString()]);
});
it("Checking attempt to add a member of favorite PDS", async () => {
createGlobalMocks();
Expand Down Expand Up @@ -1111,14 +1111,14 @@ describe("Dataset Tree Unit Tests - Function removeFavorite", () => {
await testTree.addFavorite(node1);
await testTree.addFavorite(node2);
const profileNodeInFavs = testTree.mFavorites[0];
expect(profileNodeInFavs.children[0].label).toBe(`${node1.label?.toString()}`);
expect(profileNodeInFavs.children[1].label).toBe(`${node2.label?.toString()}`);
expect(profileNodeInFavs.children[0].label).toBe(node1.label?.toString());
expect(profileNodeInFavs.children[1].label).toBe(node2.label?.toString());

// Actual test
await testTree.removeFavorite(profileNodeInFavs.children[0]);
expect(removeFavProfileSpy).not.toHaveBeenCalled();
expect(profileNodeInFavs.children.length).toBe(1);
expect(profileNodeInFavs.children[0].label).toBe(`${node2.label?.toString()}`);
expect(profileNodeInFavs.children[0].label).toBe(node2.label?.toString());
});
it("Checking removeFavorite when starting with only one favorite for the profile", async () => {
createGlobalMocks();
Expand All @@ -1139,7 +1139,7 @@ describe("Dataset Tree Unit Tests - Function removeFavorite", () => {
// First we need to have the item and be sure that it's properly added to have legit removal operation
await testTree.addFavorite(node);
const profileNodeInFavs = testTree.mFavorites[0];
expect(profileNodeInFavs.children[0].label).toBe(`${node.label?.toString()}`);
expect(profileNodeInFavs.children[0].label).toBe(node.label?.toString());
await testTree.removeFavorite(profileNodeInFavs.children[0]);
expect(removeFavProfileSpy).toHaveBeenCalledWith(profileNodeInFavs.label, false);
expect(testTree.mFavorites.length).toBe(0);
Expand Down Expand Up @@ -1862,7 +1862,7 @@ describe("Dataset Tree Unit Tests - Function findFavoritedNode", () => {
contextOverride: Constants.FAV_PROFILE_CONTEXT,
});
const favoriteNode = new ZoweDatasetNode({
label: `${node.label?.toString()}`,
label: node.label?.toString(),
collapsibleState: vscode.TreeItemCollapsibleState.Collapsed,
parentNode: favProfileNode,
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -558,10 +558,10 @@ describe("Shared Actions Unit Tests - Function refreshAll", () => {
const addedProfTypes = new Set<string>();
const removeSessionSpy = jest
.spyOn(TreeViewUtils, "removeSession")
.mockImplementation(async (treeProvider, profileName) => removedProfNames.add(profileName));
.mockImplementation((treeProvider, profileName) => removedProfNames.add(profileName) as any);
const addDefaultSessionSpy = jest
.spyOn(TreeViewUtils, "addDefaultSession")
.mockImplementation(async (treeProvider, profileType) => addedProfTypes.add(profileType));
.mockImplementation((treeProvider, profileType) => addedProfTypes.add(profileType) as any);
await SharedActions.refreshAll();
expect(removeSessionSpy).toHaveBeenCalledTimes(6);
expect([...removedProfNames]).toEqual(["zosmf", "zosmf2"]);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -444,7 +444,7 @@ describe("Test src/shared/extension", () => {
const spyRefreshAll = jest.spyOn(SharedActions, "refreshAll").mockImplementation(jest.fn());

// Setup watchers
await SharedInit.watchConfigProfile(context, { ds: "ds", uss: "uss", job: "job" } as any);
await SharedInit.watchConfigProfile(context);

expect(spyWatcher).toHaveBeenCalled();
expect(spyGuiError).not.toHaveBeenCalled();
Expand All @@ -471,7 +471,7 @@ describe("Test src/shared/extension", () => {
});
const spyGuiError = jest.spyOn(Gui, "errorMessage");

await SharedInit.watchConfigProfile(context, { ds: "ds", uss: "uss", job: "job" } as any);
await SharedInit.watchConfigProfile(context);

expect(spyWatcher).toHaveBeenCalled();
expect(spyGuiError.mock.calls[0][0]).toContain("vault changes");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,6 @@ describe("SpoolProvider Unit Tests", () => {
bindJesApi(jesApi);

const spoolOk: zosjobs.IJobFile = { ...iJobFile, stepname: "test", ddname: "dd", "record-count": 1, procstep: "proc" };
// const { id, ddname, stepname, ...withoutIdDdStep } = spoolOk;
const withoutIdDdStep: Partial<zosjobs.IJobFile> = JSON.parse(JSON.stringify(spoolOk));
delete withoutIdDdStep.id;
delete withoutIdDdStep.ddname;
Expand Down
8 changes: 2 additions & 6 deletions packages/zowe-explorer/src/trees/shared/SharedInit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -335,9 +335,7 @@ export class SharedInit {
const zoweWatcher = imperative.EventOperator.getWatcher().subscribeUser(imperative.ZoweUserEvents.ON_VAULT_CHANGED, async () => {
ZoweLogger.info(vscode.l10n.t("Changes in the credential vault detected, refreshing Zowe Explorer."));
await ProfilesUtils.readConfigFromDisk();
await SharedActions.refreshAll(providers.ds);
await SharedActions.refreshAll(providers.uss);
await SharedActions.refreshAll(providers.job);
await SharedActions.refreshAll();
ZoweExplorerApiRegister.getInstance().onVaultUpdateEmitter.fire(Validation.EventType.UPDATE);
});
context.subscriptions.push(new vscode.Disposable(zoweWatcher.close.bind(zoweWatcher)));
Expand All @@ -351,9 +349,7 @@ export class SharedInit {
async () => {
ZoweLogger.info(vscode.l10n.t("Changes in credential management detected, refreshing Zowe Explorer."));
await ProfilesUtils.getProfileInfo();
await SharedActions.refreshAll(providers.ds);
await SharedActions.refreshAll(providers.uss);
await SharedActions.refreshAll(providers.job);
await SharedActions.refreshAll();
ZoweExplorerApiRegister.getInstance().onCredMgrUpdateEmitter.fire(Validation.EventType.UPDATE);
}
);
Expand Down

0 comments on commit a8fa88b

Please sign in to comment.