refactor(e2e): migrate all tests to Playwright Test
This commit is contained in:
parent
174c6c001e
commit
7900f264ba
14 changed files with 398 additions and 401 deletions
62
tests/e2e/full-flow.spec.js
Normal file
62
tests/e2e/full-flow.spec.js
Normal file
|
|
@ -0,0 +1,62 @@
|
|||
// @ts-check
|
||||
const { test, expect } = require('@playwright/test');
|
||||
|
||||
const fixtures = JSON.parse(process.env.E2E_FIXTURES || '{}');
|
||||
|
||||
test.describe('Full user journey', () => {
|
||||
test('register via magic link, set password, logout, login', async ({ page, request }) => {
|
||||
// Verify fixtures are loaded
|
||||
expect(fixtures.register_token).toBeTruthy();
|
||||
|
||||
// ---- Step 1: Register via magic link ----
|
||||
await page.goto(`/register/${fixtures.register_token}`);
|
||||
|
||||
// Should redirect to /manage/credentials?setup=1
|
||||
await page.waitForURL('**/manage/credentials?setup=1', { timeout: 5000 });
|
||||
expect(page.url()).toContain('/manage/credentials');
|
||||
|
||||
// Should show welcome message
|
||||
const welcome = page.locator('[role="status"]');
|
||||
await expect(welcome).toBeVisible();
|
||||
const welcomeText = await welcome.textContent();
|
||||
expect(welcomeText).toContain('Welcome');
|
||||
|
||||
// Page title should contain Porchlight
|
||||
await expect(page).toHaveTitle(/Porchlight/);
|
||||
|
||||
// ---- Step 2: Set password ----
|
||||
const passwordInput = page.locator('#password');
|
||||
const confirmInput = page.locator('#confirm');
|
||||
await expect(passwordInput).toBeVisible();
|
||||
await expect(confirmInput).toBeVisible();
|
||||
|
||||
await passwordInput.fill('mypassword123');
|
||||
await confirmInput.fill('mypassword123');
|
||||
await page.click('#password-section button[type="submit"]');
|
||||
|
||||
// Wait for success message
|
||||
const successMsg = page.locator('#password-section [role="status"]');
|
||||
await expect(successMsg).toBeVisible({ timeout: 5000 });
|
||||
await expect(successMsg).toContainText('Password updated');
|
||||
|
||||
// ---- Step 3: Logout ----
|
||||
await request.post('/logout');
|
||||
|
||||
// Navigate to credentials — should redirect to login since we're logged out
|
||||
await page.goto('/manage/credentials');
|
||||
await page.waitForURL('**/login', { timeout: 5000 });
|
||||
expect(page.url()).toContain('/login');
|
||||
|
||||
// ---- Step 4: Login with the password we just set ----
|
||||
await page.fill('#username', fixtures.register_username);
|
||||
await page.fill('#password', 'mypassword123');
|
||||
await page.click('form[hx-post="/login/password"] button[type="submit"]');
|
||||
|
||||
// Wait for redirect to credentials page
|
||||
await page.waitForURL('**/manage/credentials', { timeout: 5000 });
|
||||
expect(page.url()).toContain('/manage/credentials');
|
||||
|
||||
// Should NOT show setup message (no ?setup=1)
|
||||
await expect(page.locator('[role="status"]:has-text("Welcome")')).toHaveCount(0);
|
||||
});
|
||||
});
|
||||
Loading…
Add table
Add a link
Reference in a new issue