Skip to content

Commit

Permalink
fix for refresh btn unix attributes
Browse files Browse the repository at this point in the history
Signed-off-by: Billie Simmons <[email protected]>
  • Loading branch information
JillieBeanSim committed Dec 9, 2024
1 parent f510715 commit 8877e9f
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,6 @@ describe("AttributeView unit tests", () => {
});
const updateAttrsApiMock = jest.fn();
const updateAttributesMock = jest.spyOn(node, "setAttributes").mockImplementation();
const onUpdateMock = jest.fn();
const onUpdateMocked = new MockedProperty(ZoweUSSNode.prototype, "onUpdate", undefined, onUpdateMock);

beforeAll(() => {
jest.spyOn(ZoweExplorerApiRegister, "getUssApi").mockReturnValue({
Expand All @@ -48,7 +46,6 @@ describe("AttributeView unit tests", () => {

afterAll(() => {
createDirMock.mockRestore();
onUpdateMocked[Symbol.dispose]();
});

it("refreshes properly when webview sends 'refresh' command", async () => {
Expand All @@ -60,8 +57,6 @@ describe("AttributeView unit tests", () => {
node.getParent = jest.fn().mockReturnValueOnce({ label: "parent node" } as IZoweUSSTreeNode);
await (view as any).onDidReceiveMessage({ command: "refresh" });
expect(treeProvider.refreshElement).toHaveBeenCalled();

expect(node.onUpdate).toHaveBeenCalledTimes(2);
});

it("dispatches node data to webview when 'ready' command is received", async () => {
Expand Down Expand Up @@ -117,6 +112,7 @@ describe("AttributeView unit tests", () => {
});

it("handles any errors while updating attributes", async () => {
// Object.defineProperty(ZoweUSSNode.prototype, "getAttributes", { value: new Error("Failed to update attributes"), configurable: true });
const getAttributesMock = jest.spyOn(ZoweUSSNode.prototype, "getAttributes").mockRejectedValue(new Error("Failed to update attributes"));
await (view as any).onDidReceiveMessage({
command: "update-attributes",
Expand Down
20 changes: 8 additions & 12 deletions packages/zowe-explorer/src/trees/uss/USSAttributeView.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
*/

import { Types, Gui, MainframeInteraction, IZoweUSSTreeNode, WebView } from "@zowe/zowe-explorer-api";
import { Disposable, ExtensionContext } from "vscode";
import { ExtensionContext } from "vscode";
import { ZoweExplorerApiRegister } from "../../extending/ZoweExplorerApiRegister";
import { SharedContext } from "../shared/SharedContext";
import * as vscode from "vscode";
Expand All @@ -22,8 +22,6 @@ export class USSAttributeView extends WebView {
private readonly ussApi: MainframeInteraction.IUss;
private readonly canUpdate: boolean;

private onUpdateDisposable: Disposable;

public constructor(context: ExtensionContext, treeProvider: Types.IZoweUSSTreeType, node: IZoweUSSTreeNode) {
const label = node.label ? `Edit Attributes: ${node.label as string}` : "Edit Attributes";
super(label, "edit-attributes", context, {
Expand All @@ -42,17 +40,15 @@ export class USSAttributeView extends WebView {
}

protected async onDidReceiveMessage(message: any): Promise<void> {
const actualAtts = await this.ussNode.getAttributes();
switch (message.command) {
case "refresh":
if (this.canUpdate) {
this.onUpdateDisposable = this.ussNode.onUpdate(async (node) => {
await this.attachTag(node);
await this.panel.webview.postMessage({
attributes: await this.ussNode.getAttributes(),
name: node.fullPath,
readonly: this.ussApi.updateAttributes == null,
});
this.onUpdateDisposable.dispose();
await this.attachTag(this.ussNode);
await this.panel.webview.postMessage({
attributes: actualAtts,
name: this.ussNode.fullPath,
readonly: this.ussApi.updateAttributes == null,
});

if (this.ussNode.getParent()) {
Expand All @@ -65,7 +61,7 @@ export class USSAttributeView extends WebView {
case "ready":
await this.attachTag(this.ussNode);
await this.panel.webview.postMessage({
attributes: await this.ussNode.getAttributes(),
attributes: actualAtts,
name: this.ussNode.fullPath,
readonly: this.ussApi.updateAttributes == null,
});
Expand Down

0 comments on commit 8877e9f

Please sign in to comment.