Skip to content

Commit

Permalink
Merge branch 'main' into fix/att-view-refresh
Browse files Browse the repository at this point in the history
  • Loading branch information
JillieBeanSim authored Dec 16, 2024
2 parents 0c37df4 + 080a8d9 commit 8a5b210
Show file tree
Hide file tree
Showing 12 changed files with 992 additions and 13 deletions.
1 change: 1 addition & 0 deletions packages/zowe-explorer-api/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ All notable changes to the "zowe-explorer-api" extension will be documented in t
- Added support for extenders to obtain an updated Session that will includes VS Code proxy settings values if set, `getProfileSessionWithVscProxy`. [#3010](https://github.com/zowe/zowe-explorer-vscode/issues/3010)
- Added support for VS Code proxy settings with zosmf profile types. [#3010](https://github.com/zowe/zowe-explorer-vscode/issues/3010)
- Added optional `getLocalStorage` function to the `IApiExplorerExtender` interface to expose local storage access to Zowe Explorer extenders. [#3180](https://github.com/zowe/zowe-explorer-vscode/issues/3180)
- Added optional `setEncoding`, `getEncoding`, and `getEncodingInMap` functions to the `IZoweJobTreeNode` interface. [#3361](https://github.com/zowe/zowe-explorer-vscode/pull/3361)

### Bug fixes

Expand Down
31 changes: 31 additions & 0 deletions packages/zowe-explorer-api/src/tree/IZoweTreeNode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -503,4 +503,35 @@ export interface IZoweJobTreeNode extends IZoweTreeNode {
* @returns {Promise<IZoweJobTreeNode[]>}
*/
getChildren(): Promise<IZoweJobTreeNode[]>;

/**
* Sets the encoding of the job node
*
* @returns {void | PromiseLike<void>}
*/
setEncoding?(encoding: ZosEncoding): void | PromiseLike<void>;

/**
* Gets the encoding of the job node
*
* @returns {ZosEncoding | PromiseLike<ZosEncoding>}
*/
getEncoding?(): ZosEncoding | PromiseLike<ZosEncoding>;

/**
* Gets the encoding of a job node given a path
*
* @param {string} uriPath the path of the node
* @returns {ZosEncoding | PromiseLike<ZosEncoding>}
*/
getEncodingInMap?(uriPath: string): ZosEncoding | PromiseLike<ZosEncoding>;

/**
* Updates the encoding of a job node given a path
*
* @param {string} uriPath the path of the node
* @param {ZosEncoding} encoding the encoding to apply
* @returns {void | PromiseLike<void>}
*/
updateEncodingInMap?(uriPath: string, encoding: ZosEncoding): void | PromiseLike<void>;
}
1 change: 1 addition & 0 deletions packages/zowe-explorer/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ All notable changes to the "vscode-extension-for-zowe" extension will be documen
- Allow extenders to add context menu actions to a top level node, i.e. data sets, USS, Jobs, by encoding the profile type in the context value. [#3309](https://github.com/zowe/zowe-explorer-vscode/pull/3309)
- You can now add multiple partitioned data sets or USS directories to your workspace at once using the "Add to Workspace" feature. [#3324](https://github.com/zowe/zowe-explorer-vscode/issues/3324)
- Exposed read and write access to local storage keys for Zowe Explorer extenders. [#3180](https://github.com/zowe/zowe-explorer-vscode/issues/3180)
- Added `Open with Encoding` to the context menu of Job Spool files. [#1941](https://github.com/zowe/zowe-explorer-vscode/issues/1941)

### Bug fixes

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,7 @@ const testEntries = {
profile: testProfile,
path: "/TESTJOB(JOB1234) - ACTIVE/JES2.JESMSGLG.2",
},
spool: {
id: "SOMEID",
} as any,
spool: createIJobFile(),
} as SpoolEntry,
session: {
...new FilterEntry("sestest"),
Expand Down Expand Up @@ -226,6 +224,44 @@ describe("fetchSpoolAtUri", () => {
lookupAsFileMock.mockRestore();
});

it("fetches the spool contents for a given URI - downloadSingleSpool w/ binary encoding", async () => {
const lookupAsFileMock = jest
.spyOn(JobFSProvider.instance as any, "_lookupAsFile")
.mockReturnValueOnce({ ...testEntries.spool, data: new Uint8Array(), encoding: { kind: "binary" } });
const newData = "spool contents";
const mockJesApi = {
downloadSingleSpool: jest.fn((opts) => {
opts.stream.write(newData);
}),
};
const jesApiMock = jest.spyOn(ZoweExplorerApiRegister, "getJesApi").mockReturnValueOnce(mockJesApi as any);
const entry = await JobFSProvider.instance.fetchSpoolAtUri(testUris.spool);
expect(mockJesApi.downloadSingleSpool).toHaveBeenCalledWith(expect.objectContaining({ jobFile: testEntries.spool.spool, binary: true }));
expect(entry.data.toString()).toStrictEqual(newData.toString());
jesApiMock.mockRestore();
lookupAsFileMock.mockRestore();
});

it("fetches the spool contents for a given URI - downloadSingleSpool w/ other encoding", async () => {
const lookupAsFileMock = jest
.spyOn(JobFSProvider.instance as any, "_lookupAsFile")
.mockReturnValueOnce({ ...testEntries.spool, data: new Uint8Array(), encoding: { kind: "other", codepage: "IBM-1147" } });
const newData = "spool contents";
const mockJesApi = {
downloadSingleSpool: jest.fn((opts) => {
opts.stream.write(newData);
}),
};
const jesApiMock = jest.spyOn(ZoweExplorerApiRegister, "getJesApi").mockReturnValueOnce(mockJesApi as any);
const entry = await JobFSProvider.instance.fetchSpoolAtUri(testUris.spool);
expect(mockJesApi.downloadSingleSpool).toHaveBeenCalledWith(
expect.objectContaining({ jobFile: testEntries.spool.spool, encoding: "IBM-1147", binary: false })
);
expect(entry.data.toString()).toStrictEqual(newData.toString());
jesApiMock.mockRestore();
lookupAsFileMock.mockRestore();
});

it("fetches the spool contents for a given URI - getSpoolContentById", async () => {
const lookupAsFileMock = jest
.spyOn(JobFSProvider.instance as any, "_lookupAsFile")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

import * as vscode from "vscode";
import * as zosjobs from "@zowe/zos-jobs-for-zowe-sdk";
import { Gui, imperative, IZoweJobTreeNode, ProfilesCache, Validation, Poller } from "@zowe/zowe-explorer-api";
import { Gui, imperative, IZoweJobTreeNode, ProfilesCache, Validation, Poller, ZosEncoding } from "@zowe/zowe-explorer-api";
import { createIJobFile, createIJobObject, createJobFavoritesNode, createJobSessionNode, MockJobDetail } from "../../../__mocks__/mockCreators/jobs";
import {
createIProfile,
Expand Down Expand Up @@ -1167,3 +1167,147 @@ describe("ZosJobsProvider Unit Test - Filter Jobs", () => {
expect(filterJobsSpy).toHaveBeenCalledWith(node1);
});
});

describe("openWithEncoding", () => {
beforeEach(async () => {
await createGlobalMocks();
jest.restoreAllMocks();
});
afterEach(() => {
jest.restoreAllMocks();
});
it("should open a Job Spool file with an encoding (binary, prompted)", async () => {
const testTree = new JobTree();

const spoolNode = new ZoweSpoolNode({ label: "SPOOL", collapsibleState: vscode.TreeItemCollapsibleState.None, spool: createIJobFile() });

const encoding: ZosEncoding = { kind: "binary" };

const promptMock = jest.spyOn(SharedUtils, "promptForEncoding").mockResolvedValue(encoding);
const executeCommandMock = jest.spyOn(vscode.commands, "executeCommand").mockImplementation();
const fetchSpoolAtUriMock = jest.spyOn(JobFSProvider.instance, "fetchSpoolAtUri").mockImplementation();
const setEncodingSpy = jest.spyOn(spoolNode, "setEncoding").mockImplementation();

await testTree.openWithEncoding(spoolNode);
expect(promptMock).toHaveBeenCalledWith(spoolNode);
expect(promptMock).toHaveBeenCalledTimes(1);
expect(setEncodingSpy).toHaveBeenCalledWith(encoding);
expect(fetchSpoolAtUriMock).toHaveBeenCalledTimes(1);
expect(executeCommandMock).toHaveBeenCalledTimes(1);
});

it("should open a Job Spool file with an encoding (binary, provided)", async () => {
const testTree = new JobTree();

const spoolNode = new ZoweSpoolNode({ label: "SPOOL", collapsibleState: vscode.TreeItemCollapsibleState.None, spool: createIJobFile() });

const encoding: ZosEncoding = { kind: "binary" };

const promptMock = jest.spyOn(SharedUtils, "promptForEncoding");
const executeCommandMock = jest.spyOn(vscode.commands, "executeCommand").mockImplementation();
const setEncodingSpy = jest.spyOn(spoolNode, "setEncoding").mockImplementation();
const fetchSpoolAtUriMock = jest.spyOn(JobFSProvider.instance, "fetchSpoolAtUri").mockImplementation();

await testTree.openWithEncoding(spoolNode, encoding);
expect(promptMock).toHaveBeenCalledTimes(0);
expect(setEncodingSpy).toHaveBeenCalledWith(encoding);
expect(fetchSpoolAtUriMock).toHaveBeenCalledTimes(1);
expect(executeCommandMock).toHaveBeenCalledTimes(1);
});

it("should open a Job Spool file with an encoding (ascii, prompted)", async () => {
const testTree = new JobTree();

const spoolNode = new ZoweSpoolNode({ label: "SPOOL", collapsibleState: vscode.TreeItemCollapsibleState.None, spool: createIJobFile() });

const encoding: ZosEncoding = { kind: "text" };

const promptMock = jest.spyOn(SharedUtils, "promptForEncoding").mockResolvedValue(encoding);
const executeCommandMock = jest.spyOn(vscode.commands, "executeCommand").mockImplementation();
const fetchSpoolAtUriMock = jest.spyOn(JobFSProvider.instance, "fetchSpoolAtUri").mockImplementation();
const setEncodingSpy = jest.spyOn(spoolNode, "setEncoding").mockImplementation();

await testTree.openWithEncoding(spoolNode);
expect(promptMock).toHaveBeenCalledWith(spoolNode);
expect(promptMock).toHaveBeenCalledTimes(1);
expect(setEncodingSpy).toHaveBeenCalledWith(encoding);
expect(fetchSpoolAtUriMock).toHaveBeenCalledTimes(1);
expect(executeCommandMock).toHaveBeenCalledTimes(1);
});

it("should open a Job Spool file with an encoding (ascii, provided)", async () => {
const testTree = new JobTree();

const spoolNode = new ZoweSpoolNode({ label: "SPOOL", collapsibleState: vscode.TreeItemCollapsibleState.None, spool: createIJobFile() });

const encoding: ZosEncoding = { kind: "text" };

const promptMock = jest.spyOn(SharedUtils, "promptForEncoding");
const executeCommandMock = jest.spyOn(vscode.commands, "executeCommand").mockImplementation();
const setEncodingSpy = jest.spyOn(spoolNode, "setEncoding").mockImplementation();
const fetchSpoolAtUriMock = jest.spyOn(JobFSProvider.instance, "fetchSpoolAtUri").mockImplementation();

await testTree.openWithEncoding(spoolNode, encoding);
expect(promptMock).toHaveBeenCalledTimes(0);
expect(setEncodingSpy).toHaveBeenCalledWith(encoding);
expect(fetchSpoolAtUriMock).toHaveBeenCalledTimes(1);
expect(executeCommandMock).toHaveBeenCalledTimes(1);
});

it("should open a Job Spool file with an encoding (other, prompted)", async () => {
const testTree = new JobTree();

const spoolNode = new ZoweSpoolNode({ label: "SPOOL", collapsibleState: vscode.TreeItemCollapsibleState.None, spool: createIJobFile() });

const encoding: ZosEncoding = { kind: "other", codepage: "IBM-1147" };

const promptMock = jest.spyOn(SharedUtils, "promptForEncoding").mockResolvedValue(encoding);
const executeCommandMock = jest.spyOn(vscode.commands, "executeCommand").mockImplementation();
const fetchSpoolAtUriMock = jest.spyOn(JobFSProvider.instance, "fetchSpoolAtUri").mockImplementation();
const setEncodingSpy = jest.spyOn(spoolNode, "setEncoding").mockImplementation();

await testTree.openWithEncoding(spoolNode);
expect(promptMock).toHaveBeenCalledWith(spoolNode);
expect(promptMock).toHaveBeenCalledTimes(1);
expect(setEncodingSpy).toHaveBeenCalledWith(encoding);
expect(fetchSpoolAtUriMock).toHaveBeenCalledTimes(1);
expect(executeCommandMock).toHaveBeenCalledTimes(1);
});

it("should open a Job Spool file with an encoding (other, provided)", async () => {
const testTree = new JobTree();

const spoolNode = new ZoweSpoolNode({ label: "SPOOL", collapsibleState: vscode.TreeItemCollapsibleState.None, spool: createIJobFile() });

const encoding: ZosEncoding = { kind: "other", codepage: "IBM-1147" };

const promptMock = jest.spyOn(SharedUtils, "promptForEncoding");
const executeCommandMock = jest.spyOn(vscode.commands, "executeCommand").mockImplementation();
const setEncodingSpy = jest.spyOn(spoolNode, "setEncoding").mockImplementation();
const fetchSpoolAtUriMock = jest.spyOn(JobFSProvider.instance, "fetchSpoolAtUri").mockImplementation();

await testTree.openWithEncoding(spoolNode, encoding);
expect(promptMock).toHaveBeenCalledTimes(0);
expect(setEncodingSpy).toHaveBeenCalledWith(encoding);
expect(fetchSpoolAtUriMock).toHaveBeenCalledTimes(1);
expect(executeCommandMock).toHaveBeenCalledTimes(1);
});

it("should open a Job Spool file with an encoding (undefined, prompted)", async () => {
const testTree = new JobTree();

const spoolNode = new ZoweSpoolNode({ label: "SPOOL", collapsibleState: vscode.TreeItemCollapsibleState.None, spool: createIJobFile() });

const promptMock = jest.spyOn(SharedUtils, "promptForEncoding").mockResolvedValue(undefined);
const executeCommandMock = jest.spyOn(vscode.commands, "executeCommand").mockImplementation();
const fetchSpoolAtUriMock = jest.spyOn(JobFSProvider.instance, "fetchSpoolAtUri").mockImplementation();
const setEncodingSpy = jest.spyOn(spoolNode, "setEncoding").mockImplementation();

await testTree.openWithEncoding(spoolNode);
expect(promptMock).toHaveBeenCalledWith(spoolNode);
expect(promptMock).toHaveBeenCalledTimes(1);
expect(setEncodingSpy).toHaveBeenCalledTimes(0);
expect(fetchSpoolAtUriMock).toHaveBeenCalledTimes(0);
expect(executeCommandMock).toHaveBeenCalledTimes(0);
});
});
Loading

0 comments on commit 8a5b210

Please sign in to comment.