Skip to content

Commit 4fc01bc

Browse files
committed
test: add locale test
1 parent 3f0c4f5 commit 4fc01bc

File tree

3 files changed

+52
-1
lines changed

3 files changed

+52
-1
lines changed

apps/docs/tests/e2e/basic.spec.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,16 @@
11
import { expect, test } from '@playwright/test';
2+
import { setupLocale } from './utils/locale';
23

3-
test.describe('Basic Route Tests', () => {
4+
test.describe('Basic Route Tests', async () => {
45
test('homepage loads successfully', async ({ page }) => {
6+
const { locale, messages } = await setupLocale();
7+
58
const response = await page.goto('/');
69
expect(response?.status()).toBe(200);
710
await expect(page.locator('body')).toBeVisible();
11+
12+
// Verify page meta title matches message meta title
13+
await expect(page).toHaveTitle(messages.meta.title);
814
});
915

1016
test('blog page loads successfully', async ({ page }) => {

apps/docs/tests/e2e/static-routes.spec.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ test.describe('All routes should return 200', () => {
77
// biome-ignore lint/complexity/noForEach: <explanation>
88
sampleRoutes.forEach((route) => {
99
test(`${route.url}`, async ({ page }) => {
10+
console.log(`Testing route: ${route.url}`);
1011
const response = await page.goto(route.url);
1112
expect(response?.status()).toBe(200);
1213
await expect(page.locator('body')).toBeVisible();
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
export interface LocaleMessages {
2+
meta: {
3+
title: string;
4+
[key: string]: string | number | boolean | object;
5+
};
6+
[key: string]: string | number | boolean | object;
7+
}
8+
9+
/**
10+
* Get the current locale from environment variables or use default
11+
*/
12+
export function getLocale(): string {
13+
return (process.env.LOCALE as string) || 'en';
14+
}
15+
16+
/**
17+
* Load locale messages from the messages directory
18+
*/
19+
export async function loadLocaleMessages(
20+
locale?: string,
21+
): Promise<LocaleMessages> {
22+
const currentLocale = locale || getLocale();
23+
24+
const message = (
25+
await import(`../../../messages/${currentLocale.toLowerCase()}.json`, {
26+
with: { type: 'json' },
27+
})
28+
).default;
29+
30+
return message;
31+
}
32+
33+
/**
34+
* Complete locale setup for a test - loads messages and returns both locale and messages
35+
*/
36+
export async function setupLocale(locale?: string) {
37+
const currentLocale = locale || getLocale();
38+
const messages = await loadLocaleMessages(currentLocale);
39+
40+
return {
41+
locale: currentLocale,
42+
messages,
43+
};
44+
}

0 commit comments

Comments
 (0)