Skip to content

Commit ad8b03f

Browse files
committed
✨ Add more login integration tests
1 parent 6fbdc4f commit ad8b03f

File tree

4 files changed

+37
-2
lines changed

4 files changed

+37
-2
lines changed

frontend/playwright.config.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ export default defineConfig({
2828

2929
/* Collect trace when retrying the failed test. See https://playwright.dev/docs/trace-viewer */
3030
trace: "on-first-retry",
31+
32+
locale: "en-US"
3133
},
3234

3335
/* Configure projects for major browsers */
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"~:type": "~:validation",
3+
"~:code": "~:wrong-credentials"
4+
}

frontend/playwright/helpers/index.js

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,12 @@
1-
export const interceptRPC = async (page, path, jsonFilename) => {
1+
export const interceptRPC = async (page, path, jsonFilename, options = {}) => {
2+
const interceptConfig = {
3+
status: 200,
4+
...options
5+
};
6+
27
await page.route(`**/api/rpc/command/${path}`, (route) => {
38
route.fulfill({
4-
status: 200,
9+
...interceptConfig,
510
contentType: "application/transit+json",
611
path: `playwright/fixtures/${jsonFilename}`,
712
});

frontend/playwright/login.spec.js

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,15 @@ test("Shows login page when going to index and user is logged out", async ({ pag
4040
await expect(page.getByText("Log into my account")).toBeVisible();
4141
});
4242

43+
test("User submit a wrong formated email ", async ({ page }) => {
44+
await interceptRPC(page, "get-profile", "get-profile-anonymous.json");
45+
await page.goto("/");
46+
await page.getByLabel("Email").fill("foo");
47+
48+
await expect(page).toHaveURL(/auth\/login$/);
49+
await expect(page.getByText("Enter a valid email please")).toBeVisible();
50+
});
51+
4352
test("User logs in by filling the login form", async ({ page }) => {
4453
setupLoggedOutUser(page);
4554

@@ -54,3 +63,18 @@ test("User logs in by filling the login form", async ({ page }) => {
5463

5564
await expect(page).toHaveURL(/dashboard/);
5665
});
66+
67+
test("User submits wrong credentials", async ({ page }) => {
68+
await interceptRPC(page, "get-profile", "get-profile-anonymous.json");
69+
await interceptRPC(page, "login-with-password", "login-with-password-error.json", { status: 400 });
70+
71+
await page.goto("/");
72+
73+
await page.getByLabel("Email").fill("[email protected]");
74+
await page.getByLabel("Password").fill("aaaa");
75+
76+
await page.getByRole("button", { name: "Login" }).click();
77+
78+
await expect(page.getByText("Email or password is incorrect")).toBeVisible();
79+
await expect(page).toHaveURL(/auth\/login$/);
80+
});

0 commit comments

Comments
 (0)