Download task_040/tests/validate_ui_behavior.js from Lego-X/UXInteract: direct link, hf CLI and curl.
- Browser
- Download file 2.18 kB
-
https://huggingface.co/datasets/Lego-X/UXInteract/resolve/main/task_040/tests/validate_ui_behavior.js
- Command line
-
hf download hf://datasets/Lego-X/UXInteract/task_040/tests/validate_ui_behavior.js
-
curl -L -o validate_ui_behavior.js https://huggingface.co/datasets/Lego-X/UXInteract/resolve/main/task_040/tests/validate_ui_behavior.js
2.18 kB
| const path = require('path'); | |
| const { pathToFileURL } = require('url'); | |
| const { chromium } = require('playwright'); | |
| (async () => { | |
| const browser = await chromium.launch({ headless: true }); | |
| const page = await browser.newPage({ viewport: { width: 1000, height: 700 } }); | |
| await page.goto(pathToFileURL(path.join(process.cwd(), 'index.html')).href, { waitUntil: 'domcontentloaded' }); | |
| const toggle = page.locator('[data-testid="theme-toggle"], button:has-text("主题切换")').first(); | |
| if (!(await toggle.isVisible())) throw new Error('prominent theme toggle button should be visible near top'); | |
| const before = await page.evaluate(() => { | |
| const ids = ['question-list', 'question-detail', 'comment-area']; | |
| return ids.map(id => { | |
| const el = document.querySelector(`[data-testid="${id}"]`); | |
| const s = getComputedStyle(el); | |
| return `${s.backgroundColor}|${s.color}`; | |
| }).join('||') + '::' + getComputedStyle(document.body).backgroundColor; | |
| }); | |
| await toggle.click(); | |
| await page.waitForTimeout(150); | |
| const mode = await page.evaluate(() => document.documentElement.dataset.theme || document.body.dataset.theme || document.documentElement.className + ' ' + document.body.className); | |
| const after = await page.evaluate(() => { | |
| const ids = ['question-list', 'question-detail', 'comment-area']; | |
| return ids.map(id => { | |
| const el = document.querySelector(`[data-testid="${id}"]`); | |
| const s = getComputedStyle(el); | |
| return `${s.backgroundColor}|${s.color}`; | |
| }).join('||') + '::' + getComputedStyle(document.body).backgroundColor; | |
| }); | |
| if (before === after) throw new Error('theme toggle should immediately change visual styles across the page'); | |
| for (const id of ['question-list', 'question-detail', 'comment-area']) { | |
| const changed = await page.locator(`[data-testid="${id}"]`).evaluate(el => { | |
| const s = getComputedStyle(el); | |
| return s.backgroundColor !== 'rgba(0, 0, 0, 0)' && s.color !== ''; | |
| }); | |
| if (!changed) throw new Error(`${id} should participate in global theme styling`); | |
| } | |
| await browser.close(); | |
| })().catch(err => { console.error(err && err.stack || err); process.exit(1); }); | |