Skip to content

Commit

Permalink
fix(web): wraps ServerError into a plain layout
Browse files Browse the repository at this point in the history
  • Loading branch information
dgdavid committed Dec 10, 2024
1 parent ccc3e34 commit ec2f55c
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 26 deletions.
9 changes: 2 additions & 7 deletions web/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
import React from "react";
import { Navigate, Outlet, useLocation } from "react-router-dom";
import { ServerError } from "~/components/core";
import { Loading, PlainLayout } from "~/components/layout";
import { Loading } from "~/components/layout";
import { useInstallerL10n } from "~/context/installerL10n";
import { useInstallerClientStatus } from "~/context/installer";
import { useProduct, useProductChanges } from "~/queries/software";
Expand Down Expand Up @@ -53,12 +53,7 @@ function App() {
useDeprecatedChanges();

const Content = () => {
if (error)
return (
<PlainLayout>
<ServerError />
</PlainLayout>
);
if (!error) return <ServerError />;

if (phase === InstallationPhase.Install && isBusy) {
return <Navigate to={ROOT.installationProgress} />;
Expand Down
22 changes: 21 additions & 1 deletion web/src/components/core/ServerError.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,29 @@ import { plainRender } from "~/test-utils";
import * as utils from "~/utils";
import { ServerError } from "~/components/core";

jest.mock("~/components/layout/Header", () => () => <div>Header Mock</div>);
jest.mock("~/components/layout/Sidebar", () => () => <div>Sidebar Mock</div>);
jest.mock("~/components/layout/Layout", () => {
const layout = jest.requireActual("~/components/layout/Layout");
const OriginalPlainLayout = layout.Plain;

return {
...layout,
Plain: ({ ...props }) => (
<>
<div>PlainLayout Mock</div>
<OriginalPlainLayout {...props} />
</>
),
};
});

describe("ServerError", () => {
it("includes a generic server problem message", () => {
it("wraps a generic server problem message into a plain layout with neither, header nor sidebar", () => {
plainRender(<ServerError />);
expect(screen.queryByText("Header Mock")).toBeNull();
expect(screen.queryByText("Sidebar Mock")).toBeNull();
screen.getByText("PlainLayout Mock");
screen.getByText(/Cannot connect to Agama server/i);
});

Expand Down
38 changes: 20 additions & 18 deletions web/src/components/core/ServerError.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import {
EmptyStateBody,
EmptyStateHeader,
} from "@patternfly/react-core";
import { Center, Icon } from "~/components/layout";
import { Center, Icon, PlainLayout } from "~/components/layout";
import { Page } from "~/components/core";
import { _ } from "~/i18n";
import { locationReload } from "~/utils";
Expand All @@ -36,24 +36,26 @@ const ErrorIcon = () => <Icon name="error" className="icon-xxxl" />;

function ServerError() {
return (
<Page>
<Page.Content>
<Center>
<EmptyState variant="xl">
<EmptyStateHeader
titleText={_("Cannot connect to Agama server")}
headingLevel="h2"
icon={<EmptyStateIcon icon={ErrorIcon} />}
/>
<EmptyStateBody>{_("Please, check whether it is running.")}</EmptyStateBody>
</EmptyState>
</Center>
</Page.Content>
<PlainLayout mountHeader={false} mountSidebar={false}>
<Page>
<Page.Content>
<Center>
<EmptyState variant="xl">
<EmptyStateHeader
titleText={_("Cannot connect to Agama server")}
headingLevel="h2"
icon={<EmptyStateIcon icon={ErrorIcon} />}
/>
<EmptyStateBody>{_("Please, check whether it is running.")}</EmptyStateBody>
</EmptyState>
</Center>
</Page.Content>

<Page.Actions>
<Page.Action onClick={locationReload}>{_("Reload")}</Page.Action>
</Page.Actions>
</Page>
<Page.Actions>
<Page.Action onClick={locationReload}>{_("Reload")}</Page.Action>
</Page.Actions>
</Page>
</PlainLayout>
);
}

Expand Down

0 comments on commit ec2f55c

Please sign in to comment.