treker-po-trenirovkam-i-pit.../tests/browser/russian-auth.spec.js

39 lines
3.1 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

const { test, expect } = require('@playwright/test');
const fs = require('node:fs');
const translations = require('../../profile/i18n.json');
test.use({ locale: 'en-US', viewport: { width: 360, height: 740 } });
async function capture(page, name) {
fs.mkdirSync('docs/screens', { recursive: true });
fs.writeFileSync(`docs/screens/tptip-56-${name}.txt`, await page.locator('body').innerText());
await page.screenshot({ path: `docs/screens/tptip-56-${name}.png`, fullPage: true });
}
test('Первое открытие: русские вход, регистрация и варианты выбора; явный EN сохраняется', async ({ page }) => {
await page.goto('/');
await expect(page.locator('select.lang')).toHaveValue('ru');
await expect(page.getByRole('heading', { name: 'Войдите в свой профиль' })).toBeVisible();
for (const key of ['username', 'password']) {
await expect(page.locator(`#field-${key}-hint`)).toHaveText(translations.ru[key + 'Hint']);
}
await capture(page, 'login-ru');
await page.getByRole('button', { name: 'Создать аккаунт', exact: true }).click();
await expect(page.getByRole('heading', { name: 'Создайте учётную запись' })).toBeVisible();
for (const [key, label] of Object.entries({ username: 'Имя пользователя', password: 'Пароль', height: 'Рост (см)', weight: 'Вес (кг)', age: 'Возраст (лет)', sex: 'Пол для расчёта', activity: 'Активность' })) {
await expect(page.locator(`#field-${key}`)).toBeVisible();
expect(await page.locator(`label[for="field-${key}"]`).evaluate(node => node.firstChild.textContent)).toBe(label);
if (key !== 'activity') await expect(page.locator(`#field-${key}-hint`)).toHaveText(translations.ru[key + 'Hint']);
}
await expect(page.locator('#field-sex option')).toHaveText(['Выберите пол', 'Мужской', 'Женский']);
await expect(page.locator('#field-activity option')).toHaveText(['Выберите уровень активности', 'Преимущественно сидячая', 'Лёгкая: занятия 1–3 раза в неделю', 'Средняя: занятия 3–5 раз в неделю', 'Высокая: занятия 6–7 раз в неделю']);
await expect(page.getByRole('button', { name: 'Создать учётную запись', exact: true })).toBeVisible();
await capture(page, 'register-ru');
await page.locator('select.lang').selectOption('en');
await expect(page.getByRole('heading', { name: 'Create your account' })).toBeVisible();
await expect(page.locator('#field-sex option')).toHaveText(['Select your sex', 'Male', 'Female']);
await expect(page.locator('#field-activity option')).toHaveText(['Select your activity level', 'Mostly sitting', 'Light: exercise 1–3 times weekly', 'Moderate: exercise 3–5 times weekly', 'High: exercise 6–7 times weekly']);
await page.reload();
await expect(page.locator('select.lang')).toHaveValue('en');
await expect(page.getByRole('heading', { name: 'Sign in to your profile' })).toBeVisible();
});