const { test, expect } = require('@playwright/test');
const { ADMIN_EMAIL, ADMIN_PASSWORD, localized } = require('./helpers');

test('login page rejects invalid credentials', async ({ page }) => {
  await page.goto('/login');
  await page.locator('#email').fill(ADMIN_EMAIL);
  await page.locator('#password').fill('wrong-password');
  await page.locator('.btn-signin').click();
  await expect(page.locator('#login-error')).toBeVisible();
});

test('login page signs in and redirects to operations', async ({ page }) => {
  await page.goto('/login');
  await page.locator('#email').fill(ADMIN_EMAIL);
  await page.locator('#password').fill(ADMIN_PASSWORD);
  await page.locator('.btn-signin').click();
  await expect(page).toHaveURL(/\/$/);
  await expect(page.locator('.page-title, .page-heading').first()).toHaveText(localized('Operations', 'Операции'));
});
