57 lines
2.8 KiB
JavaScript
57 lines
2.8 KiB
JavaScript
const { test, expect } = require('@playwright/test');
|
||
const translations = require('../../profile/i18n.json');
|
||
|
||
test.use({ viewport: { width: 360, height: 640 }, isMobile: true, hasTouch: true });
|
||
|
||
for (const lang of ['ru', 'kk', 'en']) {
|
||
test(`Расчёт меню и плана с приветствия (${lang})`, async ({ page }) => {
|
||
const text = translations[lang];
|
||
const writes = [];
|
||
page.on('request', request => {
|
||
if (request.method() !== 'GET') writes.push(request.url());
|
||
});
|
||
await page.goto('/?lang=' + lang);
|
||
const open = page.getByRole('button', { name: text.createGoalPlan, exact: true });
|
||
await expect(open).toBeInViewport({ ratio: 1 });
|
||
await page.locator('#welcome-goal').selectOption('lose');
|
||
await open.click();
|
||
await expect(page.getByRole('heading', { level: 1 })).toHaveText(text.goalPlanHeading);
|
||
await expect(page.locator('#field-goal')).toHaveValue('lose');
|
||
await expect(page.locator('#field-password, #field-username')).toHaveCount(0);
|
||
await page.locator('#field-height').fill('175');
|
||
await page.locator('#field-weight').fill('75');
|
||
await page.locator('#field-age').fill('30');
|
||
await page.locator('#field-sex').selectOption('male');
|
||
await page.locator('#field-activity').selectOption('1.375');
|
||
await open.click();
|
||
|
||
const days = page.locator('[data-goal-plan-day]');
|
||
await expect(days).toHaveCount(4);
|
||
await expect(days.first()).toContainText(`${text.breakfast} · 458 ${text.grams}`);
|
||
await expect(days.first()).toContainText(text.goalPlanDose.replace('{sets}', '2').replace('{reps}', '10'));
|
||
await page.locator('#field-goal').selectOption('gain');
|
||
await expect(days).toHaveCount(0);
|
||
await open.click();
|
||
await expect(days.first()).toContainText(text.goalPlanDose.replace('{sets}', '4').replace('{reps}', '10'));
|
||
await expect(days.first()).not.toContainText(`${text.breakfast} · 458 ${text.grams}`);
|
||
expect(writes).toEqual([]);
|
||
expect(await page.evaluate(() => document.documentElement.scrollWidth)).toBeLessThanOrEqual(360);
|
||
|
||
await page.getByRole('button', { name: text.publicPlanBack, exact: true }).click();
|
||
await page.locator('[data-welcome-skip]').click();
|
||
await expect(open).toBeVisible();
|
||
});
|
||
}
|
||
|
||
test('Рост вне диапазона не даёт рассчитать меню и план', async ({ page }) => {
|
||
await page.goto('/?lang=ru');
|
||
const create = page.getByRole('button', { name: translations.ru.createGoalPlan, exact: true });
|
||
await create.click();
|
||
const height = page.locator('#field-height');
|
||
await height.fill('5');
|
||
await create.click();
|
||
await expect(height).toBeFocused();
|
||
await expect(page.locator('#field-height-error')).toHaveText(translations.ru.errors.height);
|
||
await expect(page.locator('[data-goal-plan-day]')).toHaveCount(0);
|
||
});
|