treker-po-trenirovkam-i-pit.../tests/browser/register-sex.spec.js

39 lines
2.3 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({ viewport: { width: 360, height: 640 } });
for (const lang of ['ru', 'kk', 'en']) {
test(`Регистрация: подсказка пола и возврат ко входу (${lang})`, async ({ page }) => {
const t = translations[lang];
await page.addInitScript(() => sessionStorage.setItem('tpt.welcomeSeen', '1'));
await page.goto('/?lang=' + lang);
await page.getByRole('button', { name: t.toRegister, exact: true }).click();
await expect(page.locator('#field-sex option').first()).toHaveText(t.sexChoose);
await expect(page.locator('#field-sex')).not.toContainText('Choose');
await expect(page.locator('#field-sex-hint')).toHaveText(t.sexHint);
await page.getByRole('button', { name: t.toLogin, exact: true }).click();
await expect(page.getByRole('heading', { name: t.loginHeading })).toBeVisible();
await expect(page.locator('#field-sex')).toHaveCount(0);
});
}
for (const [lang, action] of Object.entries({ ru: 'Создать аккаунт', kk: 'Аккаунт ашу', en: 'Create account' })) {
test(`Первый экран открывает регистрацию с выбором пола и переходом ко входу (${lang})`, async ({ page }) => {
const t = translations[lang];
await page.goto('/?lang=' + lang);
const createAccount = page.getByRole('button', { name: action, exact: true });
await expect(page.locator('.welcome p').first()).toContainText(action);
await expect(createAccount).toBeInViewport({ ratio: 1 });
await createAccount.click();
await expect(page.getByRole('heading', { name: t.registerHeading })).toBeVisible();
const sex = page.locator('#field-sex');
await expect(sex).toHaveValue('');
await expect(sex.locator('option').first()).toHaveText(lang === 'ru' ? 'Выберите пол' : t.sexChoose);
await expect(sex).toHaveAccessibleDescription(t.sexHint);
await expect(page.locator('#field-sex-hint')).toBeVisible();
await page.getByRole('button', { name: t.toLogin, exact: true }).click();
await expect(page.getByRole('heading', { name: t.loginHeading })).toBeVisible();
await expect(page.locator('form input')).toHaveCount(2);
await expect(sex).toHaveCount(0);
});
}