Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ensure that the software context is ready #818

Closed
wants to merge 6 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/ci-integration-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ jobs:
run: podman exec agama bash -c "cd /checkout/playwright && SKIP_LOGIN=true playwright test --trace on --project chromium"

- name: Again show the D-Bus services log
run: podman exec agama bash -c "journalctl | grep agama"
run: podman exec agama bash -c "journalctl -u agama"

- name: Show the complete journal
# maybe not necessary if the above filtered journalctl calls are enough
Expand Down
6 changes: 6 additions & 0 deletions web/package/cockpit-agama.changes
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
-------------------------------------------------------------------
Wed Oct 25 15:46:37 UTC 2023 - Imobach Gonzalez Sosa <igonzalezsosa@suse.com>

- Fix the client initialization and make sure that the software
context is ready (gh#openSUSE/agama#818).

-------------------------------------------------------------------
Mon Oct 23 11:33:53 UTC 2023 - Imobach Gonzalez Sosa <igonzalezsosa@suse.com>

Expand Down
4 changes: 3 additions & 1 deletion web/src/App.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import { Outlet } from "react-router-dom";

import { _ } from "~/i18n";
import { useInstallerClient, useInstallerClientStatus } from "~/context/installer";
import { useSoftware } from "./context/software";
import { STARTUP, INSTALL } from "~/client/phase";
import { BUSY } from "~/client/status";

Expand Down Expand Up @@ -57,6 +58,7 @@ const ATTEMPTS = 3;
function App() {
const client = useInstallerClient();
const { attempt } = useInstallerClientStatus();
const { products } = useSoftware();
const { language } = useL10n();
const [status, setStatus] = useState(undefined);
const [phase, setPhase] = useState(undefined);
Expand All @@ -79,7 +81,7 @@ function App() {
}, [client, setPhase]);

const Content = () => {
if (!client) {
if (!client || !products) {
return (attempt > ATTEMPTS) ? <DBusError /> : <Loading />;
}

Expand Down
28 changes: 28 additions & 0 deletions web/src/App.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,18 @@ import { IDLE, BUSY } from "~/client/status";

jest.mock("~/client");

// list of available products
let mockProducts;
jest.mock("~/context/software", () => ({
...jest.requireActual("~/context/software"),
useSoftware: () => {
return {
products: mockProducts,
selectedProduct: null
};
}
}));

// Mock some components,
// See https://www.chakshunyu.com/blog/how-to-mock-a-react-component-in-jest/#default-export
jest.mock("~/components/core/DBusError", () => <div>D-BusError Mock</div>);
Expand Down Expand Up @@ -63,13 +75,29 @@ describe("App", () => {
}
};
});

mockProducts = [
{ id: "openSUSE", name: "openSUSE Tumbleweed" },
{ id: "Leap Micro", name: "openSUSE Micro" }
];
});

afterEach(() => {
// setting a cookie with already expired date removes it
document.cookie = "CockpitLang=; path=/; expires=" + new Date(0).toUTCString();
});

describe("when the software context is not initialized", () => {
beforeEach(() => {
mockProducts = undefined;
});

it("renders the LoadingEnvironment theme", async () => {
installerRender(<App />, { withL10n: true });
await screen.findByText(/Loading installation environment/);
});
});

describe("on the startup phase", () => {
beforeEach(() => {
getPhaseFn.mockResolvedValue(STARTUP);
Expand Down
6 changes: 1 addition & 5 deletions web/src/components/software/ProductSelectionPage.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ import {
Radio
} from "@patternfly/react-core";

import { Icon, Loading } from "~/components/layout";
import { Icon } from "~/components/layout";
import { Title, PageIcon, MainActions } from "~/components/layout/Layout";

function ProductSelectionPage() {
Expand Down Expand Up @@ -65,10 +65,6 @@ function ProductSelectionPage() {
navigate("/");
};

if (!products) return (
<Loading text={_("Loading available products, please wait...")} />
);

const buildOptions = () => {
const options = products.map((p) => (
<Card key={p.id} className={isSelected(p) && "selected-product"}>
Expand Down
1 change: 1 addition & 0 deletions web/src/context/installer.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ function InstallerClientProvider({
if (await client.isConnected()) {
setValue(client);
setAttempt(0);
return;
}

console.warn(`Failed to connect to D-Bus (attempt ${attempt + 1})`);
Expand Down
2 changes: 1 addition & 1 deletion web/src/context/installer.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ describe("installer context", () => {
<InstallerClientProvider interval={0.1}>
<ClientStatus />
</InstallerClientProvider>);
await screen.findByText("attempt: 2");
await screen.findByText("attempt: 1");
});
});

Expand Down
Loading