Skip to content

Commit

Permalink
✨ Add more login integration tests
Browse files Browse the repository at this point in the history
  • Loading branch information
EvaMarco committed Apr 24, 2024
1 parent 6fbdc4f commit ad8b03f
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 2 deletions.
2 changes: 2 additions & 0 deletions frontend/playwright.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand Down
4 changes: 4 additions & 0 deletions frontend/playwright/fixtures/login-with-password-error.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"~:type": "~:validation",
"~:code": "~:wrong-credentials"
}
9 changes: 7 additions & 2 deletions frontend/playwright/helpers/index.js
Original file line number Diff line number Diff line change
@@ -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}`,
});
Expand Down
24 changes: 24 additions & 0 deletions frontend/playwright/login.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,15 @@ test("Shows login page when going to index and user is logged out", async ({ pag
await expect(page.getByText("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 }) => {
setupLoggedOutUser(page);

Expand All @@ -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("[email protected]");
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$/);
});

0 comments on commit ad8b03f

Please sign in to comment.