95 lines
3.9 KiB
JavaScript
95 lines
3.9 KiB
JavaScript
const { test, expect } = require('@playwright/test');
|
|
const { join } = require('node:path');
|
|
const translations = require('../../profile/i18n.json');
|
|
|
|
const measurements = [
|
|
{ key: 'height', valid: '182', invalid: '5' },
|
|
{ key: 'weight', valid: '81.5', invalid: '900' },
|
|
{ key: 'age', valid: '32', invalid: '101' },
|
|
];
|
|
|
|
test.use({ viewport: { width: 860, height: 1000 } });
|
|
|
|
async function openRegistration(page, lang) {
|
|
await page.goto('/?lang=' + lang);
|
|
await page.getByRole('button', { name: translations[lang].welcomeNext, exact: true }).click();
|
|
const form = page.locator('form');
|
|
await expect(form.getByRole('button', { name: translations[lang].register, exact: true })).toBeVisible();
|
|
return form;
|
|
}
|
|
|
|
async function capture(page, scenario) {
|
|
if (process.env.TPTIP_77_SCREENSHOTS) {
|
|
await page.screenshot({
|
|
path: join(process.env.TPTIP_77_SCREENSHOTS, 'tptip-77-' + scenario + '.png'),
|
|
fullPage: true,
|
|
});
|
|
}
|
|
}
|
|
|
|
for (const lang of ['ru', 'kk', 'en']) {
|
|
test(`После «Далее» видны измерения, запрещённые символы не вводятся, диапазоны проверяются (${lang})`, async ({ page }) => {
|
|
const copy = translations[lang];
|
|
const form = await openRegistration(page, lang);
|
|
for (const { key, valid } of measurements) {
|
|
const input = form.locator('#field-' + key);
|
|
const hint = form.locator('#field-' + key + '-hint');
|
|
await expect(hint).toBeVisible();
|
|
await expect(hint).toHaveText(copy[key + 'Hint']);
|
|
await input.fill(valid);
|
|
await input.press('a');
|
|
await expect(input).toHaveValue(valid);
|
|
await input.press('-');
|
|
await expect(input).toHaveValue(valid);
|
|
}
|
|
if (lang === 'ru') await capture(page, 'filtered-input');
|
|
|
|
for (const { key, invalid } of measurements) {
|
|
const input = form.locator('#field-' + key);
|
|
await input.fill(invalid);
|
|
await expect(input).toHaveAttribute('aria-invalid', 'true');
|
|
const error = form.locator('#field-' + key + '-error');
|
|
await expect(error).toBeVisible();
|
|
await expect(error).toHaveText(copy.errors[key]);
|
|
}
|
|
if (lang === 'ru') await capture(page, 'out-of-range');
|
|
|
|
for (const { key, valid } of measurements) {
|
|
const input = form.locator('#field-' + key);
|
|
await input.fill(valid);
|
|
await expect(input).toHaveAttribute('aria-invalid', 'false');
|
|
await expect(form.locator('#field-' + key + '-error')).toBeHidden();
|
|
}
|
|
});
|
|
}
|
|
|
|
for (const missing of ['height', 'weight']) {
|
|
test(`Регистрация блокируется, когда пустое поле ${translations.ru[missing]}`, async ({ page }) => {
|
|
const form = await openRegistration(page, 'ru');
|
|
const requests = [];
|
|
page.on('request', request => {
|
|
if (new URL(request.url()).pathname === '/api/register') requests.push(request);
|
|
});
|
|
await form.locator('#field-username').fill('demo_measurements');
|
|
await form.locator('#field-password').fill('demo-measurements-password');
|
|
await form.locator('#field-sex').selectOption('female');
|
|
await form.locator('#field-activity').selectOption('1.375');
|
|
for (const { key, valid } of measurements) {
|
|
if (key !== missing) await form.locator('#field-' + key).fill(valid);
|
|
}
|
|
|
|
await form.getByRole('button', { name: translations.ru.register, exact: true }).click();
|
|
|
|
const input = form.locator('#field-' + missing);
|
|
await expect(input).toBeFocused();
|
|
await expect(input).toHaveValue('');
|
|
await expect(input).toHaveAttribute('aria-invalid', 'true');
|
|
await expect(input).toHaveCSS('border-top-color', 'rgb(158, 40, 28)');
|
|
const error = form.locator('#field-' + missing + '-error');
|
|
await expect(error).toBeVisible();
|
|
await expect(error).toHaveText(translations.ru.errors[missing + 'Required']);
|
|
expect(requests).toHaveLength(0);
|
|
await capture(page, 'empty-' + missing);
|
|
});
|
|
}
|