Files
ttrpg_manager/e2e/fixes.spec.ts
T
NilsBriggen 04fa90e580 Proper guided character builder + level-up wizard
The bare name/class/level form left new characters as shells (1 HP, all-10
abilities, no proficiencies). Now creation and level-up are guided and auto-populate.

- Hand-authored progression tables (no SRD class/slot data exists on disk):
  src/lib/rules/{dnd5e,pf2e}/progression.ts — core classes' hit die/HP, key
  abilities, save & perception proficiencies, trained-skill counts, caster type;
  5e full/half/pact spell-slot tables, pf2e slot approximation; ASI/boost/skill
  schedules.
- src/lib/rules/progression.ts: getClassDefs/getClassDef, classSkillChoices/Count,
  buildCharacter() (HP from hit die + CON over levels, trained saves/skills, spell
  slots + ability), planLevelUp() (HP gain, new slots, ASI/boost/skill choices),
  applyIncreases/bumpRank. Pure + 12 unit tests.
- Multi-step CreationWizard (Basics → Abilities → Skills → Review) replaces the
  old form; pulls PF2e ancestry HP/speed from the bestiary; review previews HP/AC/
  saves/skills/slots; lands on a ready-to-play sheet.
- LevelUpModal reworked into a guided wizard: auto HP + spell slots, presents the
  level's actual choices (5e ASI/feat, pf2e ability boosts + skill increase) and
  applies them; keeps the strategic build-route advisor.

e2e helper drives the wizard; updated 7 specs to the new flow; new character-wizard
spec asserts a complete level-3 Wizard (HP 17, slots 4xL1 2xL2).

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-06-08 09:55:48 +02:00

91 lines
4.0 KiB
TypeScript

import { test, expect } from '@playwright/test';
import { createCharacter } from './helpers';
test.beforeEach(async ({ page }) => {
await page.goto('/');
await page.evaluate(async () => {
indexedDB.deleteDatabase('ttrpg-manager');
localStorage.clear();
});
await page.reload();
});
async function makeCampaign(page: import('@playwright/test').Page, name: string) {
await page.getByRole('button', { name: '+ New campaign' }).first().click();
await page.locator('input[data-autofocus]').fill(name);
await page.getByRole('button', { name: 'Create' }).click();
}
test('combat HP damage button reduces hit points', async ({ page }) => {
await makeCampaign(page, 'Combat Test');
await page.getByRole('link', { name: 'Combat' }).click();
await page.getByRole('button', { name: '+ New encounter' }).first().click();
await page.locator('input[data-autofocus]').fill('Fight');
await page.getByRole('button', { name: 'Create' }).click();
await page.getByLabel('Name').fill('Goblin');
await page.getByRole('button', { name: 'Add', exact: true }).click();
await expect(page.getByText('10/10')).toBeVisible();
// Enter 4 damage and apply
await page.getByLabel('Goblin HP amount').fill('4');
await page.getByRole('button', { name: 'Dmg' }).click();
await expect(page.getByText('6/10')).toBeVisible();
// Heal 2 back
await page.getByLabel('Goblin HP amount').fill('2');
await page.getByRole('button', { name: 'Heal' }).click();
await expect(page.getByText('8/10')).toBeVisible();
});
test('combat condition picker adds preset and valued conditions as tags', async ({ page }) => {
await makeCampaign(page, 'Conditions');
await page.getByRole('link', { name: 'Combat' }).click();
await page.getByRole('button', { name: '+ New encounter' }).first().click();
await page.locator('input[data-autofocus]').fill('Fight');
await page.getByRole('button', { name: 'Create' }).click();
await page.getByLabel('Name').fill('Goblin');
await page.getByRole('button', { name: 'Add', exact: true }).click();
const row = page.locator('li', { hasText: 'Goblin' });
// Non-valued condition adds immediately on selection
await row.getByLabel('Add condition').selectOption('Prone');
await expect(row.getByRole('button', { name: /Prone/ })).toBeVisible();
// Valued condition (5e Exhaustion) shows a value field, then adds a tag
await row.getByLabel('Add condition').selectOption('Exhaustion');
await row.getByLabel('Condition value').fill('3');
await row.getByRole('button', { name: 'Add', exact: true }).click();
await expect(row.getByRole('button', { name: /Exhaustion 3/ })).toBeVisible();
// Clicking a tag removes it
await row.getByRole('button', { name: /Prone/ }).click();
await expect(row.getByRole('button', { name: /Prone/ })).toHaveCount(0);
});
test('character can be deleted', async ({ page }) => {
await makeCampaign(page, 'Delete Test');
await page.getByRole('link', { name: 'Characters' }).click();
await createCharacter(page, 'Doomed'); // lands on the sheet
await page.getByLabel('Primary').getByRole('link', { name: 'Characters' }).click();
await expect(page.getByRole('heading', { name: 'Doomed' })).toBeVisible();
await page.getByRole('button', { name: 'Delete' }).click();
await page.getByRole('button', { name: 'Delete', exact: true }).last().click();
await expect(page.getByRole('heading', { name: 'Doomed' })).toHaveCount(0);
});
test('compendium CR filter narrows the bestiary', async ({ page }) => {
await makeCampaign(page, 'Filter Test');
await page.getByRole('link', { name: 'Compendium' }).click();
await expect(page.getByText(/results/)).toBeVisible();
const countText = async () => (await page.getByText(/results/).textContent()) ?? '';
const before = parseInt((await countText()).replace(/\D/g, ''), 10);
await page.getByLabel('Min CR').selectOption({ label: 'CR ≥ 10' });
// wait for the count to update
await expect.poll(async () => parseInt((await countText()).replace(/\D/g, ''), 10)).toBeLessThan(before);
});