peer-at-code-web/tests/index.test.ts
2024-03-24 23:15:58 +01:00

51 lines
1.3 KiB
TypeScript

import { expect, test } from '@playwright/test';
test('index page redirects to login page', async ({ page }) => {
await page.goto('/');
await page.waitForURL('/login');
await expect(page.url()).toContain('/login');
});
test('login page has a register link that redirects to the register page', async ({ page }) => {
await page.goto('/login');
const link = await page.$('a[href*="/register"]');
await link?.click();
await page.waitForURL('/register');
await expect(page.url()).toContain('/register');
});
test('register page has a login link that redirects to the login page', async ({ page }) => {
await page.goto('/register');
const link = await page.$('a[href*="/login"]');
await link?.click();
await page.waitForURL('/login');
await expect(page.url()).toContain('/login');
});
test('dashboard page redirects to login page if user is not logged in', async ({ page }) => {
await page.goto('');
await expect(page.url()).toContain('/login');
});
test('login form accepts valid credentials', async ({ page }) => {
await page.context().clearCookies();
await page.goto('/login');
await page.fill('input[name="pseudo"]', 'glazk0');
await page.fill('input[name="passwd"]', 'Cookies Are #Miam42');
await Promise.all([page.getByRole('button').click(), page.waitForURL('')]);
await expect(page.url()).toContain('');
});