Skip to content

Commit 3db8066

Browse files
fix: tests e2e (#2915)
Co-authored-by: Gary van Woerkens <gary.van-woerkens@sg.social.gouv.fr>
1 parent bc4c4b2 commit 3db8066

3 files changed

Lines changed: 25 additions & 23 deletions

File tree

packages/app/src/e2e/declaration.e2e.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,11 @@ import { expect, test } from "@playwright/test";
33
import { loginWithProConnect } from "./helpers/login";
44

55
test.describe("Declaration workflow", () => {
6+
test.skip(
7+
!process.env.SITE_URL,
8+
"Requires a deployed environment with ProConnect",
9+
);
10+
611
test.beforeEach(async ({ page }) => {
712
await loginWithProConnect(page);
813
});

packages/app/src/e2e/helpers/login.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,19 @@
11
import type { Page } from "@playwright/test";
22

3+
/** Dismiss the cookie consent banner if present. */
4+
export async function dismissCookieBanner(page: Page) {
5+
const refuseButton = page.getByRole("button", { name: "Tout refuser" });
6+
if (await refuseButton.isVisible({ timeout: 2000 }).catch(() => false)) {
7+
await refuseButton.click();
8+
}
9+
}
10+
311
/** Log in via ProConnect using the FIA1V2 test identity provider. */
412
export async function loginWithProConnect(page: Page) {
513
await page.goto("/login");
14+
await dismissCookieBanner(page);
615
await page
7-
.getByRole("button", { name: /s'identifier avec\s*proconnect/i })
16+
.getByRole("button", { name: /s.identifier avec\s*proconnect/i })
817
.click();
918

1019
// Fill ProConnect login form with the FIA1V2 test identity

packages/app/src/e2e/login.e2e.ts

Lines changed: 10 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,28 @@
11
import { expect, test } from "@playwright/test";
22

3-
import { loginWithProConnect } from "./helpers/login";
3+
import { dismissCookieBanner, loginWithProConnect } from "./helpers/login";
44

55
test.describe("Login page", () => {
6-
test("displays ProConnect button and accordion", async ({ page }) => {
6+
test("displays ProConnect button", async ({ page }) => {
77
await page.goto("/login");
8+
await dismissCookieBanner(page);
89

910
await expect(
10-
page.getByRole("button", { name: /s'identifier avec\s*proconnect/i }),
11-
).toBeVisible();
12-
13-
// Accordion with account creation help
14-
await expect(
15-
page.getByRole("button", {
16-
name: /vous n'avez pas de compte/i,
17-
}),
11+
page.getByRole("button", { name: /s.identifier avec\s*proconnect/i }),
1812
).toBeVisible();
1913
});
2014
});
2115

2216
test.describe("ProConnect authentication flow", () => {
17+
test.skip(
18+
!process.env.SITE_URL,
19+
"Requires a deployed environment with ProConnect",
20+
);
21+
2322
test("redirects to declaration page after login", async ({ page }) => {
2423
await loginWithProConnect(page);
2524

2625
await page.waitForURL("**/declaration-remuneration");
27-
// Authenticated state is confirmed by the user-menu button
2826
await expect(
2927
page.getByRole("button", { name: "Mon espace" }),
3028
).toBeVisible();
@@ -37,7 +35,6 @@ test.describe("ProConnect authentication flow", () => {
3735
test("shows user menu in header after login", async ({ page }) => {
3836
await loginWithProConnect(page);
3937

40-
// "Mon espace" button should appear instead of "Se connecter"
4138
await expect(
4239
page.getByRole("button", { name: "Mon espace" }),
4340
).toBeVisible();
@@ -46,10 +43,8 @@ test.describe("ProConnect authentication flow", () => {
4643
test("displays user info in account menu", async ({ page }) => {
4744
await loginWithProConnect(page);
4845

49-
// Open user menu
5046
await page.getByRole("button", { name: "Mon espace" }).click();
5147

52-
// Verify logout menu item is available (role="menuitem" on the link)
5348
await expect(
5449
page.getByRole("menuitem", { name: "Se déconnecter" }),
5550
).toBeVisible();
@@ -58,20 +53,15 @@ test.describe("ProConnect authentication flow", () => {
5853
test("logs out and returns to unauthenticated state", async ({ page }) => {
5954
await loginWithProConnect(page);
6055

61-
// Open user menu and click logout
6256
await page.getByRole("button", { name: "Mon espace" }).click();
6357
await page.getByRole("menuitem", { name: "Se déconnecter" }).click();
6458

65-
// NextAuth shows a sign-out confirmation page with a CSRF form.
66-
// The button label "Sign out" is NextAuth's default English copy;
67-
// update this selector if the sign-out page is ever customised.
6859
await page.waitForURL("**/api/auth/signout**");
6960
await page.getByRole("button", { name: /sign out/i }).click();
7061

71-
// After sign-out, NextAuth redirects to the login page
7262
await page.waitForURL("**/login", { timeout: 10000 });
7363
await expect(
74-
page.getByRole("button", { name: /s'identifier avec\s*proconnect/i }),
64+
page.getByRole("button", { name: /s.identifier avec\s*proconnect/i }),
7565
).toBeVisible();
7666
});
7767

@@ -80,10 +70,8 @@ test.describe("ProConnect authentication flow", () => {
8070
}) => {
8171
await loginWithProConnect(page);
8272

83-
// Navigate to /login while already authenticated
8473
await page.goto("/login");
8574

86-
// Should be redirected to /declaration-remuneration
8775
await page.waitForURL("**/declaration-remuneration");
8876
await expect(
8977
page.getByRole("heading", {

0 commit comments

Comments
 (0)