Skip to content

Commit 68ad91d

Browse files
committed
testing
Signed-off-by: Amber <[email protected]>
1 parent 9332790 commit 68ad91d

File tree

3 files changed

+85
-20
lines changed

3 files changed

+85
-20
lines changed

packages/zowe-explorer/__tests__/__unit__/trees/dataset/DatasetTree.unit.test.ts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,15 @@ function createGlobalMocks() {
179179
return globalMocks;
180180
}
181181

182+
function makeDefaultMvsApi() {
183+
return {
184+
dataSet: jest.fn().mockResolvedValue({ apiResponse: { items: [] } }),
185+
allMembers: jest.fn().mockResolvedValue({ apiResponse: { items: [] } }),
186+
createDataSet: jest.fn().mockResolvedValue({ apiResponse: {} }),
187+
createDataSetMember: jest.fn().mockResolvedValue({ apiResponse: {} }),
188+
};
189+
}
190+
182191
describe("Dataset Tree Unit Tests - Initialisation", () => {
183192
function createBlockMocks() {
184193
const session = createISession();
@@ -5143,13 +5152,23 @@ describe("DataSetTree Unit Tests - Function handleDrop", () => {
51435152

51445153
describe("DatasetTree.handleDrop - blocking behavior", () => {
51455154
let dsTree: DatasetTree;
5155+
let originalGetMvsApiInDatasetTests: any;
51465156

51475157
beforeEach(() => {
51485158
jest.resetAllMocks();
51495159
jest.clearAllMocks();
51505160
dsTree = new DatasetTree();
5161+
jest.spyOn(ZoweExplorerApiRegister as any, "getMvsApi").mockImplementation(() => makeDefaultMvsApi());
5162+
originalGetMvsApiInDatasetTests = (ZoweExplorerApiRegister as any).getMvsApi;
5163+
(ZoweExplorerApiRegister as any).getMvsApi = jest.fn();
5164+
});
5165+
5166+
afterEach(() => {
5167+
(ZoweExplorerApiRegister as any).getMvsApi = originalGetMvsApiInDatasetTests;
5168+
jest.restoreAllMocks();
51515169
});
51525170

5171+
51535172
function makeDraggedPdsNode(dsn: string, session: any, profile: any) {
51545173
const sessionNode = createDatasetSessionNode(session, profile);
51555174
const pdsNode = new ZoweDatasetNode({

packages/zowe-explorer/__tests__/__unit__/trees/shared/SharedUtils.unit.test.ts

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ import { ZoweUSSNode } from "../../../../src/trees/uss/ZoweUSSNode";
2828
import { MockedProperty } from "../../../__mocks__/mockUtils";
2929
import { createIJobFile, createJobSessionNode } from "../../../__mocks__/mockCreators/jobs";
3030
import { JobFSProvider } from "../../../../src/trees/job/JobFSProvider";
31+
import { ZoweExplorerApiRegister } from "../../../../src/extending/ZoweExplorerApiRegister";
3132

3233
jest.mock("../../../../src/tools/ZoweLocalStorage");
3334

@@ -59,6 +60,27 @@ function createGlobalMocks() {
5960
return newMocks;
6061
}
6162

63+
function makeFakeMvsApiForDataSet(items: any[] = []) {
64+
return {
65+
dataSet: jest.fn().mockResolvedValue({ apiResponse: { items } }),
66+
// include allMembers too in case other tests call it
67+
allMembers: jest.fn().mockResolvedValue({ apiResponse: { items: [] } }),
68+
};
69+
}
70+
71+
function makeFakeMvsApi(items: any[] = []) {
72+
return {
73+
dataSet: jest.fn().mockResolvedValue({ apiResponse: { items } }),
74+
allMembers: jest.fn().mockResolvedValue({ apiResponse: { items: [] } }),
75+
};
76+
}
77+
78+
beforeEach(() => {
79+
jest.resetAllMocks();
80+
jest.clearAllMocks();
81+
jest.spyOn(ZoweExplorerApiRegister as any, "getMvsApi").mockImplementation(() => makeFakeMvsApi());
82+
});
83+
6284
describe("Shared Utils Unit Tests - Function node.concatChildNodes()", () => {
6385
it("Checks that concatChildNodes returns the proper array of children", async () => {
6486
const globalMocks = createGlobalMocks();
@@ -1517,13 +1539,18 @@ describe("SharedUtils.handleProfileChange", () => {
15171539

15181540
describe("SharedUtils helpers", () => {
15191541
const mockGetMvsApi = jest.fn();
1542+
let originalGetMvsApi: any;
15201543

15211544
beforeEach(() => {
15221545
jest.resetAllMocks();
15231546
jest.clearAllMocks();
1547+
1548+
originalGetMvsApi = (ZoweExplorerApiRegister as any).getMvsApi;
1549+
(ZoweExplorerApiRegister as any).getMvsApi = mockGetMvsApi;
15241550
});
15251551

15261552
afterEach(() => {
1553+
(ZoweExplorerApiRegister as any).getMvsApi = originalGetMvsApi;
15271554
jest.restoreAllMocks();
15281555
});
15291556

@@ -1548,7 +1575,10 @@ describe("SharedUtils helpers", () => {
15481575

15491576
const same = await SharedUtils.isSamePhysicalDataset(srcProfile, dstProfile, dsn);
15501577
expect(same).toBe(true);
1551-
expect(mockGetMvsApi).toHaveBeenCalledTimes(2);
1578+
1579+
// assert dataSet was called twice
1580+
expect((ZoweExplorerApiRegister.getMvsApi(srcProfile) as any).dataSet).toHaveBeenCalled();
1581+
expect((ZoweExplorerApiRegister.getMvsApi(dstProfile) as any).dataSet).toHaveBeenCalled();
15521582
});
15531583

15541584
test("isSamePhysicalDataset returns false when dst dataset missing", async () => {

packages/zowe-explorer/__tests__/__unit__/trees/uss/USSTree.unit.test.ts

Lines changed: 35 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -248,6 +248,19 @@ function createGlobalMocks() {
248248
return globalMocks;
249249
}
250250

251+
function makeDataTransferWithPayload(payload: any) {
252+
try {
253+
const dt = new vscode.DataTransfer();
254+
jest.spyOn(dt, "get").mockReturnValueOnce(payload);
255+
return dt;
256+
} catch {
257+
// Fallback for environments where vscode.DataTransfer cannot be constructed
258+
return {
259+
get: jest.fn().mockReturnValueOnce(payload),
260+
} as any;
261+
}
262+
}
263+
251264
describe("USSTree Unit Tests - Function initializeFavorites", () => {
252265
function createBlockMocks() {
253266
const session = createISession();
@@ -2283,16 +2296,17 @@ describe("USSTree.handleDrop - blocking behavior", () => {
22832296
[srcNode.resourceUri!.path]: srcNode,
22842297
});
22852298

2286-
// prep DataTransfer mock
2287-
const dataTransfer = new vscode.DataTransfer();
2288-
jest.spyOn(dataTransfer, "get").mockReturnValueOnce({
2289-
value: [
2290-
{
2291-
label: srcNode.label as string,
2292-
uri: srcNode.resourceUri,
2293-
},
2294-
],
2295-
} as any);
2299+
// Use a plain object with a get() mock instead of new vscode.DataTransfer()
2300+
const dataTransfer = {
2301+
get: jest.fn().mockReturnValueOnce({
2302+
value: [
2303+
{
2304+
label: srcNode.label as string,
2305+
uri: srcNode.resourceUri,
2306+
},
2307+
],
2308+
})
2309+
} as any;
22962310

22972311
// mock SharedUtils.same-path detection to return true
22982312
(SharedUtils as any).isLikelySameUssObjectByUris = jest.fn().mockResolvedValue(true);
@@ -2361,15 +2375,17 @@ describe("USSTree.handleDrop - blocking behavior", () => {
23612375
[srcFolder.resourceUri!.path]: srcFolder,
23622376
});
23632377

2364-
const dataTransfer = new vscode.DataTransfer();
2365-
jest.spyOn(dataTransfer, "get").mockReturnValueOnce({
2366-
value: [
2367-
{
2368-
label: srcFolder.label as string,
2369-
uri: srcFolder.resourceUri,
2370-
},
2371-
],
2372-
} as any);
2378+
// replace DataTransfer creation with plain object
2379+
const dataTransfer = {
2380+
get: jest.fn().mockReturnValueOnce({
2381+
value: [
2382+
{
2383+
label: srcFolder.label as string,
2384+
uri: srcFolder.resourceUri,
2385+
},
2386+
],
2387+
})
2388+
} as any;
23732389

23742390
(SharedUtils as any).hasNameCollision = jest.fn().mockReturnValue(true);
23752391
(SharedUtils as any).ERROR_SAME_OBJECT_DROP =

0 commit comments

Comments
 (0)