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
61
tests/e2e/password-auth.spec.js
Normal file
61
tests/e2e/password-auth.spec.js
Normal file
|
|
@ -0,0 +1,61 @@
|
|||
// @ts-check
|
||||
const { test, expect } = require('@playwright/test');
|
||||
|
||||
const fixtures = JSON.parse(process.env.E2E_FIXTURES || '{}');
|
||||
|
||||
test.describe('Password authentication', () => {
|
||||
test.beforeEach(async ({ page }) => {
|
||||
await page.goto('/login');
|
||||
});
|
||||
|
||||
test.describe('Error states', () => {
|
||||
test('shows error for nonexistent user', async ({ page }) => {
|
||||
await page.fill('#username', 'nobody');
|
||||
await page.fill('#password', 'whatever');
|
||||
await page.click('form[hx-post="/login/password"] button[type="submit"]');
|
||||
|
||||
const alert = page.locator('[role="alert"]');
|
||||
await expect(alert).toBeVisible({ timeout: 5000 });
|
||||
await expect(alert).toContainText('Invalid username or password');
|
||||
});
|
||||
|
||||
test('shows error for wrong password', async ({ page }) => {
|
||||
await page.fill('#username', fixtures.login_username);
|
||||
await page.fill('#password', 'wrongpassword');
|
||||
await page.click('form[hx-post="/login/password"] button[type="submit"]');
|
||||
|
||||
const alert = page.locator('[role="alert"]');
|
||||
await expect(alert).toBeVisible({ timeout: 5000 });
|
||||
await expect(alert).toContainText('Invalid username or password');
|
||||
});
|
||||
});
|
||||
|
||||
test.describe('Successful login', () => {
|
||||
test('redirects to credentials page', async ({ page }) => {
|
||||
await page.fill('#username', fixtures.login_username);
|
||||
await page.fill('#password', fixtures.login_password);
|
||||
await page.click('form[hx-post="/login/password"] button[type="submit"]');
|
||||
|
||||
await page.waitForURL('**/manage/credentials', { timeout: 5000 });
|
||||
expect(page.url()).toContain('/manage/credentials');
|
||||
});
|
||||
});
|
||||
|
||||
test.describe('Form validation attributes', () => {
|
||||
test('username has required attribute', async ({ page }) => {
|
||||
await expect(page.locator('#username')).toHaveAttribute('required', '');
|
||||
});
|
||||
|
||||
test('password has required attribute', async ({ page }) => {
|
||||
await expect(page.locator('#password')).toHaveAttribute('required', '');
|
||||
});
|
||||
|
||||
test('username autocomplete is "username"', async ({ page }) => {
|
||||
await expect(page.locator('#username')).toHaveAttribute('autocomplete', 'username');
|
||||
});
|
||||
|
||||
test('password autocomplete is "current-password"', async ({ page }) => {
|
||||
await expect(page.locator('#password')).toHaveAttribute('autocomplete', 'current-password');
|
||||
});
|
||||
});
|
||||
});
|
||||
Loading…
Add table
Add a link
Reference in a new issue