Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/uss/copy #2004

Merged
merged 44 commits into from
Dec 13, 2022
Merged
Show file tree
Hide file tree
Changes from 36 commits
Commits
Show all changes
44 commits
Select commit Hold shift + click to select a range
d3cb664
copy local files & upload copies to mainframe
KutluOzel-b Nov 7, 2022
066b718
merge main
KutluOzel-b Nov 7, 2022
c6b0da6
add unit tests
KutluOzel-b Nov 9, 2022
9841d37
Merge branch 'main' of https://github.com/zowe/vscode-extension-for-z…
KutluOzel-b Nov 9, 2022
3f7d91b
modified changelog
KutluOzel-b Nov 9, 2022
7c8837a
resolved lint issues
KutluOzel-b Nov 9, 2022
974245e
fix correct changelog
KutluOzel-b Nov 9, 2022
81e5357
fix correct changelog
KutluOzel-b Nov 9, 2022
9f03414
removed duplications on tests
KutluOzel-b Nov 9, 2022
31dd637
removed unused imports
KutluOzel-b Nov 9, 2022
0858284
removed unused tests
KutluOzel-b Nov 9, 2022
43e0d69
removed mistakenly written line on changelog
KutluOzel-b Nov 9, 2022
6c7c957
add changelog updated explorer api version
KutluOzel-b Nov 9, 2022
0647d2d
add changelog updated explorer api version
KutluOzel-b Nov 9, 2022
08f786b
revert changelog for es lint
KutluOzel-b Nov 9, 2022
c77658b
Merge branch 'main' into feature/uss/copy
JillieBeanSim Nov 14, 2022
288efac
Merge branch 'main' into feature/uss/copy
JillieBeanSim Nov 28, 2022
767a703
adressed comments
KutluOzel-b Nov 29, 2022
5800a88
Merge branch 'main' into feature/uss/copy
KutluOzel-b Nov 29, 2022
2d71a28
fix download async & add progress bar
KutluOzel-b Nov 30, 2022
ff749bc
modified tests
KutluOzel-b Nov 30, 2022
804ca81
lint issues adressed
KutluOzel-b Nov 30, 2022
1504763
modified testes
KutluOzel-b Nov 30, 2022
8ba15f7
add test for getSelectedNodes
KutluOzel-b Dec 1, 2022
083d775
adressed a lint issue
KutluOzel-b Dec 1, 2022
652f18b
refactor action calls and tests
KutluOzel-b Dec 1, 2022
8854e84
Merge branch 'main' into feature/uss/copy
KutluOzel-b Dec 1, 2022
7dab3c2
fix code smells
KutluOzel-b Dec 1, 2022
8e39370
Merge branch 'feature/uss/copy' of https://github.com/zowe/vscode-ext…
KutluOzel-b Dec 1, 2022
470229c
Merge branch 'main' into feature/uss/copy
KutluOzel-b Dec 6, 2022
e2e08be
changelog prettier
KutluOzel-b Dec 6, 2022
c99252c
adressed comments
KutluOzel-b Dec 6, 2022
9b2e5ae
make codecov happy
KutluOzel-b Dec 8, 2022
3c9213b
merge main
KutluOzel-b Dec 8, 2022
d96dbbf
Merge branch 'main' into feature/uss/copy
KutluOzel-b Dec 9, 2022
612001f
Merge branch 'main' into feature/uss/copy
JillieBeanSim Dec 9, 2022
f0b0783
adressed windows problem
KutluOzel-b Dec 12, 2022
4f79698
Merge branch 'feature/uss/copy' of https://github.com/zowe/vscode-ext…
KutluOzel-b Dec 12, 2022
8b1237f
removed duplicated method of getSelectedNodeList
KutluOzel-b Dec 12, 2022
efb52cc
fix tests
KutluOzel-b Dec 12, 2022
b38def4
Merge branch 'main' into feature/uss/copy
JillieBeanSim Dec 13, 2022
1cdd32c
modified copy label in context menun
KutluOzel-b Dec 13, 2022
d85d3bc
Merge branch 'main' into feature/uss/copy
KutluOzel-b Dec 13, 2022
7117c10
Merge branch 'main' into feature/uss/copy
JillieBeanSim Dec 13, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions packages/zowe-explorer-api/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ All notable changes to the "zowe-explorer-api" extension will be documented in t

## TBD Release

- copy api for files and directories on USS tree ( paste selected local files into current node )

## `2.4.1`

### New features and enhancements

- New API call `getJobsByParameters` to allow filtering jobs by status.
Expand Down
5 changes: 5 additions & 0 deletions packages/zowe-explorer-api/src/tree/IZoweTreeNode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,11 @@ export interface IZoweUSSTreeNode extends IZoweTreeNode {
* @param {USSTree} ussFileProvider
*/
saveSearch?(ussFileProvider: IZoweTree<IZoweUSSTreeNode>);
/**
* uploads selected uss node(s) to from clipboard to mainframe
*
*/
copyUssFile?();
}

/**
Expand Down
1 change: 1 addition & 0 deletions packages/zowe-explorer/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ All notable changes to the "vscode-extension-for-zowe" extension will be documen

## TBD Release

-Add multiselect copy/paste feature on uss view [#1549](https://github.com/zowe/vscode-extension-for-zowe/issues/1549)
-Multiple select for hide session [#1555](https://github.com/zowe/vscode-extension-for-zowe/issues/1555)

### New features and enhancements
Expand Down
47 changes: 47 additions & 0 deletions packages/zowe-explorer/__tests__/__unit__/extension.unit.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import { Profiles } from "../../src/Profiles";
import { ZoweDatasetNode } from "../../src/dataset/ZoweDatasetNode";
import { createInstanceOfProfileInfo, createIProfile, createTreeView } from "../../__mocks__/mockCreators/shared";
import { PersistentFilters } from "../../src/PersistentFilters";
import { ZoweUSSNode } from "../../src/uss/ZoweUSSNode";

jest.mock("vscode");
jest.mock("fs");
Expand Down Expand Up @@ -194,6 +195,8 @@ async function createGlobalMocks() {
"zowe.uss.enableValidation",
"zowe.uss.ssoLogin",
"zowe.uss.ssoLogout",
"zowe.uss.pasteUssFile",
"zowe.uss.copyUssFile",
"zowe.jobs.zosJobsOpenspool",
"zowe.jobs.deleteJob",
"zowe.jobs.runModifyCommand",
Expand Down Expand Up @@ -383,6 +386,35 @@ async function createGlobalMocks() {
}

describe("Extension Unit Tests", () => {
function createBlockMocks(globalMocks: any) {
const blockMocks = {
rootNode: new ZoweUSSNode(
"root",
vscode.TreeItemCollapsibleState.Collapsed,
null,
globalMocks.session,
null,
false,
"test",
undefined
),
testNode: null,
};
blockMocks.testNode = new ZoweUSSNode(
globals.DS_PDS_CONTEXT,
vscode.TreeItemCollapsibleState.Collapsed,
blockMocks.rootNode,
null,
null,
false,
"test",
undefined
);

blockMocks.rootNode.contextValue = globals.USS_SESSION_CONTEXT;
return blockMocks;
}

it("Testing that activate correctly executes", async () => {
const globalMocks = await createGlobalMocks();
Object.defineProperty(zowe.imperative, "ProfileInfo", {
Expand Down Expand Up @@ -489,4 +521,19 @@ describe("Extension Unit Tests", () => {
});
expect(actualCommands).toEqual(globalMocks.expectedCommands);
});

it("Tests getSelectedNodeList executes successfully with multiple selection", async () => {
const globalMocks = await createGlobalMocks();
const blockMocks = createBlockMocks(globalMocks);
const nodeList = [blockMocks.rootNode, blockMocks.testNode];
const res = extension.getSelectedNodeList(blockMocks.testNode, nodeList);
expect(res).toEqual(nodeList);
});

it("Tests getSelectedNodeList executes successfully when no multiple selection", async () => {
const globalMocks = await createGlobalMocks();
const blockMocks = createBlockMocks(globalMocks);
const res = extension.getSelectedNodeList(blockMocks.testNode, undefined);
expect(res[0]).toEqual(blockMocks.testNode);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ import * as path from "path";
import * as workspaceUtils from "../../../src/utils/workspace";
import * as globals from "../../../src/globals";
import * as ussUtils from "../../../src/uss/utils";

jest.mock("fs");
jest.mock("path");

Expand Down Expand Up @@ -73,6 +72,8 @@ async function createGlobalMocks() {
ussApi: null,
mockShowWarningMessage: jest.fn(),
fileExistsCaseSensitveSync: jest.fn(),
readText: jest.fn(),
fileToUSSFile: jest.fn(),
};

globalMocks.openTextDocument.mockResolvedValue(globalMocks.mockTextDocument);
Expand Down Expand Up @@ -158,6 +159,7 @@ async function createGlobalMocks() {
value: globalMocks.fileExistsCaseSensitveSync,
configurable: true,
});
Object.defineProperty(vscode.env.clipboard, "readText", { value: globalMocks.readText, configurable: true });

return globalMocks;
}
Expand Down Expand Up @@ -1583,3 +1585,148 @@ describe("ZoweUSSNode Unit Tests - Function node.initializeFileOpening()", () =>
expect(globalMocks.mockShowTextDocument).toBeCalledWith(globalMocks.mockTextDocument, { preview: false });
});
});

describe("ZoweUSSNode Unit Tests - Function node.copyUssFile()", () => {
function createIProfileFakeEncoding(): zowe.imperative.IProfileLoaded {
return {
name: "fakeProfile",
profile: {
host: "fake",
port: 999,
user: undefined,
password: undefined,
rejectUnauthorize: false,
encoding: "fake",
},
type: "zosmf",
message: "",
failNotFound: false,
};
}
function createBlockMocks(globalMocks: any) {
globalMocks.mockLoadNamedProfile.mockReturnValue(createIProfileFakeEncoding());
Object.defineProperty(Profiles, "getInstance", {
value: jest.fn(() => {
return {
allProfiles: [{ name: "firstName" }, { name: "secondName" }],
defaultProfile: { name: "firstName" },
getDefaultProfile: globalMocks.mockLoadNamedProfile,
promptCredentials: jest.fn(() => {
return ["fake", "fake", "fake"];
}),
loadNamedProfile: globalMocks.mockLoadNamedProfile,
usesSecurity: true,
validProfile: ValidProfileEnum.VALID,
checkCurrentProfile: jest.fn(() => {
return newMocks.profile;
}),
validateProfiles: jest.fn(),
getProfiles: jest.fn(() => {
return [
{ name: createIProfileFakeEncoding().name, profile: createIProfileFakeEncoding().profile },
{ name: createIProfileFakeEncoding().name, profile: createIProfileFakeEncoding().profile },
];
}),
refresh: jest.fn(),
};
}),
});

const newMocks = {
profile: createIProfileFakeEncoding(),
fileResponse: createFileResponse({
items: [{ name: "testFile" }, { name: "testFile2" }],
}),
fileResponseSame: createFileResponse({
items: [{ name: "file" }, { name: "file2" }],
}),
fileResponseEmpty: {
success: true,
commandResponse: "",
apiResponse: undefined,
},
mockUssApi: ZoweExplorerApiRegister.getUssApi(createIProfileFakeEncoding()),
getUssApiMock: jest.fn(),
testNode: new ZoweUSSNode(
"root",
vscode.TreeItemCollapsibleState.Collapsed,
null,
globalMocks.session,
null,
false,
createIProfileFakeEncoding().name,
undefined,
createIProfileFakeEncoding()
),
};

newMocks.testNode.fullPath = "/users/temp/test";
newMocks.getUssApiMock.mockReturnValue(newMocks.mockUssApi);
ZoweExplorerApiRegister.getUssApi = newMocks.getUssApiMock.bind(ZoweExplorerApiRegister);

return newMocks;
}
it("Tests node.copyUssFile() reads clipboard contents and upload directory & file sucessfully", async () => {
const globalMocks = await createGlobalMocks();

globalMocks.readText.mockResolvedValueOnce("users/directory/file,users/directory/");
const blockMocks = createBlockMocks(globalMocks);

jest.spyOn(blockMocks.mockUssApi, "fileList").mockResolvedValueOnce(blockMocks.fileResponse);
jest.spyOn(blockMocks.mockUssApi, "putContent").mockResolvedValueOnce(blockMocks.fileResponse);
jest.spyOn(blockMocks.mockUssApi, "uploadDirectory").mockResolvedValueOnce(blockMocks.fileResponse);

await blockMocks.testNode.copyUssFile();
});

it("Tests node.copyUssFile() reads clipboard contents finds same file name on destination directory", async () => {
const globalMocks = await createGlobalMocks();

globalMocks.readText.mockResolvedValueOnce("users/directory/file,users/directory/");
const blockMocks = createBlockMocks(globalMocks);

jest.spyOn(blockMocks.mockUssApi, "fileList").mockResolvedValueOnce(blockMocks.fileResponseSame);
jest.spyOn(blockMocks.mockUssApi, "putContent").mockResolvedValueOnce(blockMocks.fileResponseSame);
jest.spyOn(blockMocks.mockUssApi, "uploadDirectory").mockResolvedValueOnce(blockMocks.fileResponseSame);

await blockMocks.testNode.copyUssFile();
});

it("Tests node.copyUssFile() could not retriieve fileList api response", async () => {
const globalMocks = await createGlobalMocks();

globalMocks.readText.mockResolvedValueOnce("users/directory/file,users/directory/");
const blockMocks = createBlockMocks(globalMocks);

jest.spyOn(blockMocks.mockUssApi, "fileList").mockResolvedValueOnce(blockMocks.fileResponseEmpty);
jest.spyOn(blockMocks.mockUssApi, "putContent").mockResolvedValueOnce(blockMocks.fileResponseSame);
jest.spyOn(blockMocks.mockUssApi, "uploadDirectory").mockResolvedValueOnce(blockMocks.fileResponseSame);

await blockMocks.testNode.copyUssFile();
});
it("Tests util disposeClipboardContents function correctly free clipboardContents", async () => {
vscode.env.clipboard.writeText("test");
ussUtils.disposeClipboardContents();
expect(vscode.env.clipboard.readText()).toEqual(undefined);
});
it("Tests node.copyUssFile() reads clipboard contents and returns as nothing is copied", async () => {
const globalMocks = await createGlobalMocks();
globalMocks.readText.mockResolvedValueOnce("");
const blockMocks = createBlockMocks(globalMocks);

expect(await blockMocks.testNode.copyUssFile()).toEqual(undefined);
});

it("Tests node.copyUssFile() reads clipboard contents and fails to upload directory & file", async () => {
const globalMocks = await createGlobalMocks();

globalMocks.readText.mockResolvedValueOnce("users/directory/file,users/directory/");
const blockMocks = createBlockMocks(globalMocks);

jest.spyOn(blockMocks.mockUssApi, "fileList").mockResolvedValueOnce(blockMocks.fileResponse);
jest.spyOn(blockMocks.mockUssApi, "putContent").mockResolvedValueOnce(blockMocks.fileResponse);
jest.spyOn(blockMocks.mockUssApi, "uploadDirectory").mockRejectedValueOnce(blockMocks.fileResponse);

await blockMocks.testNode.copyUssFile();
});
});
Loading