Skip to content

Commit

Permalink
[web] Fix install button
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
dgdavid committed Nov 21, 2023
1 parent c9784cf commit 8c331ea
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 11 deletions.
5 changes: 4 additions & 1 deletion web/src/components/core/InstallButton.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
24 changes: 14 additions & 10 deletions web/src/components/core/InstallButton.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 })
};
});
});
Expand Down Expand Up @@ -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 () => {
Expand All @@ -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(<InstallButton />);
const button = await screen.findByRole("button", { name: "Install" });
Expand Down

0 comments on commit 8c331ea

Please sign in to comment.