Skip to content

Commit

Permalink
fix(tests): Add missing 'onDidCollapseElement' function to mocks
Browse files Browse the repository at this point in the history
Signed-off-by: Trae Yelovich <[email protected]>
  • Loading branch information
traeok committed Sep 27, 2023
1 parent b35edb5 commit 4a581db
Show file tree
Hide file tree
Showing 18 changed files with 37 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ function createGlobalMocks() {
showWarningMessage: jest.fn(),
createOutputChannel: jest.fn(),
createQuickPick: jest.fn(),
createTreeView: jest.fn(),
createTreeView: jest.fn().mockReturnValue({ onDidCollapseElement: jest.fn() }),
createWebviewPanel: jest.fn(),
withProgress: jest.fn(),
showTextDocument: jest.fn(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,10 @@ async function createGlobalMocks() {
configurable: true,
});
Object.defineProperty(globals, "ISTHEIA", { get: () => false, configurable: true });
Object.defineProperty(vscode.window, "createTreeView", { value: jest.fn(), configurable: true });
Object.defineProperty(vscode.window, "createTreeView", {
value: jest.fn().mockReturnValue({ onDidCollapseElement: jest.fn() }),
configurable: true,
});
Object.defineProperty(vscode.workspace, "getConfiguration", {
value: newMocks.mockGetConfiguration,
configurable: true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,10 @@ describe("ZoweExplorerExtender unit tests", () => {
})
.mockReturnValue(newMocks.profiles),
});
Object.defineProperty(vscode.window, "createTreeView", { value: jest.fn(), configurable: true });
Object.defineProperty(vscode.window, "createTreeView", {
value: jest.fn().mockReturnValue({ onDidCollapseElement: jest.fn() }),
configurable: true,
});
Object.defineProperty(vscode.window, "showErrorMessage", {
value: newMocks.mockErrorMessage,
configurable: true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ async function createGlobalMocks() {
mockLoadNamedProfile: jest.fn(),
mockDefaultProfile: jest.fn(),
withProgress: jest.fn(),
createTreeView: jest.fn(),
createTreeView: jest.fn().mockReturnValue({ onDidCollapseElement: jest.fn() }),
mockAffects: jest.fn(),
mockEditSession: jest.fn(),
mockCheckCurrentProfile: jest.fn(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import { ZoweLogger } from "../../../src/utils/LoggerUtils";

describe("ZoweSaveQueue - unit tests", () => {
const createGlobalMocks = () => {
jest.spyOn(Gui, "createTreeView").mockReturnValue({ onDidCollapseElement: jest.fn() } as any);
const globalMocks = {
errorMessageSpy: jest.spyOn(Gui, "errorMessage"),
markDocumentUnsavedSpy: jest.spyOn(workspaceUtils, "markDocumentUnsaved"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,10 @@ function createGlobalMocks() {

globalMocks.mockProfileInstance = createInstanceOfProfile(globalMocks.testProfileLoaded);

Object.defineProperty(vscode.window, "createTreeView", { value: jest.fn(), configurable: true });
Object.defineProperty(vscode.window, "createTreeView", {
value: jest.fn().mockReturnValue({ onDidCollapseElement: jest.fn() }),
configurable: true,
});
Object.defineProperty(Gui, "showMessage", { value: jest.fn(), configurable: true });
Object.defineProperty(Gui, "setStatusBarMessage", { value: jest.fn().mockReturnValue({ dispose: jest.fn() }), configurable: true });
Object.defineProperty(vscode.window, "showTextDocument", { value: jest.fn(), configurable: true });
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ async function createGlobalMocks() {
mockMoveSync: jest.fn(),
mockGetAllProfileNames: jest.fn(),
mockReveal: jest.fn(),
mockCreateTreeView: jest.fn(),
mockCreateTreeView: jest.fn().mockReturnValue({ onDidCollapseElement: jest.fn() }),
mockExecuteCommand: jest.fn(),
mockRegisterCommand: jest.fn(),
mockOnDidSaveTextDocument: jest.fn(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import * as vscode from "vscode";

describe("Checking icon generator's basics", () => {
const setGlobalMocks = () => {
const createTreeView = jest.fn();
const createTreeView = jest.fn().mockReturnValue({ onDidCollapseElement: jest.fn() });
const getConfiguration = jest.fn();

Object.defineProperty(vscode.window, "createTreeView", { value: createTreeView });
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ jest.mock("vscode");

describe("Checking message generator's basics", () => {
const setGlobalMocks = () => {
const createTreeView = jest.fn();
const createTreeView = jest.fn().mockReturnValue({ onDidCollapseElement: jest.fn() });
const getConfiguration = jest.fn();

Object.defineProperty(vscode.window, "createTreeView", { value: createTreeView });
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ async function createGlobalMocks() {
mockGetJob: jest.fn(),
mockRefresh: jest.fn(),
mockAffectsConfig: jest.fn(),
createTreeView: jest.fn(),
createTreeView: jest.fn().mockReturnValue({ onDidCollapseElement: jest.fn() }),
mockGetSpoolFiles: jest.fn(),
mockDeleteJobs: jest.fn(),
mockShowInputBox: jest.fn(),
Expand Down Expand Up @@ -85,7 +85,7 @@ async function createGlobalMocks() {
};
}),
};

jest.spyOn(Gui, "createTreeView").mockImplementation(globalMocks.createTreeView);
Object.defineProperty(ProfilesCache, "getConfigInstance", {
value: jest.fn(() => {
return {
Expand Down Expand Up @@ -173,7 +173,6 @@ async function createGlobalMocks() {
Object.defineProperty(ZoweLogger, "warn", { value: jest.fn(), configurable: true });
Object.defineProperty(ZoweLogger, "info", { value: jest.fn(), configurable: true });
Object.defineProperty(ZoweLogger, "trace", { value: jest.fn(), configurable: true });
globalMocks.createTreeView.mockReturnValue("testTreeView");
globalMocks.testSessionNode = createJobSessionNode(globalMocks.testSession, globalMocks.testProfile);
globalMocks.mockGetJob.mockReturnValue(globalMocks.testIJob);
globalMocks.mockGetJobsByOwnerAndPrefix.mockReturnValue([globalMocks.testIJob, globalMocks.testIJobComplete]);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ async function createGlobalMocks() {
mockAffectsConfig: jest.fn(),
createTreeView: jest.fn(() => ({
reveal: jest.fn(),
onDidCollapseElement: jest.fn(),
})),
mockCreateSessCfgFromArgs: jest.fn(),
mockGetSpoolFiles: jest.fn(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ import { SpoolFile } from "../../../src/SpoolProvider";
const activeTextEditorDocument = jest.fn();

function createGlobalMocks() {
jest.spyOn(Gui, "createTreeView").mockReturnValue({ onDidCollapseElement: jest.fn() } as any);
Object.defineProperty(vscode.workspace, "getConfiguration", {
value: jest.fn().mockImplementation(() => new Map([["zowe.jobs.confirmSubmission", false]])),
configurable: true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,10 @@ async function createGlobalMocks() {
}),
configurable: true,
});
Object.defineProperty(vscode.window, "createTreeView", { value: jest.fn(), configurable: true });
Object.defineProperty(vscode.window, "createTreeView", {
value: jest.fn().mockReturnValue({ onDidCollapseElement: jest.fn() }),
configurable: true,
});
Object.defineProperty(vscode.workspace, "getConfiguration", { value: jest.fn(), configurable: true });
Object.defineProperty(vscode.window, "showInformationMessage", { value: jest.fn(), configurable: true });
Object.defineProperty(vscode.window, "showInputBox", { value: jest.fn(), configurable: true });
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ import { ZoweLogger } from "../../../src/utils/LoggerUtils";
function createGlobalMocks() {
const globalMocks = {
session: createISessionWithoutCredentials(),
createTreeView: jest.fn(),
createTreeView: jest.fn().mockReturnValue({ onDidCollapseElement: jest.fn() }),
mockLog: jest.fn(),
mockDebug: jest.fn(),
mockError: jest.fn(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ async function createGlobalMocks() {
showInputBox: jest.fn(),
filters: jest.fn(),
getFilters: jest.fn(),
createTreeView: jest.fn(),
createTreeView: jest.fn().mockReturnValue({ onDidCollapseElement: jest.fn() }),
createQuickPick: jest.fn(),
getConfiguration: jest.fn(),
ZosmfSession: jest.fn(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,10 @@ async function createGlobalMocks() {
configurable: true,
});
Object.defineProperty(vscode.window, "showInputBox", { value: globalMocks.showInputBox, configurable: true });
Object.defineProperty(vscode.window, "createTreeView", { value: jest.fn(), configurable: true });
Object.defineProperty(vscode.window, "createTreeView", {
value: jest.fn().mockReturnValue({ onDidCollapseElement: jest.fn() }),
configurable: true,
});
Object.defineProperty(zowe, "ZosmfSession", { value: globalMocks.ZosmfSession, configurable: true });
Object.defineProperty(globalMocks.ZosmfSession, "createSessCfgFromArgs", {
value: globalMocks.createSessCfgFromArgs,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ function createGlobalMocks() {
setStatusBarMessage: jest.fn().mockReturnValue({ dispose: jest.fn() }),
showWarningMessage: jest.fn(),
showErrorMessage: jest.fn(),
createTreeView: jest.fn(),
createTreeView: jest.fn().mockReturnValue({ onDidCollapseElement: jest.fn() }),
fileToUSSFile: jest.fn(),
Upload: jest.fn(),
isBinaryFileSync: jest.fn(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,10 @@ describe("SessionUtils removeSession Unit Tests", () => {
newMocks.datasetSessionNode = createDatasetSessionNode(newMocks.session, newMocks.imperativeProfile);
newMocks.testDatasetTree = createDatasetTree(newMocks.datasetSessionNode, newMocks.treeView);
newMocks.testDatasetTree.addFileHistory("[profile1]: TEST.NODE");
Object.defineProperty(vscode.window, "createTreeView", { value: jest.fn(), configurable: true });
Object.defineProperty(vscode.window, "createTreeView", {
value: jest.fn().mockReturnValue({ onDidCollapseElement: jest.fn() }),
configurable: true,
});
Object.defineProperty(vscode, "ConfigurationTarget", { value: jest.fn(), configurable: true });
newMocks.mockGetConfiguration.mockReturnValue(createPersistentConfig());
Object.defineProperty(vscode.workspace, "getConfiguration", {
Expand Down

0 comments on commit 4a581db

Please sign in to comment.