Default exercises are created in selected language. Initial GUI added

This commit is contained in:
AG
2025-12-18 22:16:39 +02:00
parent 78d4a10f33
commit abffb52af1
12 changed files with 332 additions and 117 deletions

View File

@@ -12,65 +12,61 @@ test.describe('I. Core & Authentication', () => {
// Helper to handle first login if needed
async function handleFirstLogin(page: any) {
// Wait for either Free Workout (already logged in/not first time)
// OR Change Password heading
// OR Error message
try {
const heading = page.getByRole('heading', { name: /Change Password/i });
const dashboard = page.getByText('Free Workout');
const loginButton = page.getByRole('button', { name: 'Login' });
console.log('Starting handleFirstLogin helper...');
const dashboard = page.getByText(/Free Workout|Свободная тренировка/i).first();
const changePass = page.getByRole('heading', { name: /Change Password|Смена пароля/i });
const initAcc = page.getByRole('heading', { name: /Setup Your Account|Настройка аккаунта/i });
// Race condition: wait for one of these to appear
// We use a small polling or just wait logic.
// Playwright doesn't have "race" for locators easily without Promise.race
// Simple approach: Check if Change Password appears within 5s
await expect(heading).toBeVisible({ timeout: 5000 });
// If we are here, Change Password is visible
console.log('Change Password screen detected. Handling...');
await page.getByLabel('New Password').fill('StrongNewPass123!');
await page.getByRole('button', { name: /Save|Change/i }).click();
// Now expect dashboard
await expect(dashboard).toBeVisible();
console.log('Password changed. Dashboard visible.');
} catch (e) {
// If Change Password didn't appear, maybe we are already at dashboard?
if (await page.getByText('Free Workout').isVisible()) {
console.log('Already at Dashboard.');
for (let i = 0; i < 30; i++) {
if (await dashboard.isVisible()) {
console.log('Dashboard visible.');
return;
}
// Check for login error
const error = page.locator('.text-error');
if (await error.isVisible()) {
console.log('Login Error detected:', await error.textContent());
throw new Error(`Login failed: ${await error.textContent()}`);
if (await changePass.isVisible()) {
console.log('Change Password screen detected. Handling...');
await page.getByLabel(/New Password|Новый пароль/i).fill('StrongNewPass123!');
await page.getByRole('button', { name: /Save|Change|Сохранить/i }).click();
// Wait a bit for transition
await page.waitForTimeout(1000);
continue;
}
// Note: If none of the above, it might be a clean login that just worked fast or failed silently
if (await initAcc.isVisible()) {
console.log('Initialization screen detected. Handling...');
await page.getByRole('button', { name: /Get Started|Начать работу/i }).click();
// Wait a bit for transition
await page.waitForTimeout(1000);
continue;
}
await page.waitForTimeout(500);
}
// Final check with assertion to fail the test if not reached
await expect(dashboard).toBeVisible({ timeout: 5000 });
}
// 1.1. A. Login - Successful Authentication
test('1.1 Login - Successful Authentication', async ({ page, createUniqueUser }) => {
const user = await createUniqueUser();
await page.getByLabel('Email').fill(user.email);
await page.getByLabel('Password').fill(user.password);
await page.getByRole('button', { name: 'Login' }).click();
await page.getByLabel(/Email/i).fill(user.email);
await page.getByLabel(/Password|Пароль/i).fill(user.password);
await page.getByRole('button', { name: /Login|Войти/i }).click();
await handleFirstLogin(page);
// Expect redirection to dashboard
await expect(page).not.toHaveURL(/\/login/);
await expect(page.getByText('Free Workout')).toBeVisible();
await expect(page.getByText(/Free Workout|Свободная тренировка/i).first()).toBeVisible();
});
// 1.2. A. Login - Invalid Credentials
test('1.2 Login - Invalid Credentials', async ({ page }) => {
await page.getByLabel('Email').fill('invalid@user.com');
await page.getByLabel('Password').fill('wrongpassword');
await page.getByRole('button', { name: 'Login' }).click();
await page.getByLabel(/Email/i).fill('invalid@user.com');
await page.getByLabel(/Password|Пароль/i).fill('wrongpassword');
await page.getByRole('button', { name: /Login|Войти/i }).click();
await expect(page.getByText('Invalid credentials')).toBeVisible();
await expect(page.getByRole('button', { name: 'Login' })).toBeVisible();
@@ -79,31 +75,34 @@ test.describe('I. Core & Authentication', () => {
test('1.3 & 1.4 Login - First-Time Password Change', async ({ page, createUniqueUser }) => {
const user = await createUniqueUser();
await page.getByLabel('Email').fill(user.email);
await page.getByLabel('Password').fill(user.password);
await page.getByRole('button', { name: 'Login' }).click();
await page.getByLabel(/Email/i).fill(user.email);
await page.getByLabel(/Password|Пароль/i).fill(user.password);
await page.getByRole('button', { name: /Login|Войти/i }).click();
await expect(page.getByRole('heading', { name: /Change Password/i }).first()).toBeVisible({ timeout: 10000 });
await expect(page.getByRole('heading', { name: /Change Password|Смена пароля/i }).first()).toBeVisible({ timeout: 10000 });
// 1.4 Test short password
await page.getByLabel('New Password').fill('123');
await page.getByRole('button', { name: /Save|Change/i }).click();
await expect(page.getByText('Password too short')).toBeVisible();
await page.getByLabel(/New Password|Новый пароль/i).fill('123');
await page.getByRole('button', { name: /Save|Change|Сохранить/i }).click();
await expect(page.getByText(/Password too short|Пароль слишком короткий/i)).toBeVisible();
// 1.3 Test successful change
await page.getByLabel('New Password').fill('StrongNewPass123!');
await page.getByRole('button', { name: /Save|Change/i }).click();
await page.getByLabel(/New Password|Новый пароль/i).fill('StrongNewPass123!');
await page.getByRole('button', { name: /Save|Change|Сохранить/i }).click();
// Now we should be on Setup Account page
await expect(page.getByRole('heading', { name: /Setup Your Account|Настройка аккаунта/i })).toBeVisible();
await page.getByRole('button', { name: /Get Started|Начать работу/i }).click();
// Now we should be logged in
await expect(page.getByText('Free Workout')).toBeVisible();
await expect(page.getByText(/Free Workout|Свободная тренировка/i).first()).toBeVisible();
});
// 1.5. A. Login - Language Selection (English)
test('1.5 Login - Language Selection (English)', async ({ page }) => {
await page.getByRole('combobox').selectOption('en');
await expect(page.getByLabel('Email')).toBeVisible();
await expect(page.getByRole('button', { name: 'Login' })).toBeVisible();
await expect(page.getByLabel(/Email/i)).toBeVisible();
await expect(page.getByRole('button', { name: /Login|Войти/i })).toBeVisible();
});
// 1.6. A. Login - Language Selection (Russian)
@@ -116,26 +115,26 @@ test.describe('I. Core & Authentication', () => {
test('1.7 Navigation - Desktop Navigation Rail', async ({ page, createUniqueUser }) => {
const user = await createUniqueUser();
await page.getByLabel('Email').fill(user.email);
await page.getByLabel('Password').fill(user.password);
await page.getByRole('button', { name: 'Login' }).click();
await page.getByLabel(/Email/i).fill(user.email);
await page.getByLabel(/Password|Пароль/i).fill(user.password);
await page.getByRole('button', { name: /Login|Войти/i }).click();
await handleFirstLogin(page);
// Set viewport to desktop
await page.setViewportSize({ width: 1280, height: 720 });
await expect(page.getByRole('button', { name: 'Tracker' }).first()).toBeVisible();
await expect(page.getByRole('button', { name: 'Plans' }).first()).toBeVisible();
await expect(page.getByRole('button', { name: /Tracker|Трекер/i }).first()).toBeVisible();
await expect(page.getByRole('button', { name: /Plans|Планы/i }).first()).toBeVisible();
});
// 1.8. B. Navigation - Mobile Bottom Navigation Bar
test('1.8 Navigation - Mobile Bottom Navigation Bar', async ({ page, createUniqueUser }) => {
const user = await createUniqueUser();
await page.getByLabel('Email').fill(user.email);
await page.getByLabel('Password').fill(user.password);
await page.getByRole('button', { name: 'Login' }).click();
await page.getByLabel(/Email/i).fill(user.email);
await page.getByLabel(/Password|Пароль/i).fill(user.password);
await page.getByRole('button', { name: /Login|Войти/i }).click();
await handleFirstLogin(page);
@@ -145,7 +144,44 @@ test.describe('I. Core & Authentication', () => {
await page.waitForTimeout(500); // Allow layout transition
// Verify visibility of mobile nav items
await expect(page.getByRole('button', { name: 'Tracker' }).last()).toBeVisible();
await expect(page.getByRole('button', { name: /Tracker|Трекер/i }).last()).toBeVisible();
});
// 1.9. C. Initialization - Russian Language Seeding
test('1.9 Initialization - Russian Language Seeding', async ({ page, createUniqueUser }) => {
const user = await createUniqueUser();
await page.getByLabel(/Email/i).fill(user.email);
await page.getByLabel(/Password|Пароль/i).fill(user.password);
await page.getByRole('button', { name: /Login|Войти/i }).click();
// Handle password change
await expect(page.getByRole('heading', { name: /Change Password|Смена пароля/i })).toBeVisible();
await page.getByLabel(/New Password|Новый пароль/i).fill('StrongNewPass123!');
await page.getByRole('button', { name: /Save|Change|Сохранить/i }).click();
// Handle initialization - Select Russian
await expect(page.getByRole('heading', { name: /Setup Your Account|Настройка аккаунта/i })).toBeVisible();
await page.getByText('Русский').click();
await page.getByRole('button', { name: /Начать работу|Get Started/i }).click();
// Expect dashboard
await expect(page.getByText('Свободная тренировка')).toBeVisible();
// Verify some exercise is in Russian
await page.getByText(/Свободная тренировка|Free Workout/i).first().click();
await page.getByLabel(/Выберите упражнение|Select Exercise/i).click();
// "Air Squats" should be "Приседания" in suggestions
await expect(page.getByRole('button', { name: 'Приседания', exact: true })).toBeVisible();
await page.getByRole('button', { name: 'Приседания', exact: true }).click();
// Verify it's selected in the input
const exerciseInput = page.getByLabel(/Выберите упражнение|Select Exercise/i);
await expect(exerciseInput).toHaveValue('Приседания');
// Verify "Log Set" button is now in Russian
await expect(page.getByRole('button', { name: /Записать подход|Log Set/i })).toBeVisible();
});
});