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'); });