treker-po-trenirovkam-i-pit.../tests/browser/home.spec.js
Peppa 415111d418
All checks were successful
peppa/lint lint: success за 1с
peppa/test test: success за 1с
peppa/build build: success за 1с
ci / checks (pull_request) Successful in 9s
deploy / deploy (pull_request) Successful in 25s
TPTIP-4: сохранить калькулятор после пропуска статического мастера
2026-11-17 12:34:56 +05:00

69 lines
4.5 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.

// TPTIP-33: главный экран на телефоне 375 px сразу после мастера.
const { test, expect } = require('@playwright/test');
test.use({ baseURL: 'http://127.0.0.1:3094', viewport: { width: 375, height: 740 }, locale: 'ru-RU' });
async function passWizard(page) {
await page.goto('/');
await page.locator('.sheet select').first().selectOption('m');
await page.locator('.sheet select').last().selectOption('1.375');
const fields = page.locator('.sheet input');
for (const [i, value] of ['40', '170', '65'].entries()) await fields.nth(i).fill(value);
await page.getByRole('button', { name: 'Далее', exact: true }).click();
await page.getByRole('button', { name: 'Готово', exact: true }).click();
await expect(page.locator('.sheet')).toHaveCount(0);
}
test('Сценарий: Узкий экран после мастера — пять колец одинаковой ширины, под каждым название и «съедено из нормы»', async ({ page }) => {
await passWizard(page);
const rings = page.locator('.rings .ring');
await expect(rings).toHaveCount(5);
const expected = [['Калории', '0 из 2087', 'килокалории'], ['Белки', '0 из 117', 'граммы'], ['Жиры', '0 из 58', 'граммы'], ['Углеводы', '0 из 274', 'граммы'], ['Вода', '0 из 1950', 'миллилитры']];
const boxes = [];
for (const [i, [name, amount, unit]] of expected.entries()) {
const ring = rings.nth(i), label = ring.locator('.t');
await expect(label.locator('b')).toHaveText(name);
await expect(label.locator('[data-amount]')).toHaveText(amount);
await expect(label.locator('small')).toHaveText(unit);
for (const part of ['b', '[data-amount]']) expect(await label.locator(part).evaluate(e => e.getClientRects().length === 1 && e.getBoundingClientRect().height < parseFloat(getComputedStyle(e).fontSize) * 1.7), name + ': «' + part + '» в одну строку').toBe(true);
const ringBox = await ring.locator('svg').boundingBox(), labelBox = await label.boundingBox();
expect(labelBox.y, name + ': подпись под кольцом').toBeGreaterThanOrEqual(ringBox.y + ringBox.height - 1);
boxes.push(ringBox);
}
for (const b of boxes) {
expect(Math.abs(b.width - boxes[0].width), 'кольца одинаковой ширины').toBeLessThan(1);
expect(Math.abs(b.y - boxes[0].y), 'кольца в один ряд').toBeLessThan(1);
}
expect(await page.evaluate(() => document.documentElement.scrollWidth)).toBeLessThanOrEqual(375);
});
test('Сценарий: Длинный состав на узком экране — время, порция и КБЖУ на отдельных строках, состав целиком', async ({ page }) => {
await passWizard(page);
const card = page.locator('.item.dish').first();
await card.scrollIntoViewIfNeeded();
const rows = ['[data-time]', '[data-portion]', '[data-macros]'];
const ys = [];
for (const sel of rows) { await expect(card.locator(sel)).toBeVisible(); ys.push((await card.locator(sel).boundingBox()).y); }
expect(ys[1]).toBeGreaterThan(ys[0]);
expect(ys[2]).toBeGreaterThan(ys[1]);
await expect(card.locator('[data-macros]')).toHaveText(/^\d+ ккал · Б \S+ · Ж \S+ · У \S+$/);
const cardBox = await card.boundingBox();
for (const li of await card.locator('[data-ingredients] li').all()) {
const b = await li.boundingBox();
expect(b.x + b.width, 'строка состава не выходит за карточку').toBeLessThanOrEqual(cardBox.x + cardBox.width + 1);
expect(await li.evaluate(e => e.scrollWidth <= e.clientWidth)).toBe(true);
}
const body = await card.locator('.dish-body').boundingBox(), photo = await card.locator('.recipe-photo, [data-photo-placeholder]').first().boundingBox();
expect(body.y, 'состав под фото').toBeGreaterThanOrEqual(photo.y + photo.height - 1);
});
test('Сценарий: Прокрутка до конца — последняя карточка «Серия» видна целиком над нижним меню', async ({ page }) => {
await passWizard(page);
await page.evaluate(() => window.scrollTo(0, document.documentElement.scrollHeight));
const last = page.locator('#view .card').last();
await expect(last).toContainText('Серия');
const card = await last.boundingBox(), tabs = await page.locator('#tabs').boundingBox();
expect(card.y).toBeGreaterThanOrEqual(0);
expect(card.y + card.height).toBeLessThanOrEqual(tabs.y);
});