From 30d60dce1a622a8b832ecab73d56448f7b96bee3 Mon Sep 17 00:00:00 2001 From: RachelElysia <71795832+RachelElysia@users.noreply.github.com> Date: Tue, 5 Aug 2025 14:27:58 -0400 Subject: [PATCH] Fleet UI: Tarballz allow uninstall bug fix (#31607) --- .../HostInstallerActionCell.tests.tsx | 98 +++++++++++++++++++ .../HostInstallerActionCell.tsx | 13 ++- 2 files changed, 109 insertions(+), 2 deletions(-) diff --git a/frontend/pages/hosts/details/cards/HostSoftwareLibrary/HostInstallerActionCell/HostInstallerActionCell.tests.tsx b/frontend/pages/hosts/details/cards/HostSoftwareLibrary/HostInstallerActionCell/HostInstallerActionCell.tests.tsx index 0241e1a213..3bb61b7db8 100644 --- a/frontend/pages/hosts/details/cards/HostSoftwareLibrary/HostInstallerActionCell/HostInstallerActionCell.tests.tsx +++ b/frontend/pages/hosts/details/cards/HostSoftwareLibrary/HostInstallerActionCell/HostInstallerActionCell.tests.tsx @@ -578,4 +578,102 @@ describe("HostInstallerActionCell component", () => { expect(screen.getByTestId("trash-icon")).toBeInTheDocument(); expect(uninstallBtn.closest("button")).toBeDisabled(); }); + it("renders Reinstall and Uninstall buttons for tgz package with no installed_versions", () => { + render( + + ); + + const installBtn = screen.getByTestId(`${baseClass}__install-button--test`); + expect(installBtn).toHaveTextContent("Reinstall"); + expect(screen.getByTestId("refresh-icon")).toBeInTheDocument(); + expect(installBtn.closest("button")).toBeEnabled(); + + const uninstallBtn = screen.getByTestId( + `${baseClass}__uninstall-button--test` + ); + expect(uninstallBtn).toHaveTextContent("Uninstall"); + expect(screen.getByTestId("trash-icon")).toBeInTheDocument(); + expect(uninstallBtn.closest("button")).toBeEnabled(); + }); + it("renders disabled Reinstall and disabled Uninstall buttons for tgz package with no installed_versions when uninstall pending", () => { + render( + + ); + + const installBtn = screen.getByTestId(`${baseClass}__install-button--test`); + expect(installBtn).toHaveTextContent("Reinstall"); + expect(screen.getByTestId("refresh-icon")).toBeInTheDocument(); + expect(installBtn.closest("button")).toBeDisabled(); + + const uninstallBtn = screen.getByTestId( + `${baseClass}__uninstall-button--test` + ); + expect(uninstallBtn).toHaveTextContent("Uninstall"); + expect(screen.getByTestId("trash-icon")).toBeInTheDocument(); + expect(uninstallBtn.closest("button")).toBeDisabled(); + }); + it("renders Reinstall and Retry uninstall buttons for tgz package with no installed_versions when uninstall failed", () => { + render( + + ); + + const installBtn = screen.getByTestId(`${baseClass}__install-button--test`); + expect(installBtn).toHaveTextContent("Reinstall"); + expect(installBtn.closest("button")).toBeEnabled(); + + const uninstallBtn = screen.getByTestId( + `${baseClass}__uninstall-button--test` + ); + expect(uninstallBtn).toHaveTextContent("Retry uninstall"); + expect(uninstallBtn.closest("button")).toBeEnabled(); + + // Both reinstall and retry uninstall have the same icon + const refreshIcons = screen.getAllByTestId("refresh-icon"); + expect(refreshIcons).toHaveLength(2); + }); }); diff --git a/frontend/pages/hosts/details/cards/HostSoftwareLibrary/HostInstallerActionCell/HostInstallerActionCell.tsx b/frontend/pages/hosts/details/cards/HostSoftwareLibrary/HostInstallerActionCell/HostInstallerActionCell.tsx index 97e1125228..502feaa6d3 100644 --- a/frontend/pages/hosts/details/cards/HostSoftwareLibrary/HostInstallerActionCell/HostInstallerActionCell.tsx +++ b/frontend/pages/hosts/details/cards/HostSoftwareLibrary/HostInstallerActionCell/HostInstallerActionCell.tsx @@ -201,11 +201,20 @@ export const HostInstallerActionCell = ({ } }, [status, ui_status]); + const installedVersionsDetected = + installed_versions && installed_versions.length > 0; + + const installedTgzPackageDetected = + software.source === "tgz_packages" && + (ui_status === "installed" || + ui_status === "pending_uninstall" || + ui_status === "uninstalling" || + ui_status === "failed_uninstall"); + const canUninstallSoftware = !app_store_app && !!software_package && - installed_versions && - installed_versions.length > 0; + (installedVersionsDetected || installedTgzPackageDetected); return (