Skip to content

Commit 25bd9ab

Browse files
author
HusneShabbir
committed
fix(e2e): add locale display name mapping for non-Latin alphabets
Add LOCALE_DISPLAY_NAMES mapping to convert locale codes (en, fr, it, ja) to their native display names (English, Français, Italiano, 日本語). This fixes Japanese locale tests which require matching by native name.
1 parent b524110 commit 25bd9ab

File tree

11 files changed

+225
-22
lines changed

11 files changed

+225
-22
lines changed

workspaces/adoption-insights/packages/app/e2e-tests/utils/insightsHelpers.ts

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,24 @@
1515
*/
1616
import { Page, expect } from '@playwright/test';
1717

18+
/**
19+
* Mapping of locale codes to their native display names
20+
*/
21+
const LOCALE_DISPLAY_NAMES: Record<string, string> = {
22+
en: 'English',
23+
fr: 'Français',
24+
it: 'Italiano',
25+
ja: '日本語',
26+
};
27+
28+
/**
29+
* Get the display name for a locale code
30+
*/
31+
export function getLocaleDisplayName(locale: string): string {
32+
const baseLocale = locale.split('-')[0];
33+
return LOCALE_DISPLAY_NAMES[baseLocale] || locale;
34+
}
35+
1836
/**
1937
* Navigate to a page using the navigation link text
2038
*/
@@ -79,9 +97,13 @@ export async function switchToLocale(
7997
page: Page,
8098
locale: string,
8199
): Promise<void> {
100+
const baseLocale = locale.split('-')[0];
101+
if (baseLocale === 'en') return;
102+
103+
const displayName = getLocaleDisplayName(locale);
82104
await page.getByRole('link', { name: 'Settings' }).click();
83105
await page.getByRole('button', { name: 'English' }).click();
84-
await page.getByRole('option', { name: locale }).click();
106+
await page.getByRole('option', { name: displayName }).click();
85107
await page.locator('a').filter({ hasText: 'Home' }).click();
86108
}
87109

workspaces/bulk-import/packages/app/e2e-tests/utils/helpers.ts

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,19 +17,41 @@
1717
import AxeBuilder from '@axe-core/playwright';
1818
import { expect, Page, TestInfo } from '@playwright/test';
1919

20+
/**
21+
* Mapping of locale codes to their native display names
22+
*/
23+
const LOCALE_DISPLAY_NAMES: Record<string, string> = {
24+
en: 'English',
25+
fr: 'Français',
26+
it: 'Italiano',
27+
ja: '日本語',
28+
};
29+
30+
/**
31+
* Get the display name for a locale code
32+
* @param locale - The locale code (e.g., 'en', 'fr', 'ja')
33+
* @returns The native display name (e.g., 'English', 'Français', '日本語')
34+
*/
35+
export function getLocaleDisplayName(locale: string): string {
36+
const baseLocale = locale.split('-')[0];
37+
return LOCALE_DISPLAY_NAMES[baseLocale] || locale;
38+
}
39+
2040
/**
2141
* Switch to a different locale in the application settings
2242
* @param page - Playwright page object
23-
* @param locale - The locale to switch to (e.g., 'en', 'fr', 'de', 'es')
43+
* @param locale - The locale to switch to (e.g., 'en', 'fr', 'it', 'ja')
2444
*/
2545
export async function switchToLocale(
2646
page: Page,
2747
locale: string,
2848
): Promise<void> {
29-
if (locale !== 'en') {
49+
const baseLocale = locale.split('-')[0];
50+
if (baseLocale !== 'en') {
51+
const displayName = getLocaleDisplayName(locale);
3052
await page.getByRole('link', { name: 'Settings' }).click();
3153
await page.getByRole('button', { name: 'English' }).click();
32-
await page.getByRole('option', { name: locale }).click();
54+
await page.getByRole('option', { name: displayName }).click();
3355
await page.locator('a').filter({ hasText: 'Home' }).click();
3456
// Wait for page to settle after locale switch and reload
3557
await page.waitForLoadState('networkidle');

workspaces/extensions/packages/app/e2e-tests/extensions.test.ts

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,24 @@ import { runAccessibilityTests } from './utils/accessibility';
2020
import { ExtensionHelper } from './utils/helper';
2121
import { ExtensionsMessages, getTranslations } from './utils/translations';
2222

23+
/**
24+
* Mapping of locale codes to their native display names
25+
*/
26+
const LOCALE_DISPLAY_NAMES: Record<string, string> = {
27+
en: 'English',
28+
fr: 'Français',
29+
it: 'Italiano',
30+
ja: '日本語',
31+
};
32+
33+
/**
34+
* Get the display name for a locale code
35+
*/
36+
function getLocaleDisplayName(locale: string): string {
37+
const baseLocale = locale.split('-')[0];
38+
return LOCALE_DISPLAY_NAMES[baseLocale] || locale;
39+
}
40+
2341
test.describe('Admin > Extensions', () => {
2442
let extensions: Extensions;
2543
let extensionHelper: ExtensionHelper;
@@ -28,9 +46,13 @@ test.describe('Admin > Extensions', () => {
2846
let sharedContext: BrowserContext;
2947

3048
async function switchToLocale(page: Page, locale: string): Promise<void> {
49+
const baseLocale = locale.split('-')[0];
50+
if (baseLocale === 'en') return;
51+
52+
const displayName = getLocaleDisplayName(locale);
3153
await page.getByRole('link', { name: 'Settings' }).click();
3254
await page.getByRole('button', { name: 'English' }).click();
33-
await page.getByRole('option', { name: locale }).click();
55+
await page.getByRole('option', { name: displayName }).click();
3456
await page.locator('a').filter({ hasText: 'Home' }).click();
3557
}
3658

workspaces/global-floating-action-button/packages/app/e2e-tests/utils/helpers.ts

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,24 @@ import {
2020
GlobalFloatingActionButtonMessages,
2121
} from './translations.js';
2222

23+
/**
24+
* Mapping of locale codes to their native display names
25+
*/
26+
const LOCALE_DISPLAY_NAMES: Record<string, string> = {
27+
en: 'English',
28+
fr: 'Français',
29+
it: 'Italiano',
30+
ja: '日本語',
31+
};
32+
33+
/**
34+
* Get the display name for a locale code
35+
*/
36+
export function getLocaleDisplayName(locale: string): string {
37+
const baseLocale = locale.split('-')[0];
38+
return LOCALE_DISPLAY_NAMES[baseLocale] || locale;
39+
}
40+
2341
async function getPageTranslations(
2442
page: Page,
2543
): Promise<GlobalFloatingActionButtonMessages> {
@@ -46,10 +64,12 @@ export async function switchToLocale(
4664
page: Page,
4765
locale: string,
4866
): Promise<void> {
49-
if (locale !== 'en') {
67+
const baseLocale = locale.split('-')[0];
68+
if (baseLocale !== 'en') {
69+
const displayName = getLocaleDisplayName(locale);
5070
await page.getByRole('link', { name: 'Settings' }).click();
5171
await page.getByRole('button', { name: 'English' }).click();
52-
await page.getByRole('option', { name: locale }).click();
72+
await page.getByRole('option', { name: displayName }).click();
5373
await page.locator('a').filter({ hasText: 'Home' }).click();
5474
}
5575
}

workspaces/global-header/packages/app/e2e-tests/utils/globalHeaderHelper.ts

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,24 @@
1515
*/
1616
import { Page } from '@playwright/test';
1717

18+
/**
19+
* Mapping of locale codes to their native display names
20+
*/
21+
const LOCALE_DISPLAY_NAMES: Record<string, string> = {
22+
en: 'English',
23+
fr: 'Français',
24+
it: 'Italiano',
25+
ja: '日本語',
26+
};
27+
28+
/**
29+
* Get the display name for a locale code
30+
*/
31+
export function getLocaleDisplayName(locale: string): string {
32+
const baseLocale = locale.split('-')[0];
33+
return LOCALE_DISPLAY_NAMES[baseLocale] || locale;
34+
}
35+
1836
/**
1937
* Switch to a different locale
2038
* Extracts base language code (e.g., "en" from "en-US") for locale selection
@@ -23,11 +41,13 @@ export async function switchToLocale(
2341
page: Page,
2442
locale: string,
2543
): Promise<void> {
26-
if (locale !== 'en') {
44+
const baseLocale = locale.split('-')[0];
45+
if (baseLocale !== 'en') {
46+
const displayName = getLocaleDisplayName(locale);
2747
await page.getByRole('button', { name: 'Guest' }).click();
2848
await page.getByRole('menuitem', { name: 'Settings' }).click();
2949
await page.getByRole('button', { name: 'English' }).click();
30-
await page.getByRole('option', { name: locale }).click();
50+
await page.getByRole('option', { name: displayName }).click();
3151
await page.locator('a').filter({ hasText: 'Home' }).click();
3252
}
3353
}

workspaces/homepage/packages/app/e2e-tests/utils/testUtils.ts

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,24 @@
1616

1717
import { Page, expect } from '@playwright/test';
1818

19+
/**
20+
* Mapping of locale codes to their native display names
21+
*/
22+
const LOCALE_DISPLAY_NAMES: Record<string, string> = {
23+
en: 'English',
24+
fr: 'Français',
25+
it: 'Italiano',
26+
ja: '日本語',
27+
};
28+
29+
/**
30+
* Get the display name for a locale code
31+
*/
32+
function getLocaleDisplayName(locale: string): string {
33+
const baseLocale = locale.split('-')[0];
34+
return LOCALE_DISPLAY_NAMES[baseLocale] || locale;
35+
}
36+
1937
export class TestUtils {
2038
private page: Page;
2139

@@ -64,9 +82,13 @@ export class TestUtils {
6482
}
6583

6684
async switchToLocale(locale: string): Promise<void> {
85+
const baseLocale = locale.split('-')[0];
86+
if (baseLocale === 'en') return;
87+
88+
const displayName = getLocaleDisplayName(locale);
6789
await this.page.getByRole('link', { name: 'Settings' }).click();
6890
await this.page.getByRole('button', { name: 'English' }).click();
69-
await this.page.getByRole('option', { name: locale }).click();
91+
await this.page.getByRole('option', { name: displayName }).click();
7092
await this.page.locator('a').filter({ hasText: 'Home' }).click();
7193
}
7294

workspaces/lightspeed/packages/app/e2e-tests/utils/testHelper.ts

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,33 @@ import { Page, expect } from '@playwright/test';
1818
import { mockFeedbackReceived } from './devMode';
1919
import { LightspeedMessages } from './translations';
2020

21+
/**
22+
* Mapping of locale codes to their native display names
23+
*/
24+
const LOCALE_DISPLAY_NAMES: Record<string, string> = {
25+
en: 'English',
26+
fr: 'Français',
27+
it: 'Italiano',
28+
ja: '日本語',
29+
};
30+
31+
/**
32+
* Get the display name for a locale code
33+
*/
34+
export function getLocaleDisplayName(locale: string): string {
35+
const baseLocale = locale.split('-')[0];
36+
return LOCALE_DISPLAY_NAMES[baseLocale] || locale;
37+
}
38+
2139
export const switchToLocale = async (page: Page, locale: string) => {
22-
await page.getByRole('link', { name: 'Settings' }).click();
23-
await page.getByRole('button', { name: 'English' }).click();
24-
await page.getByRole('option', { name: locale }).click();
25-
await page.locator('a').filter({ hasText: 'Home' }).click();
40+
const baseLocale = locale.split('-')[0];
41+
if (baseLocale !== 'en') {
42+
const displayName = getLocaleDisplayName(locale);
43+
await page.getByRole('link', { name: 'Settings' }).click();
44+
await page.getByRole('button', { name: 'English' }).click();
45+
await page.getByRole('option', { name: displayName }).click();
46+
await page.locator('a').filter({ hasText: 'Home' }).click();
47+
}
2648
};
2749

2850
export const openLightspeed = async (page: Page) => {

workspaces/quickstart/packages/app/e2e-tests/quick-start-admin-guest.spec.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,14 @@ test.describe('Test Quick Start plugin', () => {
3131
await page.goto('/');
3232
await page.getByRole('button', { name: 'Enter' }).click();
3333

34-
// Switch to French for French projects
34+
// Switch locale for non-English projects
3535
const projectName = test.info().project.name;
36-
if (projectName === 'fr' || projectName === 'dev-config-fr') {
37-
await switchToLocale(page, 'Français');
36+
const localeMatch = projectName.match(
37+
/^(fr|it|ja)$|^dev-config-(fr|it|ja)$/,
38+
);
39+
if (localeMatch) {
40+
const locale = localeMatch[1] || localeMatch[2];
41+
await switchToLocale(page, locale);
3842
}
3943

4044
const currentLocale = await page.evaluate(

workspaces/quickstart/packages/app/e2e-tests/quick-start-developer.spec.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,14 @@ test.describe('Test Quick Start plugin', () => {
3232
await page.getByRole('button', { name: 'Enter' }).click();
3333

3434
// Switch to French for French projects
35+
// Switch locale for non-English projects
3536
const projectName = test.info().project.name;
36-
if (projectName === 'fr' || projectName === 'dev-config-fr') {
37-
await switchToLocale(page, 'Français');
37+
const localeMatch = projectName.match(
38+
/^(fr|it|ja)$|^dev-config-(fr|it|ja)$/,
39+
);
40+
if (localeMatch) {
41+
const locale = localeMatch[1] || localeMatch[2];
42+
await switchToLocale(page, locale);
3843
}
3944

4045
const currentLocale = await page.evaluate(

workspaces/quickstart/packages/app/e2e-tests/utils/helper.ts

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,24 @@
1515
*/
1616
import { Page, expect } from '@playwright/test';
1717

18+
/**
19+
* Mapping of locale codes to their native display names
20+
*/
21+
const LOCALE_DISPLAY_NAMES: Record<string, string> = {
22+
en: 'English',
23+
fr: 'Français',
24+
it: 'Italiano',
25+
ja: '日本語',
26+
};
27+
28+
/**
29+
* Get the display name for a locale code
30+
*/
31+
export function getLocaleDisplayName(locale: string): string {
32+
const baseLocale = locale.split('-')[0];
33+
return LOCALE_DISPLAY_NAMES[baseLocale] || locale;
34+
}
35+
1836
export class UIhelper {
1937
private page: Page;
2038

@@ -63,6 +81,10 @@ export async function switchToLocale(
6381
page: Page,
6482
locale: string,
6583
): Promise<void> {
84+
const baseLocale = locale.split('-')[0];
85+
if (baseLocale === 'en') return;
86+
87+
const displayName = getLocaleDisplayName(locale);
6688
// Wait for the page to be ready and Settings link to be available
6789
// Use a more reliable approach - wait for the Settings link with a reasonable timeout
6890
await page.waitForLoadState('domcontentloaded');
@@ -75,9 +97,9 @@ export async function switchToLocale(
7597
.waitFor({ state: 'visible', timeout: 5000 });
7698
await page.getByRole('button', { name: 'English' }).click();
7799
await page
78-
.getByRole('option', { name: locale })
100+
.getByRole('option', { name: displayName })
79101
.waitFor({ state: 'visible', timeout: 5000 });
80-
await page.getByRole('option', { name: locale }).click();
102+
await page.getByRole('option', { name: displayName }).click();
81103
await page
82104
.locator('a')
83105
.filter({ hasText: 'Home' })

0 commit comments

Comments
 (0)