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

fix: Go to right page when switching page on content pages (legal / impress) #993

Merged
merged 3 commits into from
Mar 2, 2023
Merged
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
14 changes: 10 additions & 4 deletions app/components/content-mdx-provider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,26 @@ import { ReactNode } from "react";
import { ContentLayout, StaticContentLayout } from "@/components/layout";
import { Intro, Tutorial, Examples, Contribute } from "@/homepage";

const castContentId = (contentId: unknown) => {
if (typeof contentId === "string") {
return contentId;
}
return undefined;
};

const Wrapper = ({
contentId,
children,
}: {
contentId: unknown;
children: ReactNode;
}) => {
if (typeof contentId !== "string") {
return <StaticContentLayout>{children}</StaticContentLayout>;
}
return contentId === "home" ? (
<ContentLayout contentId={contentId}>{children}</ContentLayout>
) : (
<StaticContentLayout>{children}</StaticContentLayout>
<StaticContentLayout contentId={castContentId(contentId)}>
{children}
</StaticContentLayout>
);
};

Expand Down
24 changes: 11 additions & 13 deletions app/components/footer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -95,20 +95,13 @@ export const Footer = ({ sx }: { sx?: FlexProps["sx"] }) => {
alignItems: ["flex-start", "center"],
}}
>
<Flex sx={{ flexDirection: ["column", "row"] }} pb={[4, 0]}>
{/* <FooterLink>
<Trans id="footer.help">Help</Trans>
</FooterLink>
<FooterLink>
<Trans id="footer.contact">Contact</Trans>
</FooterLink> */}
</Flex>

<Box
sx={{
display: ["block", "none"],

width: ["100%", "auto"],
mx: [2, 0],
mb: [4],
}}
>
<Logo />
Expand All @@ -117,8 +110,10 @@ export const Footer = ({ sx }: { sx?: FlexProps["sx"] }) => {
<Flex
sx={{
justifyContent: "flex-end",
alignItems: "center",
alignItems: ["flex-start", "center"],
width: ["100%", "auto"],
flexDirection: ["column", "row"],
mt: [4, 0],
}}
>
<Typography
Expand All @@ -127,6 +122,7 @@ export const Footer = ({ sx }: { sx?: FlexProps["sx"] }) => {
px: [4, 3],
py: [3, 4],
color: "secondary.main",
order: [7, 0],
}}
>
<Version />
Expand Down Expand Up @@ -181,8 +177,9 @@ const useFooterLinkStyles = makeStyles((theme: Theme) => ({
bottomLink: {
fontSize: "0.875rem",

borderLeftStyle: "solid",
borderLeftColor: theme.palette.grey[500],
borderTopStyle: "solid",
borderTopColor: theme.palette.grey[500],

textDecoration: "none",
cursor: "pointer",
"&:hover": {
Expand Down Expand Up @@ -236,7 +233,8 @@ const FooterLinkBottom = forwardRef<
sx={{
px: [4, 3],
py: [3, 4],
borderLeftWidth: ["1px", 0],
borderTopWidth: ["1px", 0],
width: ["100%", "auto"],
}}
>
{children}
Expand Down
4 changes: 3 additions & 1 deletion app/components/header.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,10 @@ const useHeaderStyles = makeStyles<Theme, { isConfiguring: boolean }>(

export const Header = ({
pageType = "app",
contentId,
}: {
pageType?: "content" | "app";
contentId: string | undefined;
}) => {
const router = useRouter();
const isConfiguring = router.pathname === "/create/[chartId]";
Expand All @@ -113,7 +115,7 @@ export const Header = ({
}}
>
<Logo />
<MetadataMenu />
<MetadataMenu contentId={contentId} />
</Flex>
<HeaderBorder />
</Box>
Expand Down
19 changes: 15 additions & 4 deletions app/components/layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { Header, HeaderProgressProvider } from "@/components/header";
export const AppLayout = ({ children }: { children?: ReactNode }) => (
<Flex sx={{ minHeight: "100vh", flexDirection: "column" }}>
<HeaderProgressProvider>
<Header pageType="app" />
<Header pageType="app" contentId={undefined} />
<Flex
component="main"
role="main"
Expand All @@ -34,7 +34,7 @@ export const ContentLayout = ({
backgroundColor: contentId === "home" ? "grey.100" : "muted.main",
}}
>
<Header pageType="content" />
<Header pageType="content" contentId={contentId} />
<Flex
component="main"
role="main"
Expand All @@ -51,7 +51,13 @@ export const ContentLayout = ({
);
};

export const StaticContentLayout = ({ children }: { children?: ReactNode }) => {
export const StaticContentLayout = ({
children,
contentId,
}: {
children?: ReactNode;
contentId: string | undefined;
}) => {
return (
<Flex
sx={{
Expand All @@ -60,7 +66,7 @@ export const StaticContentLayout = ({ children }: { children?: ReactNode }) => {
backgroundColor: "grey.100",
}}
>
<Header pageType="content" />
<Header pageType="content" contentId={contentId} />
<Flex
component="main"
role="main"
Expand All @@ -69,8 +75,13 @@ export const StaticContentLayout = ({ children }: { children?: ReactNode }) => {
flex: 1,
width: "100%",
maxWidth: 1024,
my: [4, 6],
mx: [0, 0, "auto"],
px: 4,

"& h2": {
mb: 1,
},
}}
>
{children}
Expand Down
5 changes: 5 additions & 0 deletions e2e/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,11 @@ export const createActions = ({
drawer: {
close: async () => await screen.locator('text="Back to main"').click(),
},
common: {
switchLang: async (lang: "de" | "fr" | "en" | "it") => {
await page.locator(`a[hreflang="${lang}"]`).click();
},
},
});

export type Actions = ReturnType<typeof createActions>;
20 changes: 18 additions & 2 deletions e2e/home.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@ describe("The Home Page", () => {
expect(await page.locator("html").getAttribute("lang")).toEqual("fr");
});

test("language switch should work", async ({ page, screen }) => {
test("language switch should work", async ({ page, screen, actions }) => {
await page.goto("/");
await page.locator('a[hreflang="fr"]').click();
await actions.common.switchLang("fr");
await screen.findByText(
"Visualisez les données ouvertes de l’administration publique suisse",
undefined,
Expand All @@ -41,3 +41,19 @@ describe("The Home Page", () => {
expect(await page.locator("html").getAttribute("lang")).toBe("fr");
});
});

describe("content pages", () => {
test("language switch should work", async ({ page, actions, screen }) => {
await page.goto("/en/legal-framework");

await actions.common.switchLang("fr");
await screen.findByText(
"Utilisation des jeux de données publiés sur visualize.admin.ch",
undefined,
{
timeout: 20 * 1000,
}
);
expect(await page.locator("html").getAttribute("lang")).toBe("fr");
});
});