treker-po-trenirovkam-i-pit.../tests/browser/recipes.spec.js
Peppa 8abdffba01
All checks were successful
peppa/lint lint: success за 0с
peppa/test test: success за 1с
peppa/build build: success за 1с
ci / checks (pull_request) Successful in 7s
deploy / deploy (pull_request) Successful in 26s
TPTIP-4: приватный профиль и расчёт питания по введённым данным
2026-11-17 12:23:14 +05:00

53 lines
3.7 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('Три рецепта, две порции, границы и перевод без потери выбора', async ({ page }) => {
await page.goto('/recipes.html?lang=ru');
await expect(page.locator('article')).toHaveCount(3);
const oats = page.locator('[data-recipe=oats]');
await expect(oats.getByRole('button', { name: 'Меньше порций' })).toBeDisabled();
await oats.getByRole('button', { name: 'Больше порций' }).click();
await expect(oats.locator('output')).toHaveText('2');
await expect(oats.locator('.ingredients li').first()).toContainText('100 г');
await expect(oats.locator('.nutrition').first().locator('strong').first()).toHaveText('352');
await expect(oats.locator('.nutrition').nth(1).locator('strong').first()).toHaveText('704');
for (let i = 0; i < 6; i++) await oats.getByRole('button', { name: 'Больше порций' }).click();
await expect(oats.getByRole('button', { name: 'Больше порций' })).toBeDisabled();
for (const [lang, title] of [['kk', 'Күнделікті тағам рецептері'], ['en', 'Recipes for every day'], ['ru', 'Рецепты на каждый день']]) {
await page.locator('select').selectOption(lang); await expect(page.locator('h1')).toHaveText(title); await expect(oats.locator('output')).toHaveText('8');
}
for (const img of await page.locator('img').all()) expect(await img.evaluate(img => img.naturalWidth)).toBeGreaterThan(0);
});
test('Фото недоступно: состав и шаги остаются видимыми', async ({ page }) => {
await page.route('**/assets/oats.jpg', route => route.abort());
await page.goto('/recipes.html?lang=ru');
const oats = page.locator('[data-recipe=oats]');
await expect(oats.getByText('Фото блюда недоступно.', { exact: false })).toBeVisible();
await expect(oats.locator('ol li')).toHaveCount(3);
});
test('Ошибка загрузки: понятное сообщение и повторная попытка', async ({ page }) => {
await page.route('**/recipes.data.json', route => route.fulfill({ status: 503, body: '' }));
await page.goto('/recipes.html?lang=ru');
await expect(page.getByRole('alert')).toContainText('Не удалось открыть рецепты. Обновите страницу или попробуйте позже.');
await page.unroute('**/recipes.data.json');
await page.getByRole('button', { name: 'Попробовать снова' }).click();
await expect(page.locator('article')).toHaveCount(3);
});
test('Узкий экран: тексты видимы, горизонтальной прокрутки нет', async ({ page }) => {
await page.setViewportSize({ width: 375, height: 812 });
await page.goto('/recipes.html?lang=kk');
await expect(page.locator('article')).toHaveCount(3);
expect(await page.evaluate(() => document.documentElement.scrollWidth <= innerWidth)).toBeTruthy();
await page.screenshot({ path: '/tmp/tptip-3-mobile.png', fullPage: true, animations: 'disabled' });
});
test('Переход из трекера в каталог рецептов', async ({ page }) => {
const registration = await page.request.post('/api/register', {
headers: { Origin: 'http://127.0.0.1:3093' },
data: { username: 'recipes-' + Date.now(), password: 'recipes-test-password', height: 182, weight: 81, age: 32, sex: 'male', activity: 1.375 }
});
expect(registration.ok()).toBeTruthy();
await page.goto('/tracker?lang=ru');
await page.getByRole('link', { name: 'Рецепты на каждый день' }).first().click();
await expect(page.locator('article')).toHaveCount(3);
await expect(page).toHaveURL(/recipes.html/);
});