The item action buttons derived their focus key from the visible label, so
the bag's Equip button became "Equip-<id>" when 9b01ee3 replaced the panel's
own lowercase "equip-<id>" button with itemControls. Slugify the label so the
key stays stable when a button is reworded, and point the progression spec at
the item-action endpoint the refactor moved equip onto -- it still polled the
websocket intents, which no longer carry equip.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
87 lines
7.5 KiB
TypeScript
87 lines
7.5 KiB
TypeScript
import { test, expect } from '@playwright/test';
|
||
import type { Character, Snapshot } from '../client/src/generated';
|
||
|
||
test('progression and signed permanent titles render in game, account, and admin views', async ({ page, request }) => {
|
||
const errors: string[] = []; page.on('pageerror', error => errors.push(error.message));
|
||
const character: Character = {
|
||
entity: { id: 'progression-fixture', kind: 'player', name: 'Title bearer', state: 'alive', hp: 100, maxHp: 100, position: { x: 0, y: 0, z: 0 } },
|
||
inventory: { wood: 1 }, skills: { combat: 2 }, kills: 2, ack: 0, gatherAttempt: 0, hasKeystone: false,
|
||
allocatedStats: {}, pendingVitalChoices: 1, healthChoices: 0, manaChoices: 0, mana: 50, stamina: 105, carryWeight: 3,
|
||
stats: { strength: { base: 2, flat: 2, percent: 50, final: 6 }, healthPoints: { base: 100, flat: 0, percent: 0, final: 100 }, manaPoints: { base: 50, flat: 0, percent: 0, final: 50 }, stamina: { base: 105, flat: 0, percent: 0, final: 105 }, carryCapacity: { base: 130, flat: 0, percent: 0, final: 130 } },
|
||
equipment: {}, items: [{ id: 'ring-fixture', definitionId: 'ring-trial', name: 'Trial Ring', description: 'An earned tool.', slot: 'ring', weight: 2, requirements: { level: 1, stats: {}, titles: [] }, modifiers: [{ stat: 'luck', flat: 2, percent: -5 }], equippable: true, requirementMessage: '' }],
|
||
playedSeconds: 120, remainingSeconds: 7080, level: 2, experience: 40, experienceToNextLevel: 150, statPoints: 5,
|
||
titles: [{ id: 'first-hunter-fixture', name: 'The First Hunter', description: 'Power comes with a heavier step.', scope: 'global', worldId: 'e2e', earnedAt: '2026-09-06T12:00:00Z', effects: { damage: 3, moveSpeed: -0.5, modifiers: [{ stat: 'strength', flat: 2, percent: 50 }] } }],
|
||
};
|
||
const record = { id: character.entity.id, account: 'fixture-account', worldId: 'e2e', name: character.entity.name, state: 'alive', character: { view: character, bornAt: '2026-09-06T11:00:00Z', dailySeconds: 120 } };
|
||
const worlds = await (await request.get('/api/worlds')).json();
|
||
const chunks = await (await request.get('/worlds/e2e/api/preview')).json();
|
||
await page.route('**/api/me', route => route.fulfill({ json: { character } }));
|
||
await page.route('**/api/account', route => route.fulfill({ json: { active: record, characters: [record], admin: true } }));
|
||
await page.route('**/api/control?*', route => route.fulfill({ json: { worlds, characters: [record], commands: [], provisioningEnabled: false, characterLimit: 500, auditLimit: 100 } }));
|
||
let sendSnapshot: () => void = () => {};
|
||
const intents: { op: string; target: string; slot: string }[] = [];
|
||
const itemActions: { op: string; item: string; slot: string }[] = [];
|
||
await page.route('**/api/item-action', route => { itemActions.push(route.request().postDataJSON()); route.fulfill({ json: { id: 'item-action-fixture', message: 'Equipped Trial Ring.', returned: {} } }); });
|
||
await page.routeWebSocket('**/ws', socket => {
|
||
socket.onMessage(raw => { const intent = JSON.parse(String(raw)); if (intent.op !== 'move') intents.push(intent); });
|
||
sendSnapshot = () => {
|
||
const snapshot: Snapshot = { type: 'snapshot', version: 1, tick: 1, self: character, chunks, chunkKeys: chunks.map(c => c.key), entities: [], unavailableResources: [], message: '',
|
||
world: { id: 'e2e', seed: 1, phase: 'gathering', ageSeconds: 120, bossInSeconds: 3600, collapseInSeconds: 5400, safeRadius: 1024, radius: 1024, online: 1, capacity: 100, bossHp: 1200, bossMaxHp: 1200 } };
|
||
socket.send(JSON.stringify(snapshot));
|
||
};
|
||
sendSnapshot();
|
||
});
|
||
await page.setViewportSize({ width: 1440, height: 900 });
|
||
await page.goto('/game?world=e2e');
|
||
await expect(page.locator('#character-level')).toHaveText('Level 2');
|
||
await expect(page.locator('#character-experience')).toHaveText('40 / 150 XP');
|
||
await expect(page.locator('#stat-point-bank')).toHaveText('5 stat points saved');
|
||
await page.getByRole('button', { name: 'Inventory and crafting' }).click();
|
||
await page.getByRole('button', { name: 'Trial Ring × 1', exact: true }).click();
|
||
await page.getByLabel('Ring slot for Trial Ring').selectOption('ring8');
|
||
sendSnapshot();
|
||
await expect(page.getByLabel('Ring slot for Trial Ring')).toHaveValue('ring8');
|
||
await page.locator('[data-focus-key="equip-ring-fixture"]').click();
|
||
await expect.poll(() => itemActions.at(-1)).toMatchObject({ op: 'equip', item: 'ring-fixture', slot: 'ring8' });
|
||
character.equipment.ring8 = 'ring-fixture'; sendSnapshot();
|
||
await page.getByRole('navigation', { name: 'Character menus' }).getByRole('button', { name: 'Equipment', exact: true }).click();
|
||
await expect(page.locator('.equipment-slot')).toHaveCount(21);
|
||
await page.locator('[data-focus-key="unequip-ring8"]').click();
|
||
await expect.poll(() => intents.at(-1)).toMatchObject({ op: 'unequip', target: 'ring8' });
|
||
await page.getByRole('navigation', { name: 'Character menus' }).getByRole('button', { name: 'Character', exact: true }).click();
|
||
await page.getByRole('button', { name: 'Allocate one point to Constitution' }).click();
|
||
await expect.poll(() => intents.at(-1)).toMatchObject({ op: 'allocate-stat', target: 'constitution' });
|
||
await page.getByRole('button', { name: '+5 mana', exact: true }).click();
|
||
await expect.poll(() => intents.at(-1)).toMatchObject({ op: 'choose-vital', target: 'mana' });
|
||
await page.getByText('Inspect all stats', { exact: true }).click();
|
||
await expect(page.locator('.stat-table tbody tr').filter({ hasText: 'Strength' })).toContainText('50%');
|
||
await page.getByText('Titles (1)', { exact: true }).click();
|
||
await expect(page.locator('#inventory .title-list')).toContainText('+3 damage');
|
||
await expect(page.locator('#inventory .title-list')).toContainText('-0.5 movement speed');
|
||
await expect(page.locator('#inventory .title-list')).toContainText('First ever');
|
||
await page.screenshot({ path: 'test-results/progression-desktop.png' });
|
||
await page.setViewportSize({ width: 390, height: 844 });
|
||
expect(await page.evaluate(() => document.documentElement.scrollWidth <= innerWidth)).toBe(true);
|
||
await expect(page.locator('#inventory .title-list .earned-title')).toBeVisible();
|
||
await page.screenshot({ path: 'test-results/progression-mobile.png' });
|
||
character.level = 1000; character.experience = 0; character.experienceToNextLevel = 0; character.statPoints = 4995;
|
||
sendSnapshot();
|
||
await expect(page.locator('#character-experience')).toHaveText('Level cap');
|
||
await expect(page.locator('#experience-meter')).toHaveAttribute('aria-valuetext', 'Level 1000: Level cap');
|
||
await page.goto('/');
|
||
await expect(page.locator('#active-character')).toContainText('4995 stat points saved');
|
||
await expect(page.locator('#active-character')).toContainText('-0.5 movement speed');
|
||
expect(await page.evaluate(() => document.documentElement.scrollWidth <= innerWidth)).toBe(true);
|
||
await page.setViewportSize({ width: 1440, height: 1000 });
|
||
await page.goto('/control');
|
||
await page.getByRole('button', { name: 'Characters', exact: true }).click();
|
||
await page.getByRole('button', { name: 'Title bearer', exact: true }).click();
|
||
await expect(page.locator('#character-detail')).toContainText('Level 1000');
|
||
await expect(page.locator('#character-detail')).toContainText('+3 damage');
|
||
await expect(page.locator('#character-detail')).toContainText('-0.5 movement speed');
|
||
await expect(page.locator('#character-detail .stat-table tbody tr').filter({ hasText: 'Strength' })).toHaveText('Strength2+2+50%6');
|
||
await expect(page.locator('#character-detail')).toContainText('Trial Ring');
|
||
await page.screenshot({ path: 'test-results/progression-control.png' });
|
||
expect(errors).toEqual([]);
|
||
});
|