77 lines
3.9 KiB
JavaScript
77 lines
3.9 KiB
JavaScript
const { test, expect } = require('@playwright/test');
|
||
|
||
test.use({ baseURL: 'http://127.0.0.1:3094', viewport: { width: 375, height: 740 }, locale: 'ru-RU', launchOptions: process.env.PLAYWRIGHT_CHROMIUM_EXECUTABLE_PATH ? { executablePath: process.env.PLAYWRIGHT_CHROMIUM_EXECUTABLE_PATH } : {} });
|
||
|
||
async function skip(page) {
|
||
await page.goto('/');
|
||
await page.getByRole('button', { name: 'Пропустить', exact: true }).click();
|
||
await expect(page.locator('.sheet')).toHaveCount(0);
|
||
}
|
||
|
||
const sections = [
|
||
['Питание', 'Итог дня'],
|
||
['Тренировки', 'Пока нет ни одной тренировки'],
|
||
['Тело', 'Вес'],
|
||
['Статистика', 'Калории по дням'],
|
||
['Настройки', 'Калькулятор нормы']
|
||
];
|
||
|
||
test('Сценарий: Разделы после пропуска', async ({ page }) => {
|
||
const errors = [];
|
||
page.on('pageerror', e => errors.push(e.message));
|
||
await skip(page);
|
||
await expect(page.locator('.datenav')).toBeVisible();
|
||
const today = await page.evaluate(() => {
|
||
const date = new Date();
|
||
return `${date.getFullYear()}-${String(date.getMonth() + 1).padStart(2, '0')}-${String(date.getDate()).padStart(2, '0')}`;
|
||
});
|
||
await expect(page.locator('.datenav input')).toHaveValue(today);
|
||
await expect(page.locator('.datenav')).toContainText('сегодня');
|
||
await page.reload();
|
||
await expect(page.locator('.sheet')).toHaveCount(0);
|
||
await expect(page.locator('.datenav input')).toHaveValue(today);
|
||
await expect(page.locator('#tabs')).toBeVisible();
|
||
await expect(page.locator('[data-norms-pending]')).toContainText('возраст, рост и вес');
|
||
await expect(page.locator('#toast')).toBeHidden();
|
||
await page.screenshot({ path: 'docs/screens/tptip-52-skipped.png' });
|
||
for (const [name, content] of sections) {
|
||
await page.locator('#tabs').getByRole('button', { name, exact: false }).click();
|
||
await expect(page.locator('#view')).toContainText(content);
|
||
await expect(page.locator('#tabs button[aria-current="page"]')).toContainText(name);
|
||
await expect(page.locator('#tabs')).toBeVisible();
|
||
expect(await page.evaluate(() => document.documentElement.scrollWidth)).toBeLessThanOrEqual(375);
|
||
}
|
||
expect(errors).toEqual([]);
|
||
});
|
||
|
||
test('Сценарий: Сохранение без данных', async ({ page }) => {
|
||
await skip(page);
|
||
await page.locator('[data-norms-open]').click();
|
||
await page.getByRole('button', { name: 'Сохранить', exact: true }).click();
|
||
await expect(page.locator('#view')).toContainText('Заполните это поле');
|
||
await expect(page.locator('#view input').first()).toBeFocused();
|
||
await page.locator('#tabs').getByRole('button', { name: 'Главная', exact: false }).click();
|
||
await expect(page.locator('[data-norms-pending]')).toBeVisible();
|
||
});
|
||
|
||
test('Сценарий: Повторное открытие после сохранения', async ({ page }) => {
|
||
await skip(page);
|
||
await page.locator('[data-norms-open]').click();
|
||
await page.locator('#view select').nth(0).selectOption('m');
|
||
await page.locator('#view select').nth(1).selectOption('1.375');
|
||
const fields = page.locator('#view input');
|
||
for (const [i, value] of ['40', '170', '65'].entries()) {
|
||
await expect(fields.nth(i)).toHaveValue('');
|
||
await fields.nth(i).fill(value);
|
||
}
|
||
await page.getByRole('button', { name: 'Сохранить', exact: true }).click();
|
||
await page.locator('#tabs').getByRole('button', { name: 'Главная', exact: false }).click();
|
||
await page.reload();
|
||
await expect(page.locator('.sheet')).toHaveCount(0);
|
||
await expect(page.locator('[data-norms-pending]')).toHaveCount(0);
|
||
for (const [i, value] of ['0 из 2087', '0 из 117', '0 из 58', '0 из 274', '0 из 1950'].entries()) {
|
||
await expect(page.locator('.rings [data-amount]').nth(i)).toHaveText(value);
|
||
}
|
||
await page.screenshot({ path: 'docs/screens/tptip-52-saved.png' });
|
||
});
|