treker-po-trenirovkam-i-pit.../tests/browser/profile-validation.spec.js
Peppa ec25250c19
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 12s
deploy / deploy (pull_request) Successful in 19s
TPTIP-49: показать диапазоны и ошибки измерений рядом с полями
2026-11-17 16:17:33 +05:00

70 lines
3.6 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');
test.use({ viewport: { width: 375, height: 812 }, locale: 'ru-RU' });
async function registration(page) {
await page.goto('/?lang=ru');
await page.getByRole('button', { name: 'Создать учётную запись', exact: true }).click();
}
test('Пустые измерения: ошибки у всех полей и запрет регистрации', async ({ page }) => {
let registrations = 0;
page.on('request', r => { if (r.url().endsWith('/api/register')) registrations++; });
await registration(page);
await page.getByRole('button', { name: 'Создать учётную запись', exact: true }).click();
for (const key of ['height', 'weight', 'age']) {
await expect(page.locator(`#field-${key}-hint`)).toBeVisible();
await expect(page.locator(`#field-${key}-error`)).toContainText('не заполнен');
await expect(page.locator(`#field-${key}`)).toHaveAttribute('aria-invalid', 'true');
}
expect(registrations).toBe(0);
await page.screenshot({ path: 'docs/screens/tptip-49-empty.png', fullPage: true });
});
test('Неверные измерения и исправление, буквы не принимаются', async ({ page }) => {
await registration(page);
for (const [key, bad, good, range] of [['height', '99', '182', '100 до 250'], ['weight', '-1', '81.5', '25 до 350'], ['age', '20.5', '32', '18 до 100']]) {
const input = page.locator(`#field-${key}`);
await input.fill(bad);
await input.blur();
await expect(page.locator(`#field-${key}-error`)).toContainText(range);
await input.fill(good);
await expect(page.locator(`#field-${key}-error`)).toBeHidden();
}
const input = page.locator('#field-height');
await input.fill('');
await input.pressSequentially('abc');
await expect(input).toHaveValue('');
await input.fill('251');
await expect(page.locator('#field-height-error')).toBeVisible();
await page.screenshot({ path: 'docs/screens/tptip-49-range.png', fullPage: true });
});
for (const lang of ['ru', 'kk', 'en']) {
test(`Диапазоны и допустимые границы (${lang})`, async ({ page }) => {
await page.goto('/?lang=' + lang);
for (const key of ['height', 'weight', 'age']) await expect(page.locator(`#field-${key}-hint`)).toBeVisible();
for (const [key, min, max] of [['height', '100', '250'], ['weight', '25', '350'], ['age', '18', '100']]) {
for (const value of [min, max]) {
await page.locator(`#field-${key}`).fill(value);
await page.locator(`#field-${key}`).blur();
await expect(page.locator(`#field-${key}-error`)).toBeHidden();
}
}
expect(await page.evaluate(() => document.documentElement.scrollWidth)).toBeLessThanOrEqual(375);
});
}
test('Допустимые измерения: успешная регистрация и сохранение', async ({ page }) => {
await registration(page);
await page.locator('#field-username').fill('validation_' + Date.now());
await page.locator('#field-password').fill('private-validation-password');
for (const [key, value] of [['height', '182'], ['weight', '81.5'], ['age', '32']]) await page.locator(`#field-${key}`).fill(value);
await page.locator('#field-sex').selectOption('female');
await page.locator('#field-activity').selectOption('1.375');
await page.getByRole('button', { name: 'Создать учётную запись', exact: true }).click();
await expect(page.getByRole('heading', { name: 'Ваш профиль', exact: true })).toBeVisible();
await page.reload();
await expect(page.locator('#field-weight')).toHaveValue('81.5');
});