Commit 21187992 by PLN (Algolia)

chore: stray persona-driver temp file out of the tree

parent 819c11d5
const { chromium } = require('@playwright/test');
const BASE = 'http://localhost:4310';
const log = (...a) => console.log('[kb]', ...a);
let n = 0;
const shot = async (page, name) => { await page.screenshot({ path: `/tmp/icp-keyboard-native-${++n}-${name}.png` }); log(`shot ${n}: ${name}`); };
(async () => {
const browser = await chromium.launch({ headless: true });
const page = await browser.newPage({ viewport: { width: 1280, height: 800 } });
const errors = [];
page.on('console', (m) => { if (m.type() === 'error') errors.push('console: ' + m.text()); });
page.on('pageerror', (e) => errors.push('pageerror: ' + e.message));
page.on('download', (d) => log('DOWNLOAD fired:', d.suggestedFilename()));
const focusOf = () => page.evaluate(() => {
const el = document.activeElement;
return (!el || el === document.body) ? 'BODY' : el.tagName + ' "' + (el.textContent || '').trim().slice(0, 40) + '"';
});
const tabUntil = async (re, max = 14) => {
for (let i = 0; i < max; i++) {
const f = await focusOf();
if (re.test(f)) return { f, tabs: i };
await page.keyboard.press('Tab');
}
return { f: 'NOT FOUND', tabs: -1 };
};
const qText = () => page.evaluate(() => (document.querySelector('h2') || { innerText: '' }).innerText.trim().slice(0, 60));
await page.goto(BASE + '/tdah/', { waitUntil: 'networkidle' });
await page.waitForTimeout(700);
await page.keyboard.press('Tab'); await page.keyboard.press('Space');
await page.keyboard.press('Tab'); await page.keyboard.press('Enter');
await page.waitForTimeout(350);
await page.keyboard.press('Tab'); await page.keyboard.press('Enter');
await page.waitForTimeout(350);
// --- double-advance timing test on Q1/Q2/Q3 ---
const q0 = await qText();
await page.keyboard.press('4'); // answer Q1
await page.waitForTimeout(80); // then Enter fast (<350ms)
await page.keyboard.press('Enter');
await page.waitForTimeout(700); // let any pending auto-advance fire
const q1 = await qText();
log('DOUBLE-ADVANCE TEST: Q1=', q0.slice(0, 40), '→ after digit+fast-Enter landed on:', q1.slice(0, 40));
log(' expected next (Q2) would be priority question; landed on:', q1.slice(0, 50));
// --- slow rhythm: digit, wait 600ms, Enter ---
const before = await qText();
await page.keyboard.press('2');
await page.waitForTimeout(600);
await page.keyboard.press('Enter');
await page.waitForTimeout(500);
log('SLOW rhythm from "', before.slice(0, 40), '" landed on:', (await qText()).slice(0, 40));
// --- now finish whole quiz with safe rhythm (wait 500ms after digit) ---
for (let step = 1; step <= 160; step++) {
const s = await page.evaluate(() => {
const btns = Array.from(document.querySelectorAll('button')).filter((b) => b.getBoundingClientRect().height > 0);
const act = btns.filter((b) => /^(Continuer →|Télécharger|Recommencer|Imprimer|Répondre aux|Passer la partie|Voir mes)/.test((b.textContent || '').trim()));
const pills = btns.filter((b) => /jamais|rare|souvent|oui|non|plutôt|pas du|un peu|beaucoup|tout à fait/i.test((b.textContent || '').trim()));
return { act: act.map((b) => b.textContent.trim().slice(0, 35)), hasPills: pills.length > 0,
h1: (document.querySelector('h1,h2') || { innerText: '' }).innerText.trim().slice(0, 60) };
});
if (s.act.length && !s.hasPills) {
if (/Télécharger|Recommencer/.test(s.act.join(' '))) { log('FINAL RESULTS at step', step, '| h:', s.h1); break; }
// recap and gates: tab to a non-jump action (Voir mes résultats / Continuer / etc.)
const r = await tabUntil(/"(Continuer →|Répondre aux|Passer la partie|Voir mes|Passer les)/);
if (r.tabs < 0) { log('cannot reach action on screen:', s.h1, JSON.stringify(s.act)); await shot(page, 'stuck-' + step); break; }
await page.keyboard.press('Enter');
await page.waitForTimeout(350);
continue;
}
if (!s.hasPills) { log('unknown screen at', step, JSON.stringify(s)); break; }
const binary = await page.evaluate(() => {
const bs = Array.from(document.querySelectorAll('button')).filter((x) => /^(Oui|Non)$/.test((x.textContent || '').trim()) && x.getBoundingClientRect().height > 0);
return bs.length === 2 && !/Jamais/.test(document.body.innerText);
});
await page.keyboard.press(binary ? (step % 3 ? '1' : '2') : ['3', '2', '4', '1', '3', '5', '2', '4'][step % 8]);
await page.waitForTimeout(520); // let auto-advance fire alone when it will
const s2 = await page.evaluate(() => {
const btns = Array.from(document.querySelectorAll('button')).filter((b) => b.getBoundingClientRect().height > 0);
return btns.some((b) => /jamais|rare|souvent|oui|non|plutôt|pas du/i.test((b.textContent || '').trim()));
});
if (s2) { await page.keyboard.press('Enter'); await page.waitForTimeout(200); } // no auto-advance (block end) → Enter
}
await page.waitForTimeout(700);
const prog = await page.evaluate(() => (document.body.innerText.match(/\d+ questions? répondue?s?(?: · \S+ \d+)?/) || [null])[0]);
log('final progress:', prog);
await shot(page, 'true-final');
log('final head:', (await page.evaluate(() => document.body.innerText.slice(0, 800))).replace(/\s+\n/g, '\n'));
const dl = await tabUntil(/Télécharger/i);
log('tabs to Télécharger:', dl.tabs, dl.f);
await page.keyboard.press('Enter');
await page.waitForTimeout(2500);
await shot(page, 'after-pdf-enter');
log('CONSOLE ERRORS:', errors.length ? JSON.stringify(errors) : '(clean)');
await browser.close();
})().catch((e) => { console.error('DRIVER FAIL', e); process.exit(1); });
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment