Fix e2e tests: Set English language before navigation

- Add context.addInitScript in beforeEach hooks to set English locale before page navigation
- Remove debugging code from useLanguage hook
- Remove unused setup file imports
- Fix exchange test to check for English text correctly
- All frontend tests passing
This commit is contained in:
counterweight 2025-12-25 22:35:27 +01:00
parent 246553c402
commit d2fc7d8850
Signed by: counterweight
GPG key ID: 883EDBAA726BD96C
6 changed files with 52 additions and 46 deletions

View file

@ -35,7 +35,13 @@ async function setAvailability(page: Page, dateStr: string) {
}
test.describe("Exchange Page - Regular User Access", () => {
test.beforeEach(async ({ page }) => {
test.beforeEach(async ({ context, page }) => {
// Set English language before any navigation
await context.addInitScript(() => {
if (typeof window !== "undefined") {
window.localStorage.setItem("arbret-locale", "en");
}
});
await clearAuth(page);
await loginUser(page, REGULAR_USER.email, REGULAR_USER.password);
});
@ -63,7 +69,9 @@ test.describe("Exchange Page - Regular User Access", () => {
// Test clicking buy/sell changes direction
await page.getByRole("button", { name: "Sell BTC" }).click();
await expect(page.getByText(/You buy €\d/)).toBeVisible();
// The summary text is split across elements, so we check for the text parts separately
await expect(page.getByText(/You buy/)).toBeVisible();
await expect(page.getByText(/€\d/)).toBeVisible();
// Test payment method selector
await expect(page.getByText("Payment Method")).toBeVisible();

View file

@ -1,12 +1,16 @@
import { Page } from "@playwright/test";
import { test } from "@playwright/test";
/**
* Set language to English for e2e tests.
* E2E tests should only test in English according to requirements.
* Call this in beforeEach hooks in test files.
* This is applied globally via test.beforeEach in the setup file.
*/
export async function setEnglishLanguage(page: Page) {
await page.addInitScript(() => {
window.localStorage.setItem("arbret-locale", "en");
test.beforeEach(async ({ context }) => {
// Add init script to set English language before any page loads
// This must be called before any page.goto() calls
await context.addInitScript(() => {
if (typeof window !== "undefined") {
window.localStorage.setItem("arbret-locale", "en");
}
});
}
});

View file

@ -70,7 +70,13 @@ async function clearProfileData(page: Page) {
}
test.describe("Profile - Regular User Access", () => {
test.beforeEach(async ({ page }) => {
test.beforeEach(async ({ context, page }) => {
// Set English language before any navigation
await context.addInitScript(() => {
if (typeof window !== "undefined") {
window.localStorage.setItem("arbret-locale", "en");
}
});
await clearAuth(page);
await loginUser(page, REGULAR_USER.email, REGULAR_USER.password);
});