const { test, expect } = require('@playwright/test'); const fs = require('node:fs'); const ru = require('../../profile/i18n.json').ru; test.use({ locale: 'en-US', viewport: { width: 360, height: 640 }, isMobile: true, hasTouch: true }); for (const [action, heading] of [['next', ru.registerHeading], ['skip', ru.loginHeading]]) { test(`Первый визит: русское приветствие и переход ${action}`, async ({ page }) => { await page.goto('/'); await expect(page.locator('html')).toHaveAttribute('lang', 'ru'); await expect(page.locator('select.lang')).toHaveValue('ru'); await expect(page.locator('h1')).toHaveText('Добро пожаловать'); for (const key of ['brand', 'welcomeIntro', 'welcomeTitle', 'welcomeHint']) { await expect(page.getByText(ru[key], { exact: true })).toBeVisible(); } await expect(page.locator('label[for=welcome-goal]')).toContainText('Цель'); await expect(page.locator('#welcome-goal')).toHaveValue('maintain'); await expect(page.locator('[data-goal-note]')).toHaveText('Цель: Поддержание. Её можно поменять позже в «Настройках»'); await expect(page.locator('[data-welcome-next]')).toHaveText('Далее'); await expect(page.locator('[data-welcome-skip]')).toHaveText('Пропустить'); for (const selector of ['[data-welcome-next]', '[data-welcome-skip]']) { await expect(page.locator(selector)).toBeInViewport({ ratio: 1 }); } const visibleText = await page.locator('main').innerText(); expect(visibleText).not.toMatch(/Welcome|Skip|Next|Start with your account|YOUR PERSONAL PROFILE/); expect(await page.evaluate(() => document.documentElement.scrollWidth)).toBeLessThanOrEqual(360); expect(await page.evaluate(() => document.documentElement.scrollHeight)).toBeLessThanOrEqual(640); if (action === 'next') { await page.screenshot({ path: 'docs/screens/tptip-68-welcome-ru.png' }); fs.writeFileSync('docs/screens/tptip-68-welcome-texts.txt', visibleText + '\n'); } await page.locator(`[data-welcome-${action}]`).click(); await expect(page.locator('h1')).toHaveText(heading); await expect(page.locator('select.lang')).toHaveValue('ru'); await expect(page.locator('form input')).toHaveCount(action === 'skip' ? 2 : 5); }); }