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();
});

test('generate ability scores and level up', async ({ page }) => {
  await page.getByRole('button', { name: '+ New campaign' }).first().click();
  await page.locator('input[data-autofocus]').fill('Build');
  await page.getByRole('button', { name: 'Create' }).click();
  await page.getByRole('link', { name: 'Characters' }).click();
  // Guided wizard builds a complete level-1 character (standard array → STR 15).
  await createCharacter(page, 'Builder');
  await expect(page.getByLabel('STR score')).toHaveValue('15');

  // Guided level-up from 1 -> 2 (HP + any choices applied automatically)
  await page.getByRole('button', { name: 'Level up' }).click();
  await page.getByRole('button', { name: /Apply level 2/ }).click();
  await expect(page.getByRole('spinbutton', { name: 'Level', exact: true })).toHaveValue('2');
});
