Download task_009/tests/validate_ui_behavior.js from Lego-X/UXInteract: direct link, hf CLI and curl.
- Browser
- Download file 4.34 kB
-
https://huggingface.co/datasets/Lego-X/UXInteract/resolve/main/task_009/tests/validate_ui_behavior.js
- Command line
-
hf download hf://datasets/Lego-X/UXInteract/task_009/tests/validate_ui_behavior.js
-
curl -L -o validate_ui_behavior.js https://huggingface.co/datasets/Lego-X/UXInteract/resolve/main/task_009/tests/validate_ui_behavior.js
4.34 kB
| const assert = require('node:assert/strict'); | |
| const path = require('node:path'); | |
| const { pathToFileURL } = require('node:url'); | |
| const { chromium } = require('playwright'); | |
| async function findScrollHost(page) { | |
| return page.evaluateHandle(() => { | |
| const blocks = document.querySelectorAll('[data-testid="prompt-response-block"]'); | |
| for (let parent = blocks[blocks.length - 1].parentElement; parent; parent = parent.parentElement) { | |
| if (parent.scrollHeight - parent.clientHeight <= 4) continue; | |
| const overflow = getComputedStyle(parent).overflowY; | |
| if (parent === document.scrollingElement || overflow !== 'visible') return parent; | |
| } | |
| return null; | |
| }); | |
| } | |
| async function checkOverflowScrolling(page) { | |
| await page.setViewportSize({width: 1200, height: 420}); | |
| await page.evaluate(() => window.__setMockGenerate(prompt => Promise.resolve('result: ' + prompt))); | |
| const placeholder = page.getByTestId('new-block-placeholder'); | |
| for (let index = 0; index < 20; index++) { | |
| await page.getByTestId('prompt-input').nth(index).fill('scroll request ' + index); | |
| await page.getByTestId('send-button').nth(index).click(); | |
| await placeholder.click(); | |
| await page.getByTestId('prompt-response-block').nth(index + 1).waitFor({state: 'attached'}); | |
| const candidate = await findScrollHost(page); | |
| try { | |
| const host = candidate.asElement(); | |
| if (!host) continue; | |
| const start = await host.evaluate(element => { | |
| const root = element === document.scrollingElement; | |
| const rect = (root ? document.querySelector('[data-testid="content"]') : element).getBoundingClientRect(); | |
| return { | |
| x: (Math.max(0, rect.left) + Math.min(innerWidth, rect.right)) / 2, | |
| y: (Math.max(0, rect.top) + Math.min(innerHeight, rect.bottom)) / 2, | |
| scrollTop: element.scrollTop, | |
| }; | |
| }); | |
| await page.mouse.move(start.x, start.y); | |
| await page.mouse.wheel(0, start.scrollTop > 2 ? -1000 : 1000); | |
| await page.waitForFunction(({element, initial}) => Math.abs(element.scrollTop - initial) > 1, | |
| {element: host, initial: start.scrollTop}, {timeout: 5000}); | |
| return true; | |
| } finally { | |
| await candidate.dispose(); | |
| } | |
| } | |
| return false; | |
| } | |
| (async () => { | |
| const browser = await chromium.launch({ headless: true, args: ['--no-sandbox'] }); | |
| try { | |
| const page = await browser.newPage({ viewport: { width: 1200, height: 800 } }); | |
| await page.route(/^https?:/, route => route.abort()); | |
| await page.goto(pathToFileURL(path.resolve('index.html')).href); | |
| const dimensions = await page.evaluate(() => { | |
| const sidebar = document.querySelector('[data-testid="sidebar"]'); | |
| const content = document.querySelector('[data-testid="content"]'); | |
| const styles = getComputedStyle(content); | |
| const sidebarBox = sidebar.getBoundingClientRect(); | |
| const contentBox = content.getBoundingClientRect(); | |
| return { | |
| sidebar: sidebarBox.width, | |
| content: contentBox.width, | |
| gap: contentBox.left - sidebarBox.right, | |
| extraRight: document.documentElement.clientWidth - contentBox.right - sidebarBox.left, | |
| padding: [parseFloat(styles.paddingLeft), parseFloat(styles.paddingRight)], | |
| }; | |
| }); | |
| assert(Math.abs(dimensions.sidebar - 240) <= 5, 'desktop sidebar must be about 240px'); | |
| assert(dimensions.content > 0 && dimensions.content <= 905, 'content must render within max 900px'); | |
| assert(dimensions.padding.every(value => value >= 15), 'content needs horizontal padding'); | |
| // When a max-width panel is centered in the remaining space, the extra | |
| // margin on its left is balanced by the equivalent right margin. | |
| const nearGutter = gap => Math.abs(gap - 32) <= 2; | |
| assert(nearGutter(dimensions.gap) || | |
| dimensions.extraRight > 0 && nearGutter(dimensions.gap - dimensions.extraRight), | |
| 'desktop layout needs a 32px sidebar gutter outside any centered surplus margin'); | |
| const overflowTested = await checkOverflowScrolling(page); | |
| console.log('desktop layout and sidebar gutter passed'); | |
| console.log(overflowTested ? 'wheel scrolled the overflowing workspace' : 'generated blocks fit without vertical overflow'); | |
| } finally { | |
| await browser.close(); | |
| } | |
| })().catch(error => { console.error(error); process.exit(1); }); | |