treker-po-trenirovkam-i-pit.../tests/browser/russian-registration.spec.js
Peppa c56104aa1f
All checks were successful
peppa/lint lint: success за 1с
peppa/test test: success за 1с
peppa/build build: success за 0с
ci / checks (pull_request) Successful in 24s
deploy / deploy (pull_request) Successful in 30s
TPTIP-78: уточнить действия входа и регистрации
2026-11-19 14:37:46 +05:00

55 lines
4.0 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: 640 } });
async function openRegistration(page) {
await page.goto('/');
await page.locator('[data-welcome-register]').click();
}
test('Регистрация через «Создать аккаунт»: русский текст и переключатель справа сверху', async ({ page }) => {
await openRegistration(page);
await expect(page.locator('html')).toHaveAttribute('lang', 'ru');
await expect(page.locator('.eyebrow')).toHaveText('ВАШ ЛИЧНЫЙ ПРОФИЛЬ');
await expect(page.getByRole('heading', { name: 'Создайте учётную запись' })).toBeVisible();
const language = page.getByRole('combobox', { name: 'Язык', exact: true });
await expect(language).toHaveValue('ru');
const [switcher, brand] = await Promise.all([language.boundingBox(), page.locator('.eyebrow').boundingBox()]);
expect(switcher.x).toBeGreaterThan(brand.x + brand.width);
expect(switcher.y).toBeLessThan(50);
expect(switcher.x + switcher.width).toBeLessThanOrEqual(360);
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 expect(page.getByRole('button', { name: 'Уже есть учётная запись? Войти', exact: true })).toBeVisible();
const text = await page.locator('body').innerText();
expect(text).not.toContain('YOUR PERSONAL PROFILE');
expect(await page.evaluate(() => document.documentElement.scrollWidth)).toBeLessThanOrEqual(360);
fs.mkdirSync('docs/screens', { recursive: true });
fs.writeFileSync('docs/screens/tptip-57-registration-ru.txt', text);
await page.screenshot({ path: 'docs/screens/tptip-57-registration-ru.png', fullPage: true });
});
test('Выбранные EN и RU сохраняются для регистрации в новой вкладке без lang', async ({ page, context }) => {
await openRegistration(page);
for (const code of ['en', 'ru']) {
await page.locator('select.lang').selectOption(code);
const next = await context.newPage();
await openRegistration(next);
expect(new URL(next.url()).search).toBe('');
await expect(next.locator('select.lang')).toHaveValue(code);
await expect(next.locator('.eyebrow')).toHaveText(code === 'en' ? 'YOUR PERSONAL PROFILE' : 'ВАШ ЛИЧНЫЙ ПРОФИЛЬ');
await expect(next.locator('h1')).toHaveText(code === 'en' ? 'Create your account' : 'Создайте учётную запись');
await expect(next.locator('#field-sex option').first()).toHaveText(code === 'en' ? 'Select your sex' : 'Выберите пол');
await expect(next.locator('#field-activity option').first()).toHaveText(code === 'en' ? 'Select your activity level' : 'Выберите уровень активности');
await next.close();
}
});