From 8c331eaf4fd2c877cd1ec23bb2011a8c89743446 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20D=C3=ADaz=20Gonz=C3=A1lez?= Date: Tue, 21 Nov 2023 15:12:59 +0000 Subject: [PATCH] [web] Fix install button After removing the core-js dependency, `issues.any()` does not work anymore. Thus, more plain JavaScript code has to be used to know if there are any kind of issues. --- web/src/components/core/InstallButton.jsx | 5 +++- .../components/core/InstallButton.test.jsx | 24 +++++++++++-------- 2 files changed, 18 insertions(+), 11 deletions(-) diff --git a/web/src/components/core/InstallButton.jsx b/web/src/components/core/InstallButton.jsx index fb5eb9af70..55e23fdd94 100644 --- a/web/src/components/core/InstallButton.jsx +++ b/web/src/components/core/InstallButton.jsx @@ -131,9 +131,12 @@ const InstallButton = ({ onClick }) => { const open = async () => { if (onClick) onClick(); const canInstall = await client.manager.canInstall(); - if (canInstall) setHasIssues(await client.issues.any()); setIsOpen(true); setError(!canInstall); + if (canInstall) { + const issues = await client.issues(); + setHasIssues(Object.values(issues).some(n => n.length > 0)); + } }; const close = () => setIsOpen(false); const install = () => client.manager.startInstallation(); diff --git a/web/src/components/core/InstallButton.test.jsx b/web/src/components/core/InstallButton.test.jsx index 08858affaf..9ee5bfc039 100644 --- a/web/src/components/core/InstallButton.test.jsx +++ b/web/src/components/core/InstallButton.test.jsx @@ -31,19 +31,18 @@ jest.mock("~/client", () => ({ createClient: jest.fn() })); -describe("when the button is clicked and there are not errors", () => { - let hasIssues = false; +let issues; +describe("when the button is clicked and there are not errors", () => { beforeEach(() => { + issues = {}; createClient.mockImplementation(() => { return { manager: { startInstallation: startInstallationFn, canInstall: () => Promise.resolve(true), }, - issues: { - any: () => Promise.resolve(hasIssues) - } + issues: jest.fn().mockResolvedValue({ ...issues }) }; }); }); @@ -74,7 +73,16 @@ describe("when the button is clicked and there are not errors", () => { describe("if there are issues", () => { beforeEach(() => { - hasIssues = true; + issues = { + product: [], + storage: [ + { description: "storage issue 1", details: "Details 1", source: "system", severity: "warn" }, + { description: "storage issue 2", details: "Details 2", source: "config", severity: "error" } + ], + software: [ + { description: "software issue 1", details: "Details 1", source: "system", severity: "warn" } + ] + }; }); it("shows a link to go to the issues page", async () => { @@ -87,10 +95,6 @@ describe("when the button is clicked and there are not errors", () => { }); describe("if there are not issues", () => { - beforeEach(() => { - hasIssues = false; - }); - it("does not show a link to go to the issues page", async () => { const { user } = installerRender(); const button = await screen.findByRole("button", { name: "Install" });