Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 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
20 changes: 19 additions & 1 deletion src/components/ItemLandingPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { Themed } from "@theme-ui/mdx";
import WorkLibrarySelector from "components/WorkLibrarySelector";
import theme from "theme/theme";
import { useTranslation } from "next-i18next/pages";
import LanguageSelector from "./LanguageSelector";

interface ItemLandingPageProps {
workId: string;
Expand All @@ -21,7 +22,24 @@ const ItemLandingPage: React.FC<ItemLandingPageProps> = ({ workId }) => {
m: 3
}}
>
<h1>{t("itemLandingPage.findLibrary", "Find a Library")}</h1>
<div
sx={{
display: "flex",
flexDirection: ["column", "row"],
justifyContent: "space-between"
}}
>
<h1 sx={{ order: [2, 1] }}>
{t("itemLandingPage.findLibrary", "Find a Library")}
</h1>
<LanguageSelector
sx={{
order: [1, 2],
width: "fit-content",
alignSelf: ["end", "unset"]
}}
/>
</div>

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks like this is exactly duplicated in MultiLibraryHome.tsx ll. 60-77. Might be worth making a helper component to keep them from diverging.

<WorkLibrarySelector workId={workId} />
</Themed.root>
</ThemeUIProvider>
Expand Down
2 changes: 1 addition & 1 deletion src/components/LibraryFilterList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ const LibraryFilterList: React.FC<LibraryFilterListProps> = ({
return (
<>
{heading}
<div sx={{ display: "inline-block", width: "44ch", mb: 2 }}>
<div sx={{ width: ["auto", "44ch"], mb: 2 }}>
<TextInput
type="search"
aria-label={t(
Expand Down
22 changes: 19 additions & 3 deletions src/components/MultiLibraryHome.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import LibraryFilterList from "components/LibraryFilterList";
import { fetchLibraries } from "dataflow/fetchLibraries";
import type { ClientLibrary, LibrariesResponse } from "pages/api/libraries";
import { useTranslation } from "next-i18next/pages";
import LanguageSelector from "./LanguageSelector";

const MultiLibraryHome: React.FC = () => {
const { t } = useTranslation();
Expand Down Expand Up @@ -56,9 +57,24 @@ const MultiLibraryHome: React.FC = () => {
m: 3
}}
>
<h1>
{instanceName} {t("multiLibraryHome.home", "Home")}
</h1>
<div
sx={{
display: "flex",
flexDirection: ["column", "row"],
justifyContent: "space-between"
}}
>
<h1 sx={{ order: [2, 1] }}>
{instanceName} {t("multiLibraryHome.home", "Home")}
</h1>
<LanguageSelector
sx={{
order: [1, 2],
width: "fit-content",
alignSelf: ["end", "unset"]
}}
/>
</div>
<LibraryFilterList
heading={<h2>{t("multiLibraryHome.choose", "Choose a library:")}</h2>}
items={sorted.map(lib => ({
Expand Down
2 changes: 2 additions & 0 deletions src/components/OpenEbooksLanding.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import { ErrorBoundary } from "components/ErrorBoundary";
import OpenEbooksLoginPicker from "auth/OpenEbooksLoginPicker";
import colors from "theme/colors";
import { Trans, useTranslation } from "next-i18next/pages";
import LanguageSelector from "./LanguageSelector";

type PopularBook = { title: string; imgHref: string };

Expand Down Expand Up @@ -279,6 +280,7 @@ const OpenEbooksHero: React.FC = () => {
</span>
</NavButton>
)}
<LanguageSelector sx={{ ml: 3 }} />
</div>
<div
sx={{
Expand Down
79 changes: 54 additions & 25 deletions src/components/__tests__/ItemLandingPage.test.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as React from "react";
import { render, screen } from "test-utils";
import { render, screen, waitFor } from "test-utils";
import useSWR from "swr";
import ItemLandingPage from "../ItemLandingPage";
import { makeSwrResponse } from "test-utils/mockSwr";
Expand All @@ -8,28 +8,57 @@ jest.mock("swr");

const mockedSWR = useSWR as jest.MockedFunction<typeof useSWR>;

test("renders a heading and passes workId down to the library selector", () => {
mockedSWR.mockReturnValue(
makeSwrResponse<any>({
data: {
libraries: [
{
id: "urn:testlib",
slug: "testlib",
title: "Test Library",
authDocUrl: "https://example.com/testlib/auth"
}
]
}
})
);

render(<ItemLandingPage workId="work-1" />);

expect(
screen.getByRole("heading", { level: 1, name: "Find a Library" })
).toBeInTheDocument();
expect(
screen.getByRole("button", { name: "Test Library" })
).toBeInTheDocument();
describe("ItemLandingPage", () => {
beforeEach(() => {
mockedSWR.mockReturnValue(
makeSwrResponse<any>({
data: {
libraries: [
{
id: "urn:testlib",
slug: "testlib",
title: "Test Library",
authDocUrl: "https://example.com/testlib/auth"
}
]
}
})
);
});
test("renders a heading and passes workId down to the library selector", () => {
render(<ItemLandingPage workId="work-1" />);

expect(
screen.getByRole("heading", { level: 1, name: "Find a Library" })
).toBeInTheDocument();
expect(
screen.getByRole("button", { name: "Test Library" })
).toBeInTheDocument();
});

describe("LanguageSelector", () => {
it("displays when enabled in appConfig", async () => {
render(<ItemLandingPage workId="work-1" />, {
appConfig: { enableLanguageSelector: true }
});

await waitFor(() => {
expect(
screen.getByRole("combobox", { name: "Choose language" })
).toBeInTheDocument();
});
});

it("does not display when disabled in appConfig", async () => {
render(<ItemLandingPage workId="work-1" />, {
appConfig: { enableLanguageSelector: false }
});

await waitFor(() => {
expect(
screen.queryByRole("combobox", { name: "Choose language" })
).not.toBeInTheDocument();
});
});
});
});
32 changes: 31 additions & 1 deletion src/components/__tests__/MultiLibraryHome.test.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as React from "react";
import { render, screen, fireEvent, act } from "test-utils";
import { render, screen, fireEvent, act, waitFor } from "test-utils";
import MultiLibraryHome from "../MultiLibraryHome";
import useSWR from "swr";
import { makeSwrResponse } from "test-utils/mockSwr";
Expand Down Expand Up @@ -440,4 +440,34 @@ describe("MultiLibraryHome", () => {
).toBe("Ill");
});
});

describe("LanguageSelector", () => {
beforeEach(() => {
mockLibraries([lib("alpha")]);
});

it("displays when enabled in appConfig", async () => {
render(<MultiLibraryHome />, {
appConfig: { enableLanguageSelector: true }
});

await waitFor(() => {
expect(
screen.getByRole("combobox", { name: "Choose language" })
).toBeInTheDocument();
});
});

it("does not display when disabled in appConfig", async () => {
render(<MultiLibraryHome />, {
appConfig: { enableLanguageSelector: false }
});

await waitFor(() => {
expect(
screen.queryByRole("combobox", { name: "Choose language" })
).not.toBeInTheDocument();
});
});
});
});
32 changes: 29 additions & 3 deletions src/components/__tests__/OpenEbooksLanding.test.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,38 @@
import * as React from "react";
import { render } from "../../test-utils";
import { render, screen, waitFor } from "../../test-utils";
import { OpenEbooksLandingComponent } from "components/OpenEbooksLanding";

test("renders", () => {
const utils = render(<OpenEbooksLandingComponent />);
render(<OpenEbooksLandingComponent />);
expect(
utils.getByRole("heading", {
screen.getByRole("heading", {
name: "Welcome to Open eBooks"
})
).toBeInTheDocument();
});

describe("LanguageSelector", () => {
it("displays when enabled in appConfig", async () => {
render(<OpenEbooksLandingComponent />, {
appConfig: { enableLanguageSelector: true }
});

await waitFor(() => {
expect(
screen.getByRole("combobox", { name: "Choose language" })
).toBeInTheDocument();
});
});

it("does not display when disabled in appConfig", async () => {
render(<OpenEbooksLandingComponent />, {
appConfig: { enableLanguageSelector: false }
});

await waitFor(() => {
expect(
screen.queryByRole("combobox", { name: "Choose language" })
).not.toBeInTheDocument();
});
});
});
28 changes: 27 additions & 1 deletion src/components/__tests__/SignedOut.test.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as React from "react";
import { screen, setup } from "test-utils";
import { render, screen, setup, waitFor } from "test-utils";
import { SignedOutContent } from "pages/[library]/signed-out";

test("renders signed out page", () => {
Expand All @@ -11,3 +11,29 @@ test("renders signed out page", () => {
screen.getByRole("button", { name: /return to catalog/i })
).toBeInTheDocument();
});

describe("LanguageSelector", () => {
it("displays when enabled in appConfig", async () => {
render(<SignedOutContent />, {
appConfig: { enableLanguageSelector: true }
});

await waitFor(() => {
expect(
screen.getByRole("combobox", { name: "Choose language" })
).toBeInTheDocument();
});
});

it("does not display when disabled in appConfig", async () => {
render(<SignedOutContent />, {
appConfig: { enableLanguageSelector: false }
});

await waitFor(() => {
expect(
screen.queryByRole("combobox", { name: "Choose language" })
).not.toBeInTheDocument();
});
});
});
3 changes: 2 additions & 1 deletion src/pages/[library]/signed-out.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import useUser from "components/context/UserContext";
import { useRouter } from "next/router";
import useLinkUtils from "hooks/useLinkUtils";
import { useTranslation } from "next-i18next/pages";
import LanguageSelector from "components/LanguageSelector";

/**
* This page is shown after SAML/Clever sign-out to warn users about
Expand Down Expand Up @@ -46,7 +47,7 @@ export const SignedOutContent: React.FC = () => {
<Head>
<title>{t("signedOut.signedOut", "Signed Out")}</title>
</Head>

<LanguageSelector sx={{ alignSelf: "end" }} />
<div
sx={{
maxWidth: 600,
Expand Down
Loading