From 4aaf05eb2a90b866c3b297b8867057f9475ae71d Mon Sep 17 00:00:00 2001 From: Claude Date: Mon, 16 Nov 2026 16:33:55 +0000 Subject: [PATCH] Give organizer pages the organizer's language on The organizer app, sign-in and the AI assistant's consent screen shared one root layout that always said lang="en". They now have one each: /app and /oauth say the organizer's language (localeOfOrganizer, from the session their pages read anyway, so no new statement), and /login says the site default (signInLocale), reading no session, so the check and confirm pages still start no session read. Moving between them is now a full page load, which also brings the right language after signing in or out. Saving the language in account Settings already updates : a server action's redirect renders the whole page, root layout included. /login now shares its folder with its root layout, which drops the layout's title template there, so the page writes the site name into its tab title itself, as a signup's page does. Fixes #938. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_016YZ9SVnYjqfPQCMgeA7pDt --- CHANGELOG.md | 1 + CLAUDE.md | 2 +- next.config.mjs | 4 +- .../app/(chrome)/signups/[id]/layout.tsx | 5 +- src/app/(organizer)/app/layout.tsx | 29 +++++ src/app/(organizer)/layout.tsx | 13 -- src/app/(organizer)/login/layout.tsx | 18 +++ src/app/(organizer)/login/page.test.tsx | 12 +- src/app/(organizer)/login/page.tsx | 7 +- src/app/(organizer)/oauth/layout.tsx | 22 ++++ src/app/(organizer)/root-layouts.test.tsx | 119 ++++++++++++++++++ src/app/global-not-found.tsx | 2 +- src/app/root-shell.tsx | 18 +-- tests/e2e/organizer-language-story.spec.ts | 4 + tests/e2e/organizer-language.spec.ts | 23 +++- tests/e2e/root-layouts.spec.ts | 2 +- tests/e2e/sign-in-text.spec.ts | 3 + 17 files changed, 251 insertions(+), 33 deletions(-) create mode 100644 src/app/(organizer)/app/layout.tsx delete mode 100644 src/app/(organizer)/layout.tsx create mode 100644 src/app/(organizer)/login/layout.tsx create mode 100644 src/app/(organizer)/oauth/layout.tsx create mode 100644 src/app/(organizer)/root-layouts.test.tsx diff --git a/CHANGELOG.md b/CHANGELOG.md index 89ed0bfc..e60ee98e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -53,6 +53,7 @@ All notable changes to OpenSignup are documented here. Format follows [Keep a Ch - Organizers now read one word for a signup people can sign up on: **open**, the status beside its title (#638). The preview of an open signup said "This signup is live."; it now says "This signup is open.", which pairs with "This signup is closed." The help pages "Create and publish your first signup", "Close or reopen a signup" and "Connect an AI assistant" say open where they meant taking sign-ups, and "Create and publish your first signup" now says the signup is marked **open** at the top of the page. "Published" stays only where it means no longer a draft, and **Publish and share** and the share panel's green **Published** keep their words, since they are about the step itself. The greyed-out **Sign up** button on a preview no longer asks the organizer of an open signup to publish it: its hint reads "Preview: publish to let people sign up" on a draft and "Preview: people sign up at the public link" on an open signup. The `publish_signup` tool's description says the signup's status becomes open instead of calling it live. `docs/writing-help.md` now defines publish, published, open and closed, and the help pages' style check fails on calling a signup "live", as a new check on the connector tools' descriptions does. The stored status, the API, the tools' fields and the activity log are unchanged. - An address no page matches now gets the site's own 404 page (#621): "Sorry, we can’t find this page", a line saying to check the address or ask whoever sent the link for a new one, a **Go to the home page** link and the site footer, in place of Next's bare "404 | This page could not be found." It is marked `lang="en"`, still answers 404 and stays out of search results. Behind it, the app now has three root layouts, one for the home, help and legal pages, one for the organizer app, sign-in and OAuth consent, and one for a signup's pages, so a later change can mark a signup's pages with the signup's language while help and legal stay static. No address changes and every other page looks the same, but following a link from one of these areas to another now loads the whole page. Link previews name the share image as `/opengraph-image.png` and `/twitter-image.png` everywhere, without the version query the home page and a few others had. A signup's page and its edit link's page each load 0.2 kB less JavaScript (one layout where there were two), and their budgets in `budgets.json` come down by the same, to 130.3 and 113.5 kB. +- The organizer pages' `` follows the organizer (#938): the organizer app and the AI assistant's consent screen say the organizer's language, and the sign-in pages the instance's `DEFAULT_LOCALE`, else English, the same language as each page's text, so screen readers and browser translation take the whole page in it, the parts no screen marks itself too, such as the share panel's sheet on a phone. For this, the organizer app, sign-in and the consent screen each have a root layout of their own in place of the one they shared, so going from one to another loads the whole page, and a page reached by signing in or out never keeps the language of the one before. Saving a new language in account Settings updates it with no reload. While only English has shipped, which is today, every page still says `en`. - A signup's Settings tab has one **Save** for its settings (#899's tophat). "Ask for an email address" and, once a second language has shipped, "Signup language" each had a Save of their own, and saving one dropped an unsaved change in the other without a word. Save sends only the choices changed since the tab loaded, so it no longer puts back a language changed elsewhere meanwhile (by account Settings' switch or an AI assistant). The language's help adds "People who already signed up see it in the new language too." - The Settings tab's last card is called "Delete this signup" instead of "Danger zone" (#977's tophat), and its **Delete signup** button has a full red outline, so it reads as a button on the card's pink. - The unsubscribe page says "The link may be incomplete, or the signup has been deleted." for a link it can't read (#931's tophat), as the edit-link page does, instead of "It may have been mangled in transit, or the signup may have been deleted." diff --git a/CLAUDE.md b/CLAUDE.md index 980a44bf..6a7e85c1 100644 --- a/CLAUDE.md +++ b/CLAUDE.md @@ -128,7 +128,7 @@ Optional feature: organizers paste a description and get a draft signup. Provide ### Routes -There are three root layouts and none above them, so each can set `` while help and legal stay static: `(site)` (home, help, legal), `(organizer)` (`/app`, `/login`, `/oauth`) and `s/[slug]` (a signup's pages). Route groups don't change URLs. What they share (metadata, viewport, font, `globals.css`, the `` element) is `src/app/root-shell.tsx`; an address no page matches gets `src/app/global-not-found.tsx` (`experimental.globalNotFound`). A new page goes inside one of the three: outside them it has no root layout, and `next dev` quietly writes a bare one beside it, with no shell and no `lang`. A link from one group to another is a full page load. +There are five root layouts and none above them, so each can set `` while help and legal stay static: `(site)` (home, help, legal); in `(organizer)`, `app` (`/app`) and `oauth` (`/oauth`), in the organizer's language (`localeOfOrganizer`, from the session their pages read anyway), and `login` (`/login`), in the site default (`signInLocale()`), which reads no session; and `s/[slug]` (a signup's pages). Route groups don't change URLs. What they share (metadata, viewport, font, `globals.css`, the `` element) is `src/app/root-shell.tsx`; an address no page matches gets `src/app/global-not-found.tsx` (`experimental.globalNotFound`). A new page goes under one of them: outside them it has no root layout, and `next dev` quietly writes a bare one beside it, with no shell and no `lang`. A link from one root layout to another is a full page load. A page in the same folder as its root layout (`/login`, `/s/[slug]`) misses the layout's title template, so it writes the site name into its own tab title. A root layout isn't rendered again on a client-side navigation, but a server action that redirects renders the whole page it goes to, so saving the organizer's language in account Settings updates `` too. - Organizer UI: `src/app/(organizer)/app/...` (requires session). - Public participant page: `src/app/s/[slug]/...` (no auth, cookie-based "returning participant" flow). diff --git a/next.config.mjs b/next.config.mjs index bc39ea6b..ed585302 100644 --- a/next.config.mjs +++ b/next.config.mjs @@ -48,8 +48,8 @@ const nextConfig = { }, experimental: { // An address no page matches gets src/app/global-not-found.tsx. The app - // has three root layouts (src/app/root-shell.tsx says why) and none above - // them, so without this Next's built-in 404 renders in a bare document + // has several root layouts (src/app/root-shell.tsx says why) and none + // above them, so without this Next's built-in 404 renders in a bare document // with no ``. If the flag goes away, a // `src/app/(site)/[...missing]/page.tsx` that calls `notFound()` with a // `(site)/not-found.tsx` does the same job. diff --git a/src/app/(organizer)/app/(chrome)/signups/[id]/layout.tsx b/src/app/(organizer)/app/(chrome)/signups/[id]/layout.tsx index 7791693b..abf9738e 100644 --- a/src/app/(organizer)/app/(chrome)/signups/[id]/layout.tsx +++ b/src/app/(organizer)/app/(chrome)/signups/[id]/layout.tsx @@ -38,8 +38,9 @@ export default async function SignupDetailLayout({ children, params }: LayoutPro const { id } = await params; const session = await requireOrganizerSession(); const actor = toActor(session); - // The header's language. It changes only with a full page load (#938), so - // this layout not re-rendering between tabs leaves it right. + // The header's language. It changes only when the organizer saves one in + // account Settings, a server action whose redirect renders every layout + // again (#938), so this layout not re-rendering between tabs leaves it right. const locale = localeOfOrganizer(session); const result = await loadSignupForOrganizer(actor, id); if (!result.ok) { diff --git a/src/app/(organizer)/app/layout.tsx b/src/app/(organizer)/app/layout.tsx new file mode 100644 index 00000000..fe1faa7c --- /dev/null +++ b/src/app/(organizer)/app/layout.tsx @@ -0,0 +1,29 @@ +import { getOrganizerSession } from '@/auth/session'; +import { localeOfOrganizer } from '@/i18n/locale'; +import { RootShell, rootMetadata, rootViewport } from '../../root-shell'; + +export const metadata = rootMetadata; +export const viewport = rootViewport; + +/** + * The root layout for the organizer app (`/app`), in the organizer's language + * (`localeOfOrganizer`), as its pages' text is. With nobody signed in, it's + * the language of an account with none stored, the site default, else + * English, which is what the page that sends them to sign in is in. + * + * Every page here reads the session itself (`requireOrganizerSession`), and + * the read is cached for the request, so this costs no statement. Sign-in's + * check and confirm pages read none, and must not start to, so the sign-in + * pages have a root layout of their own (`../login/layout.tsx`), and so does + * the AI assistant's consent screen (`../oauth/layout.tsx`), which is in the + * organizer's language too. + * + * A root layout isn't rendered again on a client-side navigation, but the + * language only changes when the organizer saves one in account Settings, + * and a server action that redirects renders the page it goes to whole, this + * layout included. Going to or from sign-in or the consent screen crosses + * root layouts, which loads the whole page. + */ +export default async function OrganizerAppLayout({ children }: { children: React.ReactNode }) { + return {children}; +} diff --git a/src/app/(organizer)/layout.tsx b/src/app/(organizer)/layout.tsx deleted file mode 100644 index 46d4d26a..00000000 --- a/src/app/(organizer)/layout.tsx +++ /dev/null @@ -1,13 +0,0 @@ -import { RootShell, rootMetadata, rootViewport } from '../root-shell'; - -export const metadata = rootMetadata; -export const viewport = rootViewport; - -/** - * The root layout for the organizer app (`/app`), sign-in (`/login`) and - * OAuth consent (`/oauth`). English until organizers have a language of - * their own (#619). - */ -export default function OrganizerLayout({ children }: { children: React.ReactNode }) { - return {children}; -} diff --git a/src/app/(organizer)/login/layout.tsx b/src/app/(organizer)/login/layout.tsx new file mode 100644 index 00000000..005f38f0 --- /dev/null +++ b/src/app/(organizer)/login/layout.tsx @@ -0,0 +1,18 @@ +import { signInLocale } from '@/i18n/locale'; +import { RootShell, rootMetadata, rootViewport } from '../../root-shell'; + +export const metadata = rootMetadata; +export const viewport = rootViewport; + +/** + * The root layout for the sign-in pages (`/login` and its check and confirm + * pages), in the site default, else English (`signInLocale`), as their text + * is: nobody is signed in on them yet. It reads no session, so a page that + * reads none (check and confirm) doesn't start loading one, and an organizer + * who opens one while signed in sees it in the language it's written in. + * Signing in leaves for another root layout, which loads the whole page in + * the organizer's language. + */ +export default function SignInLayout({ children }: { children: React.ReactNode }) { + return {children}; +} diff --git a/src/app/(organizer)/login/page.test.tsx b/src/app/(organizer)/login/page.test.tsx index 62c79d98..184774a1 100644 --- a/src/app/(organizer)/login/page.test.tsx +++ b/src/app/(organizer)/login/page.test.tsx @@ -7,6 +7,7 @@ import { cleanup, render, screen, within } from '@testing-library/react'; import { CATALOG_LOCALES } from '@/i18n/config'; import { ship } from '@/i18n/testing/ship'; import type { ServiceError } from '@/lib/errors'; +import { INSTANCE_NAME } from '@/lib/site-config'; import type { LoginForm as LoginFormType } from './login-form'; // The instance's DEFAULT_LOCALE, the sign-in providers it has set up, and @@ -94,7 +95,10 @@ describe('the sign-in page', () => { expect(screen.queryByText('or')).not.toBeInTheDocument(); const footer = within(screen.getByRole('navigation', { name: 'Footer' })); expect(footer.getByRole('link', { name: 'Privacy' })).toHaveAttribute('href', '/privacy'); - expect(await generateMetadata()).toEqual({ title: 'Sign in', robots: { index: false } }); + expect(await generateMetadata()).toEqual({ + title: { absolute: `Sign in · ${INSTANCE_NAME}` }, + robots: { index: false }, + }); }); it('offers each sign-in provider the instance has set up, in English', async () => { @@ -127,7 +131,9 @@ describe('the sign-in page', () => { const { frame } = await renderPage(); expect(frame).toHaveAttribute('lang', 'en'); expect(screen.getByRole('heading', { level: 1 })).toHaveTextContent('Sign in to OpenSignup'); - expect(await generateMetadata()).toMatchObject({ title: 'Sign in' }); + expect(await generateMetadata()).toMatchObject({ + title: { absolute: `Sign in · ${INSTANCE_NAME}` }, + }); }); it('is in that language once it has shipped to organizers', async () => { @@ -159,7 +165,7 @@ describe('the sign-in page', () => { ); expect(footer.getByRole('link', { name: `common.footer.privacy in ${other}` })).toBeVisible(); expect(await generateMetadata()).toEqual({ - title: `auth.tabTitle in ${other}`, + title: { absolute: `auth.tabTitle in ${other} · ${INSTANCE_NAME}` }, robots: { index: false }, }); }); diff --git a/src/app/(organizer)/login/page.tsx b/src/app/(organizer)/login/page.tsx index 1159d8a0..1e1fa57a 100644 --- a/src/app/(organizer)/login/page.tsx +++ b/src/app/(organizer)/login/page.tsx @@ -12,6 +12,7 @@ import { getDb } from '@/db/client'; import { signInLocale } from '@/i18n/locale'; import { getServerTranslator } from '@/i18n/server'; import { RateLimits, chargeRateLimit, ipSubject } from '@/lib/rate-limit'; +import { INSTANCE_NAME } from '@/lib/site-config'; import { EmailSchema } from '@/schemas/common'; import { codeRefusal } from './code-refusal'; import { LoginForm, type CodeActionResult, type LoginActionResult } from './login-form'; @@ -19,9 +20,13 @@ import { loginFormText } from './login-text'; import { OAuthButtons } from './oauth-buttons'; import { requestMagicLink } from './request-magic-link'; +// The tab title, with the site name after it. Next applies the root layout's +// title template only to the segments below the layout's own, and this page +// shares its segment with that layout (./layout.tsx), so it writes the site +// name in itself, the way the template does for every other page. export async function generateMetadata(): Promise { const t = getServerTranslator(signInLocale(), 'auth'); - return { title: t('tabTitle'), robots: { index: false } }; + return { title: { absolute: `${t('tabTitle')} · ${INSTANCE_NAME}` }, robots: { index: false } }; } export default async function LoginPage({ diff --git a/src/app/(organizer)/oauth/layout.tsx b/src/app/(organizer)/oauth/layout.tsx new file mode 100644 index 00000000..f557c0cd --- /dev/null +++ b/src/app/(organizer)/oauth/layout.tsx @@ -0,0 +1,22 @@ +import { getOrganizerSession } from '@/auth/session'; +import { localeOfOrganizer } from '@/i18n/locale'; +import { RootShell, rootMetadata, rootViewport } from '../../root-shell'; + +export const metadata = rootMetadata; +export const viewport = rootViewport; + +/** + * The root layout for the AI assistant's consent screen (`/oauth/consent`), + * in the organizer's language (`localeOfOrganizer`), as the screen's text is: + * they're signed in by then. With nobody signed in, the page says the request + * can't go on, or sends them to sign in, in the site default, else English, + * and so does this. The page reads the session itself, and the read is + * cached for the request, so this costs no statement. `../app/layout.tsx` + * says why the sign-in pages have a root layout of their own. + * + * The provider's error pages aren't under it: they're HTML the provider + * writes (`src/oauth/provider.ts`), in the sign-in pages' language. + */ +export default async function ConsentLayout({ children }: { children: React.ReactNode }) { + return {children}; +} diff --git a/src/app/(organizer)/root-layouts.test.tsx b/src/app/(organizer)/root-layouts.test.tsx new file mode 100644 index 00000000..8dec3a4e --- /dev/null +++ b/src/app/(organizer)/root-layouts.test.tsx @@ -0,0 +1,119 @@ +import type { ReactElement } from 'react'; +import { afterEach, describe, expect, it, vi } from 'vitest'; +import { CATALOG_LOCALES } from '@/i18n/config'; +import { ship } from '@/i18n/testing/ship'; + +// Who is signed in, with the language stored on their account, and the +// instance's settings: unit tests have no DATABASE_URL, so the real getEnv() +// would throw. +const request = vi.hoisted(() => ({ + session: null as null | { locale: string | null }, + env: { DEFAULT_LOCALE: undefined as string | undefined }, +})); +const getOrganizerSession = vi.hoisted(() => vi.fn(async () => request.session)); +vi.mock('@/auth/session', () => ({ getOrganizerSession })); +vi.mock('@/lib/env', () => ({ getEnv: () => request.env })); +// The `` itself loads the font and the stylesheet, which only Next can; +// what's checked here is the language each layout gives it. +vi.mock('@/app/root-shell', () => ({ + rootMetadata: {}, + rootViewport: {}, + RootShell: ({ children }: { children: React.ReactNode }) => children, +})); + +const { default: AppLayout } = await import('./app/layout'); +const { default: ConsentLayout } = await import('./oauth/layout'); +const { default: SignInLayout } = await import('./login/layout'); + +type RootLayout = (props: { children: React.ReactNode }) => ReactElement | Promise; + +/** The `` a root layout gives its pages. */ +async function htmlLang(layout: RootLayout): Promise { + const shell = (await layout({ children: null })) as ReactElement<{ lang: string }>; + return shell.props.lang; +} + +/** Every language with a catalog besides English, each tried in turn. */ +const OTHER_LANGUAGES = CATALOG_LOCALES.filter((locale) => locale !== 'en'); + +afterEach(() => { + request.session = null; + request.env.DEFAULT_LOCALE = undefined; + getOrganizerSession.mockClear(); + vi.unstubAllEnvs(); +}); + +describe.each(OTHER_LANGUAGES)('with %s', (other) => { + describe.each([ + ['the organizer app', AppLayout], + ['the consent screen', ConsentLayout], + ] as const)('%s', (_name, layout) => { + it('is in the language stored on the signed-in organizer’s account', async () => { + ship('organizer', ['en', other]); + request.session = { locale: other }; + expect(await htmlLang(layout)).toBe(other); + request.session = { locale: 'en' }; + request.env.DEFAULT_LOCALE = other; + expect(await htmlLang(layout)).toBe('en'); + }); + + it('is in the site default, else English, for an organizer with none stored', async () => { + ship('organizer', ['en', other]); + request.session = { locale: null }; + expect(await htmlLang(layout)).toBe('en'); + request.env.DEFAULT_LOCALE = other; + expect(await htmlLang(layout)).toBe(other); + }); + + it('is in the site default, else English, with nobody signed in', async () => { + ship('organizer', ['en', other]); + expect(await htmlLang(layout)).toBe('en'); + request.env.DEFAULT_LOCALE = other; + expect(await htmlLang(layout)).toBe(other); + }); + + it('is English while only English has shipped to organizers, whatever is stored', async () => { + request.session = { locale: other }; + request.env.DEFAULT_LOCALE = other; + expect(await htmlLang(layout)).toBe('en'); + }); + + // As the screens are, so the e2e specs can see a language that hasn't + // shipped on the page's `` too. + it('keeps the e2e run’s unshipped language stored on the account', async () => { + vi.stubEnv('E2E_UNSHIPPED_LOCALES', other); + request.session = { locale: other }; + expect(await htmlLang(layout)).toBe(other); + request.session = null; + request.env.DEFAULT_LOCALE = other; + expect(await htmlLang(layout)).toBe('en'); + }); + }); + + describe('the sign-in pages', () => { + it('are in the site default, else English, whoever is signed in', async () => { + ship('organizer', ['en', other]); + request.session = { locale: other }; + expect(await htmlLang(SignInLayout)).toBe('en'); + request.env.DEFAULT_LOCALE = other; + expect(await htmlLang(SignInLayout)).toBe(other); + request.session = { locale: 'en' }; + expect(await htmlLang(SignInLayout)).toBe(other); + }); + + it('are English while only English has shipped to organizers', async () => { + vi.stubEnv('E2E_UNSHIPPED_LOCALES', other); + request.session = { locale: other }; + request.env.DEFAULT_LOCALE = other; + expect(await htmlLang(SignInLayout)).toBe('en'); + }); + + // The check and confirm pages read none, and mustn't start loading one. + it('read no session', async () => { + ship('organizer', ['en', other]); + request.session = { locale: other }; + await htmlLang(SignInLayout); + expect(getOrganizerSession).not.toHaveBeenCalled(); + }); + }); +}); diff --git a/src/app/global-not-found.tsx b/src/app/global-not-found.tsx index e7ac11b1..b8d6ea7a 100644 --- a/src/app/global-not-found.tsx +++ b/src/app/global-not-found.tsx @@ -14,7 +14,7 @@ export const viewport = rootViewport; /** * What an address no page matches gets, with a 404 (`globalNotFound` in - * next.config.mjs). With three root layouts and none above them, nothing else + * next.config.mjs). With several root layouts and none above them, nothing else * could give it a ``. It renders outside every layout, so it brings * its own shell, and it's prerendered. A `notFound()` from a page renders the * nearest not-found page instead, inside the page's own root layout: a diff --git a/src/app/root-shell.tsx b/src/app/root-shell.tsx index b6b749f8..b92e8cf6 100644 --- a/src/app/root-shell.tsx +++ b/src/app/root-shell.tsx @@ -5,13 +5,17 @@ import { APP_ORIGIN, INSTANCE_NAME } from '@/lib/site-config'; import { inter } from './fonts'; import './globals.css'; -// What the three root layouts share: `(site)/layout.tsx` (home, help, legal), -// `(organizer)/layout.tsx` (the organizer app, sign-in, OAuth consent) and -// `s/[slug]/layout.tsx` (a signup's pages), plus `global-not-found.tsx`. Each -// is a root layout so it can set `` itself: a signup's pages in the -// signup's language, while help and legal stay static. One layout above every -// page couldn't see a signup's slug, and reading the request there would make -// every page dynamic. Moving between root layouts is a full page load. +// What the root layouts share: `(site)/layout.tsx` (home, help, legal), the +// organizer's three, `(organizer)/app/layout.tsx` (the organizer app), +// `(organizer)/oauth/layout.tsx` (OAuth consent) and +// `(organizer)/login/layout.tsx` (sign-in), and `s/[slug]/layout.tsx` (a +// signup's pages), plus `global-not-found.tsx`. Each is a root layout so it +// can set `` itself: the organizer's pages in the organizer's +// language, the sign-in pages in the site's without reading a session, and a +// signup's pages in the signup's language, while help and legal stay static. +// One layout above every page couldn't see a signup's slug or tell sign-in +// from the pages after it, and reading the request there would make every +// page dynamic. Moving between root layouts is a full page load. // Kept under 160 characters so search engines don't truncate it, and over 110 // so crawlers (Ahrefs, Screaming Frog) don't flag it as too thin. diff --git a/tests/e2e/organizer-language-story.spec.ts b/tests/e2e/organizer-language-story.spec.ts index 30dac19a..c14029c9 100644 --- a/tests/e2e/organizer-language-story.spec.ts +++ b/tests/e2e/organizer-language-story.spec.ts @@ -50,6 +50,9 @@ for (const locale of CATALOG_LOCALES.filter((other) => other !== 'en')) { .click(); const saveNotice = messagesIn(locale, 'organizer.saveNotice'); await expect(page.getByRole('status')).toHaveText(saveNotice('saved')); + // With no reload: a server action that redirects renders the whole page + // it goes to, its root layout included. + await expect(page.locator('html')).toHaveAttribute('lang', locale); } // Your signups. @@ -58,6 +61,7 @@ for (const locale of CATALOG_LOCALES.filter((other) => other !== 'en')) { const heading = page.getByRole('heading', { level: 1, name: dashboard('title') }); await expect(heading, unshippedHint).toBeVisible(); expect(await languageOf(heading), unshippedHint).toBe(locale); + await expect(page.locator('html')).toHaveAttribute('lang', locale); // A new signup, from the form, which opens its Build tab. const newSignup = messagesIn(locale, 'organizer.newSignup'); diff --git a/tests/e2e/organizer-language.spec.ts b/tests/e2e/organizer-language.spec.ts index b4669dbc..ff7e7798 100644 --- a/tests/e2e/organizer-language.spec.ts +++ b/tests/e2e/organizer-language.spec.ts @@ -149,6 +149,24 @@ for (const stored of STORED) { await expect(here).toHaveText(crumbs('newSignup')); }); + test(`gets ${locale} on , and the sign-in pages the site’s`, async ({ page }) => { + const html = page.locator('html'); + // The page itself, which screen readers and browser translation read, + // and what anything outside the screens' own marks falls back to. + await page.goto('/app'); + await expect(html, unshippedHint).toHaveAttribute('lang', locale); + + // The sign-in pages are in the site default, else English, whoever is + // signed in, as their text is: this server sets no DEFAULT_LOCALE, and + // the check page reads no session. + await page.goto('/login/check'); + await expect(html).toHaveAttribute('lang', 'en'); + // It moves on once it sees the session, to the organizer app's own root + // layout, so the whole page loads, in the organizer's language. + await page.waitForURL(/\/app$/); + await expect(html, unshippedHint).toHaveAttribute('lang', locale); + }); + test(`sees account Settings and Connected apps in ${locale}`, async ({ page }) => { const settings = messagesIn(locale, 'organizer.settings'); const apps = messagesIn(locale, 'organizer.connectedApps'); @@ -207,6 +225,7 @@ for (const stored of STORED) { 'OAUTH_STATIC_CLIENTS has no "e2e-client": set it as in .env.example', ); await expect(page).toHaveURL(/\/oauth\/consent\//); + await expect(page.locator('html'), unshippedHint).toHaveAttribute('lang', locale); const permissions = page.getByRole('heading', { level: 2 }); await expect(permissions).toHaveText(consent('permissions')); expect(await languageOf(permissions), unshippedHint).toBe(locale); @@ -330,8 +349,8 @@ for (const stored of STORED) { await onScreen(page.getByRole('button', { name: share('button') })).click(); const panel = page.getByRole('dialog', { name: share('heading.later') }); await expect(panel).toBeVisible(); - // A phone's sheet sits outside the page's wrapper, under (#938). - if (!phone) expect(await languageOf(panel), unshippedHint).toBe(locale); + // A phone's sheet sits outside the page's wrapper, so it's 's. + expect(await languageOf(panel), unshippedHint).toBe(locale); await expect(panel.getByText(share(phone ? 'lead.phone' : 'lead.desktop'))).toBeVisible(); await expect(panel.getByRole('button', { name: share('copyLink') })).toBeVisible(); await expect( diff --git a/tests/e2e/root-layouts.spec.ts b/tests/e2e/root-layouts.spec.ts index 29c1e50a..1882a162 100644 --- a/tests/e2e/root-layouts.spec.ts +++ b/tests/e2e/root-layouts.spec.ts @@ -8,7 +8,7 @@ const seed = loadSeed(); const escapeRegExp = (text: string) => text.replace(/[.*+?^${}()|[\]\\]/g, '\\$&'); -// The app has three root layouts and none above them (src/app/root-shell.tsx). +// The app has several root layouts and none above them (src/app/root-shell.tsx). // Each must still give its pages the language, the icons and the manifest the // single root layout used to, and an address no page matches must get the // site's own 404 rather than Next's, which has no `lang`. diff --git a/tests/e2e/sign-in-text.spec.ts b/tests/e2e/sign-in-text.spec.ts index 8d30cbe2..e5dabc51 100644 --- a/tests/e2e/sign-in-text.spec.ts +++ b/tests/e2e/sign-in-text.spec.ts @@ -16,6 +16,7 @@ test.describe('the sign-in pages, in English', () => { const email = `e2e-text-${Date.now()}@example.com`; await page.goto(`${BASE_URL}/login`, { waitUntil: 'networkidle' }); await expect(page).toHaveTitle(/^Sign in · /); + await expect(page.locator('html')).toHaveAttribute('lang', 'en'); await expect(page.locator('main').locator('..')).toHaveAttribute('lang', 'en'); await expect(page.getByRole('heading', { level: 1 })).toHaveText('Sign in to OpenSignup'); await expect( @@ -37,6 +38,7 @@ test.describe('the sign-in pages, in English', () => { test('the check-your-email page says how long the link lasts', async ({ page }) => { await page.goto(`${BASE_URL}/login/check?callbackUrl=%2Fapp`); await expect(page).toHaveTitle(/^Check your email · /); + await expect(page.locator('html')).toHaveAttribute('lang', 'en'); await expect(page.getByRole('heading', { level: 1 })).toHaveText('Check your email'); await expect(page.getByText(/^We sent a sign-in link/)).toHaveText( /^We sent a sign-in link to your inbox\. Click it to continue\. The link expires in \d+ (minutes?|hours?|days?)( \d+ (minutes?|hours?))?\. This page will move on by itself once you have signed in\.$/, @@ -48,6 +50,7 @@ test.describe('the sign-in pages, in English', () => { const next = `${BASE_URL}/api/auth/callback/nodemailer?token=not-a-real-token&email=pat%40example.com`; await page.goto(`${BASE_URL}/login/confirm?next=${encodeURIComponent(next)}`); await expect(page).toHaveTitle(/^Sign in · /); + await expect(page.locator('html')).toHaveAttribute('lang', 'en'); await expect(page.getByRole('heading', { level: 1 })).toHaveText('Sign in to OpenSignup'); const line = page.getByText(/^Click the button below/); await expect(line).toHaveText('Click the button below to sign in as pat@example.com.');