57 lines
3.3 KiB
JavaScript
57 lines
3.3 KiB
JavaScript
const { readFileSync } = require('node:fs')
|
|
const { parse } = require('@vue/compiler-sfc')
|
|
const { chromium } = require('playwright')
|
|
const assert = require('node:assert/strict')
|
|
|
|
// Use the production layout styles; the fixture isolates sizing from authentication and GPU rendering.
|
|
const css = (path) => parse(readFileSync(path, 'utf8')).descriptor.styles.map(s => s.content).join('\n')
|
|
async function main() {
|
|
const browser = await chromium.launch({ headless: true })
|
|
try {
|
|
const page = await browser.newPage()
|
|
const styles = [
|
|
'src/components/layout/AppShell.vue',
|
|
'src/components/layout/AppPageShell.vue',
|
|
'src/views/AdminComponentImportSplit.vue',
|
|
].map(css).join('\n')
|
|
for (const height of [600, 928]) {
|
|
await page.setViewportSize({ width: 1666, height })
|
|
await page.setContent(`<style>*{box-sizing:border-box}body{margin:0}:root{--rf-size-topbar:48px}${styles}</style>
|
|
<div class="rf-app-shell split-page-shell">
|
|
<nav style="height:48px;flex-shrink:0">导航</nav>
|
|
<main class="content"><main class="split-workbench">
|
|
<header class="split-workbench__header">导入整机并拆分</header>
|
|
<section class="split-workbench__grid">
|
|
<aside class="split-panel split-panel--tree"><div class="split-tree">拆分结构</div></aside>
|
|
<section class="split-panel split-panel--viewport"><div class="split-panel__heading">3D 预览</div><div class="split-viewport"><canvas style="width:100%;height:100%"></canvas></div></section>
|
|
<aside class="split-panel split-panel--inspector"><div class="split-panel__heading">片段属性</div><div class="split-inspector__content"><div id="form"></div><div id="last">最后一个接口字段</div></div></aside>
|
|
</section>
|
|
</main></main>
|
|
</div>`)
|
|
let original
|
|
for (const formHeight of [100, 2400, 100, 3600]) {
|
|
const result = await page.evaluate((formHeight) => {
|
|
document.querySelector('#form').style.height = `${formHeight}px`
|
|
const scroll = document.querySelector('.split-inspector__content')
|
|
scroll.scrollTop = scroll.scrollHeight
|
|
const viewport = document.querySelector('.split-viewport').getBoundingClientRect()
|
|
const last = document.querySelector('#last').getBoundingClientRect()
|
|
return { viewportHeight: viewport.height, bottom: viewport.bottom,
|
|
client: scroll.clientHeight, total: scroll.scrollHeight, scrollTop: scroll.scrollTop,
|
|
lastBottom: last.bottom, scrollBottom: scroll.getBoundingClientRect().bottom,
|
|
documentHeight: document.documentElement.scrollHeight }
|
|
}, formHeight)
|
|
original ??= result.viewportHeight
|
|
assert.ok(result.viewportHeight > 200, JSON.stringify(result))
|
|
assert.equal(result.viewportHeight, original)
|
|
assert.equal(result.bottom, height)
|
|
assert.equal(result.documentHeight, height)
|
|
assert.ok(result.lastBottom <= result.scrollBottom + 1)
|
|
if (formHeight > 100) assert.ok(result.total > result.client && result.scrollTop > 0)
|
|
}
|
|
console.log(`PASS 1666x${height}: stable viewport, internal scrolling, final field reachable`)
|
|
}
|
|
} finally { await browser.close() }
|
|
}
|
|
main().catch(error => { console.error(error); process.exitCode = 1 })
|