treker-po-trenirovkam-i-pit.../tests/browser/mobile-welcome.spec.js

35 lines
1.9 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.use({ baseURL: process.env.MOCK_WELCOME_URL || 'http://127.0.0.1:3094', viewport: { width: 360, height: 640 } });
test('Первое открытие на телефоне: поля и обе кнопки целиком без прокрутки', async ({ page }) => {
await page.goto('/');
const sheet = page.locator('.sheet');
await expect(sheet).toBeVisible();
expect(await sheet.evaluate(e => e.scrollHeight <= e.clientHeight)).toBe(true);
const boxes = await sheet.locator('input, select, .chips button, .foot button').evaluateAll(nodes => nodes.map(e => {
const r = e.getBoundingClientRect();
return { x: r.x, y: r.y, right: r.right, bottom: r.bottom };
}));
for (const box of boxes) {
expect(box.x).toBeGreaterThanOrEqual(0);
expect(box.y).toBeGreaterThanOrEqual(0);
expect(box.right).toBeLessThanOrEqual(360);
expect(box.bottom).toBeLessThanOrEqual(640);
}
for (let i = 0; i < boxes.length; i++) for (let j = i + 1; j < boxes.length; j++) {
const a = boxes[i], b = boxes[j];
expect(a.right <= b.x || b.right <= a.x || a.bottom <= b.y || b.bottom <= a.y).toBe(true);
}
await page.getByRole('button', { name: 'Пропустить', exact: true }).click();
await expect(sheet).toHaveCount(0);
});
test('Ошибки пустых полей на телефоне: подсказки и действия доступны', async ({ page }) => {
await page.goto('/');
await page.getByRole('button', { name: 'Далее', exact: true }).click();
await expect(page.locator('.sheet .field.bad')).toHaveCount(3);
await expect(page.locator('.sheet input').first()).toBeFocused();
const skip = page.getByRole('button', { name: 'Пропустить', exact: true });
await skip.scrollIntoViewIfNeeded();
await skip.click();
await expect(page.locator('.sheet')).toHaveCount(0);
});