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

test.beforeEach('check server is up', async ({ page }) => {
  try {
    await page.goto('http://localhost:8099/dry-wash');
    const makeOrderText = page.getByText('Сделать заказ', { exact: true });
    await expect(makeOrderText).toBeVisible();
  } catch (error) {
    console.error('server not up', error);
    test.skip();
  }
});

test('login', async ({ page }) => {
  await page.goto('http://localhost:8099/dry-wash/arm');
  await page.getByRole('textbox', { name: 'Username or email' }).click();
  await page
    .getByRole('textbox', { name: 'Username or email' })
    .fill('237x237');
  await page.getByRole('textbox', { name: 'Password' }).click();
  await page.getByRole('textbox', { name: 'Password' }).fill('');
  await page.getByRole('button', { name: 'Sign In' }).click();
  await page.getByRole('heading', { name: 'Заказы' }).click();
  await page.getByRole('link', { name: 'Мастера' }).click();
  await page.getByRole('link', { name: 'Заказы' }).click();
});
