File tree Expand file tree Collapse file tree 3 files changed +52
-1
lines changed
Expand file tree Collapse file tree 3 files changed +52
-1
lines changed Original file line number Diff line number Diff line change 11import { 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 } ) => {
Original file line number Diff line number Diff 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 ( ) ;
Original file line number Diff line number Diff line change 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+ }
You can’t perform that action at this time.
0 commit comments