A test signs in with the sign-in form (#393)
Every browser test signed in with the token link, so the form was never run: login.ts at 0% in the page coverage (#390). login.spec.ts, on the suite's page before anything signs it in: signed out, the app sends you to the form, its name field focused; a wrong password shows the server's "wrong name or password" and leaves you signed out; the right one, submitted with Enter, opens the app as admin. With the form changed to show only its fallback message, the second fails, as it should. login.ts is at 87% of lines now. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
41
tests/ui/login.spec.ts
Normal file
41
tests/ui/login.spec.ts
Normal file
@@ -0,0 +1,41 @@
|
|||||||
|
// The sign-in form (#393). Every other test signs in with the token link, so the form itself --
|
||||||
|
// its fields, its error, where it goes after -- was never run (login.ts at 0% in the coverage).
|
||||||
|
// The suite's page starts signed out here: this file has no beforeEach presenting the token.
|
||||||
|
|
||||||
|
import fs from 'node:fs';
|
||||||
|
import path from 'node:path';
|
||||||
|
import { root } from './global-setup.ts';
|
||||||
|
import { expect, test } from './coverage.ts';
|
||||||
|
|
||||||
|
// The first start made `admin` and wrote its password beside the config, as production's does.
|
||||||
|
const password = () => fs.readFileSync(path.join(root, 'config', 'admin-password'), 'utf8').trim();
|
||||||
|
|
||||||
|
test('signed out, the app sends you to the sign-in form', async ({ page }) => {
|
||||||
|
await page.goto('/');
|
||||||
|
await expect(page).toHaveURL(/\/login$/);
|
||||||
|
await expect(page.locator('#f')).toBeVisible();
|
||||||
|
await expect(page.locator('#name')).toBeFocused();
|
||||||
|
});
|
||||||
|
|
||||||
|
test('a wrong password says so and leaves you signed out', async ({ page }) => {
|
||||||
|
await page.goto('/login');
|
||||||
|
await page.locator('#name').fill('admin');
|
||||||
|
await page.locator('#pw').fill('not the password');
|
||||||
|
await page.getByRole('button', { name: /sign in/i }).click();
|
||||||
|
// The server's own words, not the form's fallback.
|
||||||
|
await expect(page.locator('#msg')).toHaveText('wrong name or password');
|
||||||
|
await expect(page).toHaveURL(/\/login$/);
|
||||||
|
expect((await page.request.get('/api/me')).status()).toBe(401);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('the right name and password sign you in and open the app as you', async ({ page }) => {
|
||||||
|
await page.goto('/login');
|
||||||
|
await page.locator('#name').fill('admin');
|
||||||
|
await page.locator('#pw').fill(password());
|
||||||
|
// Enter submits, as a sign-in form should.
|
||||||
|
await page.locator('#pw').press('Enter');
|
||||||
|
await expect(page).toHaveURL(/\/$/);
|
||||||
|
await expect(page.locator('#feedlist')).toBeVisible();
|
||||||
|
await expect(page.locator('#who')).toContainText('admin');
|
||||||
|
expect((await (await page.request.get('/api/me')).json()).name).toBe('admin');
|
||||||
|
});
|
||||||
Reference in New Issue
Block a user