test(frontend): correct test to fit sign up/in

This commit is contained in:
Edouard Vanbelle
2026-07-14 03:21:18 +02:00
parent 691d01a458
commit 341e354162
4 changed files with 475 additions and 449 deletions
+15 -4
View File
@@ -29,11 +29,22 @@ test.describe('SPA · authentication', () => {
await expect(page.getByTestId('login-form')).toBeVisible();
});
test('magic-link panel toggles open', async ({ page }) => {
test('submit button dispatches to magic-link when password is empty', async ({ page }) => {
// Unified login form: one identifier + one optional password + one
// adaptive submit button. Filling the identifier and leaving the
// password blank flips the button label to "Send sign-in link" and
// routes to /api/auth/magic-link/send on click. The old two-form
// UX with `login-magic-toggle-btn` was retired 2026-07-14.
await page.goto('/login');
await page.getByTestId('login-magic-toggle-btn').click();
await expect(page.getByTestId('login-magic-form')).toBeVisible();
await expect(page.getByTestId('login-magic-email-input')).toBeVisible();
await expect(page.getByTestId('login-form')).toBeVisible();
await page.getByTestId('login-username-input').fill('someone@example.test');
// Password intentionally NOT filled — this drives the label swap.
const submit = page.getByTestId('login-submit-btn');
await expect(submit).toBeVisible();
// Label content differs per mode: password-empty → magic-link copy;
// password-filled → "Sign in". Assert the magic-link copy is what's
// shown so the dispatch is provably in the magic-link branch.
await expect(submit).toHaveText(/link|Link|Send/);
});
test('successful login reaches the files app shell', async ({ page }) => {
+14 -6
View File
@@ -58,13 +58,21 @@ test('an oidc callback code is exchanged on load', async ({ page }) => {
});
test('request a magic link from the login page', async ({ page }) => {
// Unified form: leave the password field empty and submit — the
// adaptive submit routes to /api/auth/magic-link/send with the
// identifier as-is (backend accepts email OR username via `@`
// dispatch). Old separate `login-magic-*` testids retired in the
// single-form refactor.
await page.goto('/login');
await page.getByTestId('login-magic-toggle-btn').click();
await expect(page.getByTestId('login-magic-form')).toBeVisible();
await expect(page.getByTestId('login-form')).toBeVisible();
await page.getByTestId('login-magic-email-input').fill('someone@example.test');
await page.getByTestId('login-magic-send-btn').click();
// A status message resolves (success or error); give the request time to run.
await page.getByTestId('login-username-input').fill('someone@example.test');
// Password intentionally NOT filled.
await page.getByTestId('login-submit-btn').click();
// A status message resolves (uniform 200 anti-enum success or error);
// give the request time to run.
await page.waitForTimeout(1_000);
await expect(page.getByTestId('login-magic-form').or(page.getByTestId('login-form')).first()).toBeVisible();
// Still on the login page either way — anti-enum success doesn't redirect.
await expect(page.getByTestId('login-form')).toBeVisible();
});