Lo schema dei test era fermo all'epoca pre-onboarding. Aggiornati e ampliati a 4 spec, 8 test totali, tutti verdi: - e2e/auth.spec.ts (esistente, già passante): sign-up/out/in - e2e/home.spec.ts (esistente): smoke landing - e2e/onboarding.spec.ts (nuovo, sostituisce profile.spec.ts): signup → /welcome → /onboarding → goal → profile → conditions → verifica BMR/TDEE persistiti su /profile (Michele 49a, 76 kg, 170 cm, sedentario → 1583 / 1899 kcal) - e2e/plan.spec.ts (nuovo): genera piano, verifica presenza colazione/ pranzo/cena, header con kcal·P·G·C, bottoni "Segna come consumato" - e2e/fasting-tracking.spec.ts (nuovo): avvia 16:8 + diario sintomi + abort; inserisci pesata e verifica che appaia nella history 8 passed (9.6s). Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
79 lines
3.2 KiB
TypeScript
79 lines
3.2 KiB
TypeScript
import { expect, test, type Page } from '@playwright/test';
|
|
|
|
function uniqueEmail(prefix: string): string {
|
|
const ts = Date.now();
|
|
const rand = Math.floor(Math.random() * 1e6);
|
|
return `e2e-${prefix}-${ts}-${rand}@ketopath.test`;
|
|
}
|
|
|
|
async function signupOnboarded(page: Page, email: string): Promise<void> {
|
|
const password = 'Password!123';
|
|
await page.goto('/sign-up');
|
|
await page.getByLabel('Come ti chiami').fill('FT E2E');
|
|
await page.getByLabel('Email').fill(email);
|
|
await page.getByLabel('Password').fill(password);
|
|
await page.getByRole('button', { name: 'Crea account' }).click();
|
|
await page.waitForURL('/');
|
|
|
|
await page.goto('/welcome');
|
|
await page.getByText(/Confermo di essere maggiorenne/).click();
|
|
await page.getByText(/Dichiaro di non avere condizioni mediche escludenti/).click();
|
|
await page.getByText(/Accetto che KetoPath non sostituisce/).click();
|
|
await page.getByRole('button', { name: 'Accetto e proseguo' }).click();
|
|
await page.waitForURL('/onboarding');
|
|
await page.getByRole('button', { name: /Perdere peso/ }).click();
|
|
await page.getByRole('button', { name: 'Salva e continua' }).click();
|
|
await page.getByLabel('Età').fill('45');
|
|
await page.getByLabel('Sesso').click();
|
|
await page.getByRole('option', { name: 'Maschio' }).click();
|
|
await page.getByLabel('Altezza (cm)').fill('175');
|
|
await page.getByLabel('Iniziale').fill('80');
|
|
await page.getByLabel('Attuale').fill('80');
|
|
await page.getByLabel('Obiettivo').fill('75');
|
|
await page.getByLabel('Livello di attività').click();
|
|
await page.getByRole('option', { name: /Sedentario/ }).click();
|
|
await page.getByRole('button', { name: 'Salva e continua' }).click();
|
|
await page.getByRole('button', { name: 'Salva e continua' }).click();
|
|
}
|
|
|
|
test.describe('fasting flow', () => {
|
|
test('start a 16:8 fast then abort it', async ({ page }) => {
|
|
test.setTimeout(60_000);
|
|
await signupOnboarded(page, uniqueEmail('fasting'));
|
|
|
|
await page.goto('/fasting');
|
|
// Default protocollo è 16:8 — clicca "Avvia digiuno"
|
|
await page.getByRole('button', { name: 'Avvia digiuno' }).click();
|
|
|
|
// Live timer dovrebbe apparire (00:00:0X)
|
|
await expect(page.locator('text=/^\\d\\d:\\d\\d:\\d\\d$/').first()).toBeVisible();
|
|
// Diario sintomi presente
|
|
await expect(page.getByText('Come ti senti?')).toBeVisible();
|
|
|
|
// Annulla la sessione (dialog confirm → accept)
|
|
page.once('dialog', (d) => {
|
|
void d.accept();
|
|
});
|
|
await page.getByRole('button', { name: 'Annulla sessione' }).click();
|
|
// Dopo l'abort si torna alla schermata di avvio
|
|
await expect(page.getByRole('button', { name: 'Avvia digiuno' })).toBeVisible();
|
|
});
|
|
});
|
|
|
|
test.describe('weight tracking flow', () => {
|
|
test('inserire una pesata + apparire nella history', async ({ page }) => {
|
|
test.setTimeout(60_000);
|
|
await signupOnboarded(page, uniqueEmail('tracking'));
|
|
|
|
await page.goto('/tracking');
|
|
|
|
// Form pesata
|
|
await page.getByLabel('Peso (kg)').fill('80');
|
|
await page.getByRole('button', { name: 'Registra', exact: true }).click();
|
|
|
|
// "Peso attuale" + "80.0kg" appaiono nella history
|
|
await expect(page.getByText('Peso attuale')).toBeVisible();
|
|
await expect(page.getByText(/80\.0\s*kg/).first()).toBeVisible();
|
|
});
|
|
});
|