38 lines
1.6 KiB
JavaScript
38 lines
1.6 KiB
JavaScript
|
|
// Unauthenticated smoke tests: no storageState, run as an anonymous visitor.
|
||
|
|
const { test, expect } = require('@playwright/test');
|
||
|
|
|
||
|
|
test('home page loads for an anonymous visitor', async ({ page }) => {
|
||
|
|
await page.goto('/');
|
||
|
|
await expect(page).toHaveTitle(/diora/);
|
||
|
|
await expect(page.locator('.navbar-brand')).toHaveText('diora');
|
||
|
|
await expect(page.locator('.navbar-links a[href="/accounts/login/"]')).toBeVisible();
|
||
|
|
});
|
||
|
|
|
||
|
|
test('login page renders the auth form', async ({ page }) => {
|
||
|
|
await page.goto('/accounts/login/');
|
||
|
|
await expect(page.locator('[name=username]')).toBeVisible();
|
||
|
|
await expect(page.locator('[name=password]')).toBeVisible();
|
||
|
|
});
|
||
|
|
|
||
|
|
test('a new user can register and lands on the home page logged in', async ({ page }) => {
|
||
|
|
const username = `e2e_reg_${Date.now()}`;
|
||
|
|
await page.goto('/accounts/register/');
|
||
|
|
await page.fill('[name=username]', username);
|
||
|
|
await page.fill('[name=password1]', 'a-very-unlikely-pw-98234');
|
||
|
|
await page.fill('[name=password2]', 'a-very-unlikely-pw-98234');
|
||
|
|
await Promise.all([
|
||
|
|
page.waitForURL('/'),
|
||
|
|
page.click('button[type=submit]'),
|
||
|
|
]);
|
||
|
|
await expect(page.locator('.navbar-user')).toHaveText(username);
|
||
|
|
});
|
||
|
|
|
||
|
|
test('login with wrong credentials shows an error and stays on the login page', async ({ page }) => {
|
||
|
|
await page.goto('/accounts/login/');
|
||
|
|
await page.fill('[name=username]', 'nobody-such-user');
|
||
|
|
await page.fill('[name=password]', 'wrong-password');
|
||
|
|
await page.click('button[type=submit]');
|
||
|
|
await expect(page).toHaveURL(/\/accounts\/login\//);
|
||
|
|
await expect(page.locator('.form-errors, .field-errors')).toBeVisible();
|
||
|
|
});
|