treker-po-trenirovkam-i-pit.../tests/browser/auth-guidance.spec.js

33 lines
1.9 KiB
JavaScript

const { test, expect } = require('@playwright/test');
const fs = require('node:fs');
const translations = require('../../profile/i18n.json');
test.use({ viewport: { width: 360, height: 640 } });
for (const lang of ['ru', 'kk', 'en']) {
test(`Вход на телефоне и переход к регистрации (${lang})`, async ({ page }) => {
await page.addInitScript(() => sessionStorage.setItem('tpt.welcomeSeen', '1'));
await page.goto('/?lang=' + lang);
const t = translations[lang];
await expect(page.locator('[data-auth-guidance]')).toHaveText(t.authGuidance);
await expect(page.locator('form input')).toHaveCount(2);
await expect(page.locator('#field-height,#field-weight,#field-age')).toHaveCount(0);
for (const name of [t.login, t.toRegister]) {
const box = await page.getByRole('button', { name, exact: true }).boundingBox();
expect(box.y).toBeGreaterThanOrEqual(0);
expect(box.y + box.height).toBeLessThanOrEqual(640);
expect(box.x + box.width).toBeLessThanOrEqual(360);
}
fs.writeFileSync(`docs/screens/tptip-59-${lang}-texts.txt`, await page.locator('main').innerText());
await page.screenshot({ path: `docs/screens/tptip-59-login-${lang}.png`, fullPage: true });
await page.getByRole('button', { name: t.toRegister, exact: true }).click();
await expect(page.locator('[data-auth-guidance]')).toHaveText(t.authGuidance);
for (const name of ['height', 'weight', 'age']) await expect(page.locator('#field-' + name)).toHaveAttribute('required', '');
for (const name of [t.register, t.toLogin]) {
const box = await page.getByRole('button', { name, exact: true }).boundingBox();
expect(box.y + box.height).toBeLessThanOrEqual(640);
}
await page.getByRole('button', { name: t.register, exact: true }).click();
await expect(page.locator('#field-height-error')).toBeVisible();
await expect(page.getByRole('heading', { name: t.registerHeading })).toBeVisible();
});
}