Skip to content

Commit

Permalink
fix(web): add tests for installation progress
Browse files Browse the repository at this point in the history
Kind of regresion tests in an attempt to avoid unsubscribing the
installation progress component from the installer status by mistake in
the future.

Related to commits f10153b and
d1202ea
  • Loading branch information
dgdavid committed Nov 4, 2024
1 parent d1202ea commit 0c870f0
Showing 1 changed file with 43 additions and 5 deletions.
48 changes: 43 additions & 5 deletions web/src/components/core/InstallationProgress.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,20 +25,58 @@ import { screen } from "@testing-library/react";
import { installerRender } from "~/test-utils";
import { InstallationPhase } from "~/types/status";
import InstallationProgress from "./InstallationProgress";
import { ROOT } from "~/routes/paths";

let isBusy = false;
let phase = InstallationPhase.Install;
const mockInstallerStatusChanges = jest.fn();

jest.mock("~/components/core/ProgressReport", () => () => <div>ProgressReport Mock</div>);

jest.mock("~/queries/status", () => ({
...jest.requireActual("~/queries/status"),
useInstallerStatus: () => ({ isBusy: true, phase: InstallationPhase.Install }),
useInstallerStatus: () => ({ isBusy, phase }),
useInstallerStatusChanges: () => mockInstallerStatusChanges(),
}));

describe("InstallationProgress", () => {
it("renders progress report", () => {
it("subscribes to installer status", () => {
installerRender(<InstallationProgress />);
screen.getByText("ProgressReport Mock");
expect(mockInstallerStatusChanges).toHaveBeenCalled();
});

it.todo("redirects to root path when not in an installation phase");
it.todo("redirects to installatino finished path if in an installation phase but not busy");
describe("when not in an installation phase", () => {
beforeEach(() => {
phase = InstallationPhase.Config;
});

it("redirects to the root path", async () => {
installerRender(<InstallationProgress />);
await screen.findByText(`Navigating to ${ROOT.root}`);
});
});

describe("when installer in the installation phase and busy", () => {
beforeEach(() => {
phase = InstallationPhase.Install;
isBusy = true;
});

it("renders progress report", () => {
installerRender(<InstallationProgress />);
screen.getByText("ProgressReport Mock");
});
});

describe("when installer in the installation phase but not busy", () => {
beforeEach(() => {
phase = InstallationPhase.Install;
isBusy = false;
});

it("redirect to installation finished path", async () => {
installerRender(<InstallationProgress />);
await screen.findByText(`Navigating to ${ROOT.installationFinished}`);
});
});
});

0 comments on commit 0c870f0

Please sign in to comment.