47 lines
2.3 KiB
JavaScript
47 lines
2.3 KiB
JavaScript
// Feeds synthetic tilt events (tan 5° ≈ 8.7 %) through both sensor paths. Run against `pnpm preview`.
|
|
import { chromium } from 'playwright-core';
|
|
const URL = process.env.URL ?? 'http://localhost:4173/';
|
|
const browser = await chromium.launch();
|
|
let bad = 0;
|
|
const check = (c, m) => { console.log(`${c ? 'ok ' : 'FAIL'} ${m}`); if (!c) bad = 1; };
|
|
|
|
async function run(kind) {
|
|
const page = await browser.newPage({ viewport: { width: 1000, height: 900 }, locale: 'pl-PL' });
|
|
await page.goto(URL, { waitUntil: 'networkidle' });
|
|
await page.click('text=Zaloguj jako Anna Kowalska');
|
|
await page.fill('#q', 'Sukiennice');
|
|
await page.click('button[id^=place-]');
|
|
await page.click('text=Popraw lub uzupełnij >> nth=0');
|
|
await page.selectOption('#rep-attr', 'ramp');
|
|
await page.click('text=Zmierz telefonem');
|
|
await page.click('text=Włącz czujniki');
|
|
for (let i = 0; i < 5; i++) {
|
|
await page.evaluate((k) => {
|
|
if (k === 'orientation') window.dispatchEvent(new DeviceOrientationEvent('deviceorientation', { beta: 5, gamma: 0 }));
|
|
else window.dispatchEvent(new DeviceMotionEvent('devicemotion', { accelerationIncludingGravity: { x: 0, y: 0.854, z: 9.77 } }));
|
|
}, kind);
|
|
await page.waitForTimeout(100);
|
|
}
|
|
const txt = await page.locator('[aria-labelledby=inc-title] p.text-bold').innerText();
|
|
check(/^8\.[67] %/.test(txt), `${kind}: reads ${txt} (expected ≈ 8.7 %)`);
|
|
await page.click('text=Wyzeruj tutaj');
|
|
await page.evaluate(() => window.dispatchEvent(new DeviceOrientationEvent('deviceorientation', { beta: 5, gamma: 0 })));
|
|
await page.close();
|
|
}
|
|
await run('orientation');
|
|
await run('motion');
|
|
|
|
// no events at all -> explicit message with diagnostics, not a silent failure
|
|
const page = await browser.newPage({ locale: 'pl-PL' });
|
|
await page.goto(URL, { waitUntil: 'networkidle' });
|
|
await page.click('text=Zaloguj jako Anna Kowalska');
|
|
await page.fill('#q', 'Sukiennice');
|
|
await page.click('button[id^=place-]');
|
|
await page.click('text=Popraw lub uzupełnij >> nth=0');
|
|
await page.selectOption('#rep-attr', 'ramp');
|
|
await page.click('text=Zmierz telefonem');
|
|
await page.click('text=Włącz czujniki');
|
|
await page.waitForSelector('text=Diagnostyka', { timeout: 6000 });
|
|
check(true, 'silent device -> message + diagnostics: ' + (await page.locator('text=Diagnostyka').innerText()));
|
|
await browser.close();
|
|
process.exitCode = bad;
|