treker-po-trenirovkam-i-pit.../tests/browser/language-switcher.spec.js

69 lines
4.0 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');
const translations = require('../../profile/i18n.json');
test.use({ locale: 'ru-RU', viewport: { width: 360, height: 640 } });
const cyrillic = /[А-Яа-яЁё]/;
async function toLogin(page) {
await page.locator('[data-welcome-skip], form').first().waitFor();
const skip = page.locator('[data-welcome-skip]');
if (await skip.count()) await skip.click();
}
test('Переключатель подписан и предлагает ровно RU и EN', async ({ page }) => {
await page.goto('/');
const field = page.locator('[data-language]');
await expect(field).toBeVisible();
await expect(field.locator('.lang-caption')).toHaveText(/Язык/);
await expect(page.getByRole('combobox', { name: 'Язык' })).toBeVisible();
await expect(page.locator('select.lang option')).toHaveText(['RU — Русский', 'EN — English']);
await expect(page.locator('select.lang option')).toHaveCount(2);
const box = await field.boundingBox();
expect(box.x + box.width).toBeLessThanOrEqual(360);
require('node:fs').mkdirSync('docs/screens', { recursive: true });
await page.screenshot({ path: 'docs/screens/tptip-73-switcher-ru.png' });
});
test('EN переводит вход и регистрацию без русских слов и запоминается', async ({ page, context }) => {
const en = translations.en;
await page.goto('/');
await page.locator('select.lang').selectOption('en');
await expect(page.locator('html')).toHaveAttribute('lang', 'en');
await expect(page.locator('[data-language] .lang-caption')).toHaveText(/Language/);
await expect(page.locator('select.lang option')).toHaveText(['RU — Русский', 'EN — English']);
// Только названия языков в списке пишутся на своём языке.
const visible = async () => (await page.locator('body').innerText()).replace('RU — Русский', '');
expect(await visible()).not.toMatch(cyrillic);
await toLogin(page);
await expect(page.getByRole('heading', { name: en.loginHeading })).toBeVisible();
expect(await visible()).not.toMatch(cyrillic);
await page.screenshot({ path: 'docs/screens/tptip-73-login-en.png' });
await page.getByRole('button', { name: en.toRegister, exact: true }).click();
await expect(page.getByRole('heading', { name: en.registerHeading })).toBeVisible();
expect(await visible()).not.toMatch(cyrillic);
await page.screenshot({ path: 'docs/screens/tptip-73-register-en.png', fullPage: true });
await page.reload();
await expect(page.locator('select.lang')).toHaveValue('en');
await toLogin(page);
expect(await visible()).not.toMatch(cyrillic);
const second = await context.newPage();
await second.goto('/');
await expect(second.locator('select.lang')).toHaveValue('en');
await second.locator('select.lang').selectOption('ru');
await second.reload();
await expect(second.locator('select.lang')).toHaveValue('ru');
await toLogin(second);
await expect(second.getByRole('heading', { name: translations.ru.loginHeading })).toBeVisible();
});
test('Русский вход и регистрация без английских подписей', async ({ page }) => {
await page.goto('/?lang=ru');
await toLogin(page);
const latin = async () => (await page.locator('body').innerText()).replace('EN — English', '').replace(/Peppa FACTORY/g, '');
expect(await latin()).not.toMatch(/\b[A-Za-z]{3,}\b/);
await page.getByRole('button', { name: translations.ru.toRegister, exact: true }).click();
expect(await latin()).not.toMatch(/\b[A-Za-z]{3,}\b/);
});
test('Казахский по ссылке остаётся выбранным в списке', async ({ page }) => {
await page.goto('/?lang=kk');
await expect(page.locator('select.lang')).toHaveValue('kk');
await expect(page.locator('select.lang option')).toHaveText(['RU — Русский', 'EN — English', 'KK — Қазақша']);
await page.locator('select.lang').selectOption('en');
await expect(page.locator('select.lang option')).toHaveCount(2);
});