Download task_022/tests/validate_ui_behavior.js from Lego-X/UXInteract: direct link, hf CLI and curl.
- Browser
- Download file 3.76 kB
-
https://huggingface.co/datasets/Lego-X/UXInteract/resolve/main/task_022/tests/validate_ui_behavior.js
- Command line
-
hf download hf://datasets/Lego-X/UXInteract/task_022/tests/validate_ui_behavior.js
-
curl -L -o validate_ui_behavior.js https://huggingface.co/datasets/Lego-X/UXInteract/resolve/main/task_022/tests/validate_ui_behavior.js
3.76 kB
| const path = require('path'); | |
| const { pathToFileURL } = require('url'); | |
| const { chromium } = require('playwright'); | |
| const inputText = input => input.evaluate(el => 'value' in el ? el.value : el.textContent || ''); | |
| (async () => { | |
| const browser = await chromium.launch({ headless: true }); | |
| const page = await browser.newPage({ viewport: { width: 1000, height: 720 } }); | |
| await page.goto(pathToFileURL(path.join(process.cwd(), 'index.html')).href, { waitUntil: 'domcontentloaded' }); | |
| const area = page.locator('[data-testid="floating-prompt-area"]'); | |
| const input = area.locator('input, textarea, [contenteditable="true"]'); | |
| if (!(await area.isVisible())) throw new Error('floating prompt area must remain visible'); | |
| if (!(await input.first().isVisible())) throw new Error('floating prompt area should contain the reusable input'); | |
| const box = await area.evaluate(el => { | |
| const rect = el.getBoundingClientRect(); | |
| const style = getComputedStyle(el); | |
| return { position: style.position, bottom: style.bottom, radius: style.borderRadius, top: rect.top, bottomEdge: rect.bottom, height: rect.height }; | |
| }); | |
| if (box.position !== 'fixed') throw new Error('floating area must retain fixed positioning'); | |
| // Real on-screen check: the floating area must be fully within the viewport, | |
| // regardless of whether it is pinned to the top or the bottom. (Previously this | |
| // used an arbitrary `top > 600` cutoff that rejected a legitimately on-screen | |
| // bottom-pinned bar, contradicting the instruction to preserve the floating layout.) | |
| const viewportHeight = 720; | |
| if (!(box.bottomEdge <= viewportHeight + 1 && box.top >= -1 && box.bottomEdge > box.top)) { | |
| throw new Error('floating area is not fully visible in viewport'); | |
| } | |
| await input.first().fill('pending prompt text'); | |
| const value = await inputText(input.first()); | |
| if (value !== 'pending prompt text') throw new Error('pending input should be editable'); | |
| const areaText = ((await area.textContent()) || '').toLowerCase(); | |
| if (areaText.includes('already sent') || areaText.includes('sent message')) { | |
| throw new Error('floating area should not render sent-message-only content'); | |
| } | |
| const className = await area.getAttribute('class') || ''; | |
| if (!/(rounded|square|radius|corner)/i.test(className) && !box.radius) { | |
| throw new Error('corner logic signal should remain on floating area'); | |
| } | |
| // Chat send behavior: sending appends a new user bubble, clears the input, | |
| // and an empty input never appends. | |
| const userBubbles = page.locator('.chat-message.user, [data-testid="chat-message-user"]'); | |
| const sendBtn = page.locator('[data-testid="send-button"], .floating-prompt-area button, .send-btn').first(); | |
| if (!(await sendBtn.isVisible())) throw new Error('a send control should exist in the floating prompt area'); | |
| const before = await userBubbles.count(); | |
| await input.first().fill('hello world'); | |
| await sendBtn.click(); | |
| const after = await userBubbles.count(); | |
| if (after !== before + 1) throw new Error('sending should append exactly one new user message bubble'); | |
| const lastText = ((await userBubbles.last().textContent()) || '').trim(); | |
| if (lastText !== 'hello world') throw new Error('the appended bubble should contain the sent text'); | |
| if ((await inputText(input.first())) !== '') throw new Error('input should be cleared after sending'); | |
| // Empty / whitespace-only input must not append anything. | |
| await input.first().fill(' '); | |
| await sendBtn.click(); | |
| if ((await userBubbles.count()) !== after) throw new Error('empty input should not append a message'); | |
| await browser.close(); | |
| })().catch(err => { console.error(err && err.stack || err); process.exit(1); }); | |