import { test, expect } from '@playwright/test';

test('home page loads correctly', async ({ page }) => {
  await page.goto('/');

  await expect(page).toHaveTitle(/Casino/);
  await expect(page.getByRole('heading', { name: 'Willkommensbonus' })).toBeVisible();
  await expect(page.getByText('von bis zu €')).toBeVisible();
});

test('registration popup should open and close', async ({ page }) => {
  await page.goto('/');
  await page.getByRole('navigation').getByRole('button', { name: 'Jetzt registrieren' }).click();

  await expect(page.getByText('Konto erstellenE-')).toBeVisible();

  await page.getByRole('button', { name: 'Dialog schließen' }).click();

  await expect(page.getByText('Konto erstellenE-')).not.toBeVisible();
});

test('registration should work', async ({ page }) => {
  await page.goto('/');
  await page.getByRole('navigation').getByRole('button', { name: 'Jetzt registrieren' }).click();

  await page.getByRole('textbox', { name: 'E-Mail' }).fill('test@kjan.email');
  await page.getByRole('textbox', { name: 'Benutzername' }).fill('test-playwright');
  await page.getByRole('textbox', { name: 'Passwort' }).fill('BananaMan123');
  await page.locator('form').getByRole('button', { name: 'Registrieren' }).click();
  await page.getByRole('button', { name: 'Dialog schließen' }).click();
  await page.getByRole('navigation').getByRole('button', { name: 'Anmelden' }).click();
  await page.getByRole('textbox', { name: 'Benutzername oder E-Mail' }).fill('test@kjan.email');
  await page.getByRole('textbox', { name: 'Passwort' }).fill('BananaMan123');
  await page.locator('form').getByRole('button', { name: 'Anmelden' }).click();
  await expect(page.getByText('Email not verified')).toBeVisible();
});
