File size: 3,122 Bytes
ef987bb | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 | const path = require('path');
const { pathToFileURL } = require('url');
const { chromium } = require('playwright');
function assert(condition, message) {
if (!condition) throw new Error(message);
}
async function beginFirstQuestion(browser) {
const page = await browser.newPage({ viewport: { width: 900, height: 700 } });
const attemptedNetwork = [];
await page.route(/^https?:\/\//, route => {
attemptedNetwork.push(route.request().url());
return route.abort('blockedbyclient');
});
await page.goto(pathToFileURL(path.join(process.cwd(), 'index.html')).href, { waitUntil: 'domcontentloaded' });
await page.locator('[data-testid="write-trigger"]').click();
await page.locator('[data-testid="prompt-input"]').fill('first deterministic question');
await page.locator('[data-testid="send-button"]').click();
const followup = page.locator('[data-testid="followup-input"]');
await followup.waitFor({ state: 'visible', timeout: 2000 });
return { page, followup, attemptedNetwork };
}
(async () => {
const browser = await chromium.launch({ headless: true, args: ['--no-sandbox'] });
try {
// ENHANCED_CASE_1: the newly created follow-up editor itself owns focus after the first send.
{
const { page, followup, attemptedNetwork } = await beginFirstQuestion(browser);
assert(await followup.evaluate(el => document.activeElement === el), 'new follow-up input must receive focus automatically');
assert(attemptedNetwork.length === 0, 'enhanced case must run without network access');
await page.close();
}
// ENHANCED_CASE_2: immediate typing, without any extra click, is captured by the focused follow-up editor.
{
const { page, followup, attemptedNetwork } = await beginFirstQuestion(browser);
const question = 'typed immediately as a follow up';
await page.keyboard.type(question);
assert(await followup.inputValue() === question, 'typing immediately must populate the follow-up input');
assert(attemptedNetwork.length === 0, 'enhanced case must run without network access');
await page.close();
}
// ENHANCED_CASE_3: Enter submits the focused follow-up question from the keyboard.
{
const { page, followup, attemptedNetwork } = await beginFirstQuestion(browser);
const question = 'keyboard submitted follow up';
await page.keyboard.type(question);
const before = await page.locator('body').innerText();
await page.keyboard.press('Enter');
await page.waitForFunction(text => window.__getSubmissions().at(-1) === text, question, { timeout: 1500 });
const after = await page.locator('body').innerText();
assert(await page.evaluate(text=>window.__getSubmissions().at(-1)===text,question), 'Enter must submit or record the follow-up question');
assert(attemptedNetwork.length === 0, 'enhanced case must run without network access');
await page.close();
}
} finally {
await browser.close();
}
console.log('enhanced cases passed for task 18');
})().catch(err => {
console.error(err && err.stack || err);
process.exit(1);
});
|