diff --git a/frontend/playwright.config.js b/frontend/playwright.config.js index 73245e3ce..08a372946 100644 --- a/frontend/playwright.config.js +++ b/frontend/playwright.config.js @@ -28,6 +28,8 @@ export default defineConfig({ /* Collect trace when retrying the failed test. See https://playwright.dev/docs/trace-viewer */ trace: "on-first-retry", + + locale: "en-US" }, /* Configure projects for major browsers */ diff --git a/frontend/playwright/fixtures/login-with-password-error.json b/frontend/playwright/fixtures/login-with-password-error.json new file mode 100644 index 000000000..c54589e42 --- /dev/null +++ b/frontend/playwright/fixtures/login-with-password-error.json @@ -0,0 +1,4 @@ +{ + "~:type": "~:validation", + "~:code": "~:wrong-credentials" +} diff --git a/frontend/playwright/helpers/index.js b/frontend/playwright/helpers/index.js index 50f7e5487..419dfa918 100644 --- a/frontend/playwright/helpers/index.js +++ b/frontend/playwright/helpers/index.js @@ -1,7 +1,12 @@ -export const interceptRPC = async (page, path, jsonFilename) => { +export const interceptRPC = async (page, path, jsonFilename, options = {}) => { + const interceptConfig = { + status: 200, + ...options + }; + await page.route(`**/api/rpc/command/${path}`, (route) => { route.fulfill({ - status: 200, + ...interceptConfig, contentType: "application/transit+json", path: `playwright/fixtures/${jsonFilename}`, }); diff --git a/frontend/playwright/login.spec.js b/frontend/playwright/login.spec.js index 5463a74f2..5b10ca2ce 100644 --- a/frontend/playwright/login.spec.js +++ b/frontend/playwright/login.spec.js @@ -37,7 +37,16 @@ test("Shows login page when going to index and user is logged out", async ({ pag await page.goto("/"); await expect(page).toHaveURL(/auth\/login$/); - await expect(page.getByText("Log into my account")).toBeVisible(); + await expect(page.getByRole("heading", { name: "Log into my account" } )).toBeVisible(); +}); + +test("User submit a wrong formated email ", async ({ page }) => { + await interceptRPC(page, "get-profile", "get-profile-anonymous.json"); + await page.goto("/"); + await page.getByLabel("Email").fill("foo"); + + await expect(page).toHaveURL(/auth\/login$/); + await expect(page.getByText("Enter a valid email please")).toBeVisible(); }); test("User logs in by filling the login form", async ({ page }) => { @@ -54,3 +63,18 @@ test("User logs in by filling the login form", async ({ page }) => { await expect(page).toHaveURL(/dashboard/); }); + +test("User submits wrong credentials", async ({ page }) => { + await interceptRPC(page, "get-profile", "get-profile-anonymous.json"); + await interceptRPC(page, "login-with-password", "login-with-password-error.json", { status: 400 }); + + await page.goto("/"); + + await page.getByLabel("Email").fill("foo123@example.com"); + await page.getByLabel("Password").fill("aaaa"); + + await page.getByRole("button", { name: "Login" }).click(); + + await expect(page.getByText("Email or password is incorrect")).toBeVisible(); + await expect(page).toHaveURL(/auth\/login$/); +});