From 8877e9ff19ca8c772d0749064c3788d5cd642413 Mon Sep 17 00:00:00 2001 From: Billie Simmons <49491949+JillieBeanSim@users.noreply.github.com> Date: Mon, 9 Dec 2024 15:49:26 -0500 Subject: [PATCH] fix for refresh btn unix attributes Signed-off-by: Billie Simmons <49491949+JillieBeanSim@users.noreply.github.com> --- .../trees/uss/USSAttributeView.unit.test.ts | 6 +----- .../src/trees/uss/USSAttributeView.ts | 20 ++++++++----------- 2 files changed, 9 insertions(+), 17 deletions(-) diff --git a/packages/zowe-explorer/__tests__/__unit__/trees/uss/USSAttributeView.unit.test.ts b/packages/zowe-explorer/__tests__/__unit__/trees/uss/USSAttributeView.unit.test.ts index 6254493206..a409f3e674 100644 --- a/packages/zowe-explorer/__tests__/__unit__/trees/uss/USSAttributeView.unit.test.ts +++ b/packages/zowe-explorer/__tests__/__unit__/trees/uss/USSAttributeView.unit.test.ts @@ -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({ @@ -48,7 +46,6 @@ describe("AttributeView unit tests", () => { afterAll(() => { createDirMock.mockRestore(); - onUpdateMocked[Symbol.dispose](); }); it("refreshes properly when webview sends 'refresh' command", async () => { @@ -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 () => { @@ -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", diff --git a/packages/zowe-explorer/src/trees/uss/USSAttributeView.ts b/packages/zowe-explorer/src/trees/uss/USSAttributeView.ts index 72f2a5084c..94cdf2dcd7 100644 --- a/packages/zowe-explorer/src/trees/uss/USSAttributeView.ts +++ b/packages/zowe-explorer/src/trees/uss/USSAttributeView.ts @@ -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"; @@ -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, { @@ -42,17 +40,15 @@ export class USSAttributeView extends WebView { } protected async onDidReceiveMessage(message: any): Promise { + 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()) { @@ -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, });