Download task_013/tests/validate_enhanced_cases.js from Lego-X/UXInteract: direct link, hf CLI and curl.
- Browser
- Download file 3.12 kB
-
https://huggingface.co/datasets/Lego-X/UXInteract/resolve/main/task_013/tests/validate_enhanced_cases.js
- Command line
-
hf download hf://datasets/Lego-X/UXInteract/task_013/tests/validate_enhanced_cases.js
-
curl -L -o validate_enhanced_cases.js https://huggingface.co/datasets/Lego-X/UXInteract/resolve/main/task_013/tests/validate_enhanced_cases.js
3.12 kB
| 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); | |
| }); | |