treker-po-trenirovkam-i-pit.../tests/browser/profile-results.spec.js
Peppa bde271abe2
All checks were successful
peppa/lint lint: success за 1с
peppa/test test: success за 1с
peppa/build build: success за 0с
ci / checks (pull_request) Successful in 10s
deploy / deploy (pull_request) Successful in 14s
TPTIP-51: проверить профиль, пересчёт питания и приватность
2026-11-17 16:44:23 +05:00

69 lines
4.2 KiB
JavaScript

const { test, expect } = require('@playwright/test');
const translations = require('../../profile/i18n.json');
test.use({ viewport: { width: 375, height: 812 } });
const password = 'private-profile-results-password';
async function register(page, lang, username, weight = 81) {
await page.goto('/?lang=' + lang);
await page.getByRole('button', { name: translations[lang].toRegister, exact: true }).click();
for (const [key, value] of Object.entries({ username, password, height: 182, weight, age: 32 })) await page.locator('#field-' + key).fill(String(value));
await page.locator('#field-sex').selectOption('male');
await page.locator('#field-activity').selectOption('1.375');
await page.getByRole('button', { name: translations[lang].register, exact: true }).click();
await expect(page.locator('.stats strong').first()).toBeVisible();
}
for (const lang of ['ru', 'kk', 'en']) {
test(`Пересчёт после изменения и ошибка редактирования (${lang})`, async ({ page }) => {
const t = translations[lang], username = 'results_' + lang + Date.now();
await register(page, lang, username);
await page.getByRole('button', { name: t.logout, exact: true }).click();
await page.getByRole('button', { name: t.toLogin, exact: true }).click();
await page.locator('#field-username').fill(username);
await page.locator('#field-password').fill(password);
await page.getByRole('button', { name: t.login, exact: true }).click();
await expect(page.locator('.stats strong')).toHaveText(['2465', '130']);
await expect(page.locator('.meal')).toHaveCount(3);
await expect(page.locator('.meal').first()).toContainText('569');
await page.locator('#field-height').fill('190');
await page.locator('#field-weight').fill('90');
await page.getByRole('button', { name: t.save, exact: true }).click();
await expect(page.locator('.stats strong')).toHaveText(['2657', '144']);
await expect(page.locator('.meal').first()).toContainText('613');
await expect(page.locator('.meal').nth(1)).toContainText('709');
await expect(page.locator('.meal').nth(2)).toContainText('569');
await expect(page.getByRole('alert')).toHaveText(t.saved);
await page.reload();
await expect(page.locator('#field-height')).toHaveValue('190');
await expect(page.locator('#field-weight')).toHaveValue('90');
await expect(page.locator('.stats strong')).toHaveText(['2657', '144']);
await page.screenshot({ path: `docs/screens/tptip-51-profile-${lang}.png`, fullPage: true });
await page.locator('#field-weight').fill('0');
await page.getByRole('button', { name: t.save, exact: true }).click();
await expect(page.locator('#field-weight-error')).toHaveText(t.errors.weight);
await expect(page.locator('.stats strong')).toHaveText(['2657', '144']);
await page.reload();
await expect(page.locator('#field-weight')).toHaveValue('90');
});
}
test('Два пользователя и доступ без входа', async ({ browser }) => {
const annaContext = await browser.newContext(), borisContext = await browser.newContext();
try {
const anna = await annaContext.newPage(), boris = await borisContext.newPage();
const username = 'anna_' + Date.now();
await register(anna, 'ru', username);
await register(boris, 'ru', 'boris_' + Date.now(), 92);
const response = await boris.request.get('/api/profile?username=' + username);
expect((await response.json()).profile.weight).toBe(92);
await expect(anna.locator('#field-weight')).toHaveValue('81');
await boris.locator('#field-weight').fill('95');
await boris.getByRole('button', { name: translations.ru.save, exact: true }).click();
await expect(boris.getByRole('alert')).toHaveText(translations.ru.saved);
await anna.reload();
await expect(anna.locator('#field-weight')).toHaveValue('81');
await anna.getByRole('button', { name: translations.ru.logout, exact: true }).click();
expect((await anna.request.get('/api/profile')).status()).toBe(401);
await expect(anna.locator('.stats')).toHaveCount(0);
await anna.reload();
await expect(anna.locator('.meal')).toHaveCount(0);
} finally { await annaContext.close(); await borisContext.close(); }
});