Skip to content

Commit

Permalink
Merge pull request #2801 from zowe/fix/doc-close-event
Browse files Browse the repository at this point in the history
Fix undefined node error on save
  • Loading branch information
JillieBeanSim authored Apr 2, 2024
2 parents 039036a + eb126ff commit 143f5d1
Show file tree
Hide file tree
Showing 18 changed files with 190 additions and 384 deletions.
1 change: 1 addition & 0 deletions packages/zowe-explorer/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ All notable changes to the "vscode-extension-for-zowe" extension will be documen
### Bug fixes

- Fixed issue where files left open in prior VS Code session cannot be uploaded to mainframe after window is reloaded. [#2758](https://github.com/zowe/vscode-extension-for-zowe/issues/2758)
- Fixed issue where saving changes to favorited data set or USS file could fail. [#2801](https://github.com/zowe/vscode-extension-for-zowe/pull/2801)

## `2.15.1`

Expand Down
19 changes: 9 additions & 10 deletions packages/zowe-explorer/__mocks__/mockCreators/uss.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,13 +51,13 @@ export function createUSSTree(favoriteNodes: ZoweUSSNode[], sessionNodes: ZoweUS

export function createUSSNode(session, profile) {
const parentNode = new ZoweUSSNode({
label: "parentNode",
label: "usstest",
collapsibleState: vscode.TreeItemCollapsibleState.Expanded,
session,
profile,
});
const ussNode = new ZoweUSSNode({
label: "usstest",
label: "testDir",
collapsibleState: vscode.TreeItemCollapsibleState.Expanded,
parentNode,
session,
Expand All @@ -66,7 +66,8 @@ export function createUSSNode(session, profile) {
parentNode.contextValue = globals.USS_SESSION_CONTEXT;
ussNode.contextValue = globals.USS_DIR_CONTEXT;
parentNode.fullPath = "/u/myuser";
ussNode.fullPath = "/u/myuser/usstest";
ussNode.fullPath = "/u/myuser/testDir";
parentNode.children.push(ussNode);
return ussNode;
}

Expand All @@ -88,25 +89,23 @@ export function createUSSSessionNode(session: imperative.Session, profile: imper
return zoweUSSNode;
}

// This is NOT a favorite equivalent of the node created by createdUSSNode.
// This is a favorited textfile node. createUSSNode creates a USS session node.
export function createFavoriteUSSNode(session, profile) {
const parentNode = new ZoweUSSNode({
label: "parentNode",
label: "usstest",
collapsibleState: vscode.TreeItemCollapsibleState.Expanded,
session,
profile,
});
const ussNodeF = new ZoweUSSNode({
label: "usstest",
label: "testDir",
collapsibleState: vscode.TreeItemCollapsibleState.Expanded,
parentNode,
session,
profile,
});
parentNode.contextValue = globals.FAV_PROFILE_CONTEXT;
ussNodeF.contextValue = globals.USS_TEXT_FILE_CONTEXT + globals.FAV_SUFFIX;
ussNodeF.fullPath = "/u/myuser/usstest";
ussNodeF.tooltip = "/u/myuser/usstest";
ussNodeF.contextValue = globals.USS_DIR_CONTEXT + globals.FAV_SUFFIX;
ussNodeF.fullPath = ussNodeF.tooltip = "/u/myuser/testDir";
parentNode.children.push(ussNodeF);
return ussNodeF;
}
Original file line number Diff line number Diff line change
Expand Up @@ -3330,7 +3330,7 @@ describe("Dataset Tree Unit Tests - Sorting and Filtering operations", () => {

describe("onDidCloseTextDocument", () => {
it("sets the entry in openFiles record to null if Data Set URI is valid", async () => {
const doc = { uri: { fsPath: join(globals.DS_DIR, "lpar", "SOME.PS") } } as vscode.TextDocument;
const doc = { isClosed: true, isDirty: false, uri: { fsPath: join(globals.DS_DIR, "lpar", "SOME.PS") } } as vscode.TextDocument;

jest.spyOn(TreeProviders, "ds", "get").mockReturnValue(tree);
await DatasetTree.onDidCloseTextDocument(doc);
Expand Down
205 changes: 51 additions & 154 deletions packages/zowe-explorer/__tests__/__unit__/dataset/actions.unit.test.ts

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -1149,7 +1149,7 @@ describe("ZosJobsProvider Unit Test - Filter Jobs", () => {

describe("onDidCloseTextDocument", () => {
it("sets the entry in openFiles record to null if Spool URI is valid", async () => {
const doc = { uri: { scheme: "zosspool", path: "JOB12345.SPOOL1.SYSOUT" } } as vscode.TextDocument;
const doc = { isClosed: true, isDirty: false, uri: { scheme: "zosspool", path: "JOB12345.SPOOL1.SYSOUT" } } as vscode.TextDocument;
await createGlobalMocks();
const tree = new ZosJobsProvider();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ async function createGlobalMocks() {
mockDeleteJobs: jest.fn(),
mockShowInputBox: jest.fn(),
mockDeleteJob: jest.fn(),
mockGetJobsByOwnerAndPrefix: jest.fn(),
mockGetJobsByParameters: jest.fn(),
mockShowInformationMessage: jest.fn(),
mockLoadNamedProfile: jest.fn(),
mockCreateQuickPick: jest.fn(),
Expand Down Expand Up @@ -107,8 +107,8 @@ async function createGlobalMocks() {
configurable: true,
});
Object.defineProperty(globalMocks.mockGetJobs, "getJob", { value: globalMocks.mockGetJob, configurable: true });
Object.defineProperty(globalMocks.mockGetJobs, "getJobsByOwnerAndPrefix", {
value: globalMocks.mockGetJobsByOwnerAndPrefix,
Object.defineProperty(globalMocks.mockGetJobs, "getJobsByParameters", {
value: globalMocks.mockGetJobsByParameters,
configurable: true,
});
Object.defineProperty(zowe.ZosmfSession, "createSessCfgFromArgs", {
Expand Down Expand Up @@ -171,7 +171,7 @@ async function createGlobalMocks() {
globalMocks.mockCreateSessCfgFromArgs.mockReturnValue(globalMocks.testSession);
globalMocks.testSessionNode = createJobSessionNode(globalMocks.testSession, globalMocks.testProfile);
globalMocks.mockGetJob.mockReturnValue(globalMocks.testIJob);
globalMocks.mockGetJobsByOwnerAndPrefix.mockReturnValue([globalMocks.testIJob, globalMocks.testIJobComplete]);
globalMocks.mockGetJobsByParameters.mockReturnValue([globalMocks.testIJob, globalMocks.testIJobComplete]);
globalMocks.mockProfileInstance.editSession = jest.fn(() => globalMocks.testProfile);
globalMocks.testJobNode = new ZoweJobNode({
label: "jobtest",
Expand All @@ -197,6 +197,12 @@ async function createGlobalMocks() {
configurable: true,
});

jest.spyOn(TreeProviders, "providers", "get").mockReturnValue({
ds: { addSingleSession: jest.fn(), mSessionNodes: [...globalMocks.testJobsProvider.mSessionNodes], refresh: jest.fn() } as any,
uss: { addSingleSession: jest.fn(), mSessionNodes: [...globalMocks.testJobsProvider.mSessionNodes], refresh: jest.fn() } as any,
jobs: { addSingleSession: jest.fn(), mSessionNodes: [...globalMocks.testJobsProvider.mSessionNodes], refresh: jest.fn() } as any,
} as any);

// Reset getConfiguration because we called it when testJobsProvider was assigned
globalMocks.getConfiguration.mockClear();

Expand All @@ -218,11 +224,6 @@ describe("ZoweJobNode unit tests - Function createJobsTree", () => {
describe("ZoweJobNode unit tests - Function addSession", () => {
it("Tests that addSession adds the session to the tree", async () => {
const globalMocks = await createGlobalMocks();
jest.spyOn(TreeProviders, "providers", "get").mockReturnValue({
ds: { addSingleSession: jest.fn(), mSessionNodes: [...globalMocks.testJobsProvider.mSessionNodes], refresh: jest.fn() } as any,
uss: { addSingleSession: jest.fn(), mSessionNodes: [...globalMocks.testJobsProvider.mSessionNodes], refresh: jest.fn() } as any,
jobs: { addSingleSession: jest.fn(), mSessionNodes: [...globalMocks.testJobsProvider.mSessionNodes], refresh: jest.fn() } as any,
} as any);
await globalMocks.testJobsProvider.addSession("sestest");
expect(globalMocks.testJobsProvider.mSessionNodes[1]).toBeDefined();
expect(globalMocks.testJobsProvider.mSessionNodes[1].label).toEqual("sestest");
Expand Down Expand Up @@ -295,17 +296,18 @@ describe("ZoweJobNode unit tests - Function onDidConfiguration", () => {
});

describe("ZoweJobNode unit tests - Function getChildren", () => {
xit("Tests that getChildren returns the jobs of the session, when called on the session", async () => {
it("Tests that getChildren returns the jobs of the session, when called on the session", async () => {
const globalMocks = await createGlobalMocks();

await globalMocks.testJobsProvider.addSession("fake");
globalMocks.testJobsProvider.mSessionNodes[1].filtered = true;

const jobs = await globalMocks.testJobsProvider.mSessionNodes[1].getChildren();
expect(jobs.length).toBe(2);
expect(jobs[0].job.jobid).toEqual(globalMocks.testIJob.jobid);
expect(jobs[0].tooltip).toEqual("TESTJOB(JOB1234)");
expect(jobs[0].tooltip).toEqual("TESTJOB(JOB1234) - ACTIVE");
expect(jobs[1].job.jobid).toEqual(globalMocks.testIJobComplete.jobid);
expect(jobs[1].tooltip).toEqual("TESTJOB(JOB1235) - 0");
expect(jobs[1].tooltip).toEqual("TESTJOB(JOB1235) - sampleMember - 0");
});

it("Tests that getChildren updates existing job nodes with new statuses", async () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,7 @@ describe("USSTree Unit Tests - Function checkDuplicateLabel", () => {
it("Tests that checkDuplicateLabel() returns an error message if passed a name that's already used for an existing folder", async () => {
const globalMocks = await createGlobalMocks();

const returnVal = globalMocks.testTree.checkDuplicateLabel("/u/myuser/usstest", [globalMocks.testUSSNode]);
const returnVal = globalMocks.testTree.checkDuplicateLabel("/u/myuser/testDir", [globalMocks.testUSSNode]);
expect(returnVal).toEqual("A folder already exists with this name. Please choose a different name.");
});
});
Expand Down Expand Up @@ -755,23 +755,20 @@ const setupUssFavNode = (globalMocks): ZoweUSSNode => {
describe("USSTree Unit Tests - Function findFavoritedNode", () => {
it("Testing that findFavoritedNode() returns the favorite of a non-favorited node", async () => {
const globalMocks = await createGlobalMocks();
globalMocks.testUSSNode.contextValue = globals.USS_TEXT_FILE_CONTEXT;

const ussFavNode = setupUssFavNode(globalMocks);

const foundNode = await globalMocks.testTree.findFavoritedNode(globalMocks.testUSSNode);

expect(foundNode).toStrictEqual(ussFavNode);
});
it("Tests that findFavoritedNode() does not error when there is no favorite or matching profile node in Favorites", async () => {
it("Tests that findFavoritedNode() returns undefined when there is no favorite or matching profile node in Favorites", async () => {
const globalMocks = await createGlobalMocks();
globalMocks.testTree.mSessionNodes[1].children.push(globalMocks.testUSSNode);

const node = createUSSNode(globalMocks.testSession, globalMocks.testProfile);
const foundNode = await globalMocks.testTree.findFavoritedNode(node);

expect(() => {
globalMocks.testTree.findFavoritedNode(node);
}).not.toThrow();
expect(foundNode).toBeUndefined();
});
});

Expand Down Expand Up @@ -1657,7 +1654,7 @@ describe("USSTree Unit Tests - Function editSession", () => {
Object.defineProperty(globals, "USS_DIR", {
value: join("some", "fspath", "_U_"),
});
const doc = { uri: { fsPath: join(globals.USS_DIR, "lpar", "someFile.txt") } } as vscode.TextDocument;
const doc = { isClosed: true, isDirty: false, uri: { fsPath: join(globals.USS_DIR, "lpar", "someFile.txt") } } as vscode.TextDocument;

jest.spyOn(TreeProviders, "uss", "get").mockReturnValue(tree);
await USSTree.onDidCloseTextDocument(doc);
Expand Down
Loading

0 comments on commit 143f5d1

Please sign in to comment.