Files
aeternalis/tests/portal.spec.ts
T

75 lines
5.2 KiB
TypeScript

import { test, expect } from '@playwright/test';
test('public directory and account history fit desktop and mobile', async ({ page }) => {
const errors: string[] = []; page.on('pageerror', e => errors.push(e.message));
await page.setViewportSize({ width: 1440, height: 1000 });
await page.goto('/');
await expect(page.getByRole('heading', { name: 'Aeternalis', exact: true })).toBeVisible();
await expect(page.locator('.world-row')).toHaveCount(1);
await expect(page.locator('.world-hero img')).toBeVisible();
await expect.poll(() => page.locator('.world-hero img').evaluate((img: HTMLImageElement) => img.naturalWidth)).toBeGreaterThan(100);
await page.getByRole('button', { name: 'Sign in', exact: true }).click();
await expect(page.getByRole('button', { name: 'Sign out', exact: true })).toBeVisible();
await page.screenshot({ path: 'test-results/website-desktop.png', fullPage: true });
await page.setViewportSize({ width: 390, height: 844 });
expect(await page.evaluate(() => document.documentElement.scrollWidth <= innerWidth)).toBe(true);
await page.screenshot({ path: 'test-results/website-mobile.png', fullPage: true });
expect(errors).toEqual([]);
});
test('admin actions are audited and death permits a distinct replacement', async ({ page }) => {
const origin = 'http://127.0.0.1:18089';
await page.request.post('/auth/dev', { data: {}, headers: { Origin: origin } });
const joined = await page.request.post('/worlds/e2e/api/join', { data: { name: 'Portal life', passage: '' }, headers: { Origin: origin } });
expect(joined.status()).toBe(200); const old = await joined.json();
await page.setViewportSize({ width: 1440, height: 1000 });
await page.goto('/control');
await expect(page.locator('#workspace')).toBeVisible();
await page.getByRole('button', { name: 'Characters', exact: true }).click();
await expect(page.locator('#view-title')).toHaveText('Characters');
await page.getByRole('searchbox', { name: 'Search records' }).fill('Portal life');
await expect(page.locator('#records tbody tr')).toHaveCount(1);
await page.getByRole('button', { name: 'Portal life', exact: true }).click();
await expect(page.locator('#character-dialog')).toBeVisible();
await expect(page.locator('#character-detail')).toContainText(old.entity.id);
await page.getByRole('button', { name: 'Close character', exact: true }).click();
await page.getByLabel(`Action for ${old.entity.id}`).selectOption('rename');
await page.getByLabel('Character name', { exact: true }).fill('Portal renamed');
await page.getByLabel('Reason', { exact: true }).fill('Rename verification');
await page.getByRole('button', { name: 'Queue action' }).click();
await expect.poll(async () => (await (await page.request.get('/api/account')).json()).active?.name).toBe('Portal renamed');
await page.getByRole('searchbox', { name: 'Search records' }).fill('Portal renamed');
await page.getByRole('button', { name: 'Refresh', exact: true }).click();
await expect(page.locator('#records tbody tr')).toHaveCount(1);
await page.screenshot({ path: 'test-results/control-desktop.png', fullPage: true });
await page.getByLabel(`Action for ${old.entity.id}`).selectOption('retire');
await page.getByLabel('Reason', { exact: true }).fill('Permanent death verification');
await page.getByLabel(`Confirm character ID: ${old.entity.id}`).fill(old.entity.id);
await page.getByRole('button', { name: 'Queue action' }).click();
await expect.poll(async () => (await (await page.request.get('/api/account')).json()).active).toBeNull();
await page.goto('/game?world=e2e');
await expect(page.locator('#connection-status')).toHaveText('World online');
await page.getByLabel('Character name', { exact: true }).fill('Portal second life');
await page.getByRole('button', { name: 'Enter world' }).click();
await expect(page.locator('#connection-status')).toHaveText('Connected');
// Default 5s poll was too tight for a fresh join's first snapshot on slow CI hardware.
await expect.poll(() => page.evaluate(() => (window as any).__aeternalis?.snapshot?.self?.entity?.id), { timeout: 15000 }).toBeTruthy();
const current = await page.evaluate(() => (window as any).__aeternalis.snapshot.self.entity.id);
expect(current).not.toBe(old.entity.id);
const account = await (await page.request.get('/api/account')).json();
expect(account.characters.find(c => c.id === old.entity.id).state).toBe('dead');
expect(account.characters.find(c => c.id === old.entity.id).character.deathReason).toContain('Permanent death verification');
await page.goto('/control'); await page.getByRole('button', { name: 'Audit log', exact: true }).click();
await expect(page.locator('#records tbody')).toContainText('Permanent death verification');
await page.setViewportSize({ width: 390, height: 844 });
expect(await page.evaluate(() => document.documentElement.scrollWidth <= innerWidth)).toBe(true);
await page.screenshot({ path: 'test-results/control-mobile.png', fullPage: true });
});
test('control gives anonymous visitors a sign-in state', async ({ page }) => {
await page.goto('/control');
await expect(page.getByRole('heading', { name: 'Sign in to Control' })).toBeVisible();
await expect(page.locator('#workspace')).toBeHidden();
expect((await page.request.get('/api/control')).status()).toBe(401);
});