const { test, expect } = require('@playwright/test'); // Preserve the legacy static wizard checks; the private entry has its own profile flow. test.use({ baseURL: 'http://127.0.0.1:3094' }); async function secondStep(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 expect(page.locator('.sheet')).toContainText('Мы посчитали ваши дневные нормы по введённым данным'); } async function checkFinished(page, targets) { await expect(page.locator('.sheet')).toHaveCount(0); for (const [i, target] of targets.entries()) { await expect(page.locator('.ring').nth(i)).toContainText(`из ${target}`); } } test('Второй шаг: расчёт, возврат, правки всех норм и повторное открытие', async ({ page, browser }) => { await secondStep(page); const fields = page.locator('.sheet input'); // Мужчина, поддержание веса, активность 1.375: независимые ожидаемые значения. for (const [i, value] of ['2087', '117', '58', '274'].entries()) await expect(fields.nth(i)).toHaveValue(value); await page.getByRole('button', { name: 'Назад', exact: true }).click(); for (const [i, value] of ['40', '170', '65'].entries()) await expect(fields.nth(i)).toHaveValue(value); await page.getByRole('button', { name: 'Далее', exact: true }).click(); const targets = [1800, 111, 55, 222]; for (const [i, value] of targets.entries()) await fields.nth(i).fill(String(value)); await page.getByRole('button', { name: 'Готово', exact: true }).click(); await checkFinished(page, targets); await page.reload(); await checkFinished(page, targets); const context = await browser.newContext({ storageState: await page.context().storageState() }); try { const reopened = await context.newPage(); await reopened.goto('http://127.0.0.1:3094/'); await checkFinished(reopened, targets); } finally { await context.close(); } }); test('Неверная норма не завершает мастер; после исправления видны рассчитанные нормы', async ({ page }) => { await secondStep(page); await page.locator('.sheet input').first().fill('100'); await page.getByRole('button', { name: 'Готово', exact: true }).click(); await expect(page.locator('.sheet')).toContainText('Проверьте калории в день: число 100 не подходит. Введите число от 500 до 10000 ккал.'); await expect(page.locator('.sheet input').first()).toBeFocused(); await page.reload(); await expect(page.locator('.sheet')).toContainText('Шаг 1 из 2'); await secondStep(page); await page.getByRole('button', { name: 'Готово', exact: true }).click(); await checkFinished(page, [2087, 117, 58, 274]); });