// E2E for photo evidence + on-device AI triage. Needs `pnpm preview` and sample photos in scripts/.cache/img. import { chromium } from 'playwright-core'; const URL = process.env.URL ?? 'http://localhost:4173/'; const IMG = process.env.IMG ?? 'scripts/.cache/img/staircase_entrance_building_steps.jpg'; const attr = process.env.ATTR ?? 'steps'; const claim = process.env.CLAIM ?? 'yes'; const browser = await chromium.launch(); const page = await browser.newPage({ viewport: { width: 1280, height: 900 }, locale: 'pl-PL' }); const errors = []; page.on('pageerror', (e) => errors.push(e.message)); await page.goto(URL, { waitUntil: 'networkidle' }); await page.click('text=Zaloguj jako Anna Kowalska'); await page.fill('#q', 'Pracownia Przykładowa'); await page.click('button[id^=place-]'); await page.waitForSelector('text=Szczegóły dostępności'); await page.click('text=Popraw lub uzupełnij >> nth=0'); await page.selectOption('#rep-attr', attr); await page.click(`label[for=rep-v-${claim}]`); await page.setInputFiles('#rep-gal', IMG); await page.waitForSelector('img.kbb-thumb'); if (attr === 'steps') { await page.fill('#rep-manual', '14'); await page.click('text=Użyj wartości'); } await page.click('text=Zapisz zgłoszenie'); console.log('submitted; waiting for model (first run downloads ~100 MB)…'); const t0 = Date.now(); await page.waitForSelector('text=/Szybka ścieżka|Do przeglądu|Prawdopodobnie do odrzucenia|Brak kredytów/', { timeout: 280000 }); console.log(`vetting finished in ${Math.round((Date.now() - t0) / 1000)}s`); console.log((await page.locator('li:has(img.kbb-thumb)').first().innerText()).replace(/\n+/g, ' | ')); await page.screenshot({ path: process.env.OUT ?? 'scripts/.cache/vet.png' }); console.log('errors:', errors.slice(0, 3)); await browser.close();