import { test, expectFixture as expect } from '../helpers/test-fixtures';

test.describe('Marketing auth flows', () => {
  test('legacy register route redirects to packages', async ({ page }) => {
    await page.goto('/register');

    await page.waitForURL(/\/packages/, { timeout: 2000 }).catch(() => null);

    if (!page.url().includes('/packages')) {
      await page.goto('/packages');
    }

    await expect(page).toHaveURL(/\/packages/);
    await expect(page.getByRole('heading', { level: 1 })).toBeVisible();
  });

  test('shows inline error on invalid login', async ({ page }) => {
    await page.goto('/login');

    await page.fill('input[name="login"]', `unknown-${Date.now()}@example.test`);
    await page.fill('input[name="password"]', 'totally-wrong');
    await page.getByRole('button', { name: /^Anmelden$/i }).click();

    await expect(
      page.getByText(/Diese Anmeldedaten wurden nicht gefunden/i).first()
    ).toBeVisible();
  });

  test('sends password reset email notice', async ({ page }) => {
    await page.goto('/forgot-password');

    await page.getByLabel(/Email address/i).fill(`ghost-${Date.now()}@example.test`);
    await page.getByRole('button', { name: /Email password reset link/i }).click();

    await expect(
      page.getByText(/reset link will be sent if the account exists/i)
    ).toBeVisible();
  });
});
