PocketBase gains optional, manually-authored English fields on articles and categories (same record, same slug), and the frontend serves an /en counterpart of every dynamic route via thin page wrappers around shared view components — no i18n library, consistent with the project's existing minimalism stance for a two-locale site with ~20 UI strings. An article/category with no translation 404s cleanly on its own /en detail page and is filtered out of /en listings, and the header's language-switch link falls back to the English blog index rather than a dead link; resolving that requires a global route middleware, since the layout's header renders before the page content in document order and so can't react to state a page component sets during its own async setup.
52 lines
1.9 KiB
TypeScript
52 lines
1.9 KiB
TypeScript
import { expect, test } from '@playwright/test'
|
|
|
|
test('English home page renders in English', async ({ page }) => {
|
|
await page.goto('/en')
|
|
|
|
await expect(page.locator('html')).toHaveAttribute('lang', 'en')
|
|
await expect(page.getByRole('link', { name: 'Read the latest article' })).toBeVisible()
|
|
})
|
|
|
|
test('English blog archive lists only translated articles', async ({ page }) => {
|
|
await page.goto('/en/blog')
|
|
|
|
await expect(page.getByRole('link', { name: 'Published article' })).toBeVisible()
|
|
await expect(page.getByText('Secondo articolo pubblicato')).toHaveCount(0)
|
|
})
|
|
|
|
test('translated article renders in English at the /en prefix', async ({ page }) => {
|
|
await page.goto('/en/blog/articolo-pubblicato')
|
|
|
|
await expect(page.getByRole('heading', { level: 1, name: 'Published article' })).toBeVisible()
|
|
await expect(page.locator('.prose strong')).toHaveText('markdown')
|
|
})
|
|
|
|
test('an untranslated article 404s under /en', async ({ page }) => {
|
|
const response = await page.goto('/en/blog/secondo-articolo')
|
|
|
|
expect(response?.status()).toBe(404)
|
|
})
|
|
|
|
test('language switch links to the English version of a translated article', async ({ page }) => {
|
|
await page.goto('/blog/articolo-pubblicato')
|
|
|
|
const languageSwitch = page.getByRole('link', { name: 'English' })
|
|
await expect(languageSwitch).toHaveAttribute('href', '/en/blog/articolo-pubblicato')
|
|
})
|
|
|
|
test('language switch falls back to the English blog index for an untranslated article', async ({ page }) => {
|
|
await page.goto('/blog/secondo-articolo')
|
|
|
|
const languageSwitch = page.getByRole('link', { name: 'English' })
|
|
await expect(languageSwitch).toHaveAttribute('href', '/en/blog')
|
|
})
|
|
|
|
test('language switch on the Italian-only corralito page falls back to the English home page', async ({
|
|
page,
|
|
}) => {
|
|
await page.goto('/come-difendersi-dal-corralito')
|
|
|
|
const languageSwitch = page.getByRole('link', { name: 'English' })
|
|
await expect(languageSwitch).toHaveAttribute('href', '/en')
|
|
})
|