const assert = require('node:assert/strict') const { chromium, frontend, backend, username, password } = require('./vue3-test-runtime.cjs') const long = '智能机器人控制系统专用高精度工业级零部件及配套安装组件的完整长名称' ;(async () => { const login = await (await fetch(backend + '/login', { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ username, password }) })).json() assert.equal(login.code, 200) const browser = await chromium.launch() try { const context = await browser.newContext({ viewport: { width: 1366, height: 900 } }) await context.addCookies([{ name: 'Admin-Token', value: login.token, url: frontend }]) const page = await context.newPage(), queries = [], errors = [] page.setDefaultTimeout(12000) page.on('pageerror', e => errors.push(e.message)) await page.route('**/dev-api/**', route => { const req = route.request(), url = new URL(req.url()), p = url.pathname if (!['GET', 'HEAD'].includes(req.method())) return route.abort('blockedbyclient') if(p==='/dev-api/system/dict/type/1')return route.fulfill({json:{code:200,data:{dictId:1,dictType:'audit_fixture',dictName:'测试字典'}}}) if(p==='/dev-api/system/dict/data/list'&&url.searchParams.get('dictType')==='audit_fixture')return route.fulfill({json:{code:200,total:1,rows:[{dictCode:999991,dictLabel:'测试选项',dictValue:'TEST',status:'0'}]}}) if (p === '/dev-api/warehouse/purchase/batch/list') { queries.push(Object.fromEntries(url.searchParams)) return route.fulfill({ json: { code: 200, rows: [], total: 0 } }) } if (p === '/dev-api/warehouse/product/list') return route.fulfill({ json: { code: 200, total: 1, rows: [{ id: 990901, productName: long, brand: long, spec: long + '-ABCDEFGHIJKLMNOPQRST-1234567890', unit: '个' }] } }) return route.continue() }) async function ready(route) { await page.goto(frontend + route) await page.locator('.desktop-viewport').waitFor() await page.waitForFunction(() => ![...document.querySelectorAll('.desktop-viewport .el-loading-mask')].some(e => e.getClientRects().length)) } await ready('/procurement/details') await page.getByRole('button', { name: '更多筛选', exact: true }).click() const advancedItem = page.locator('.query-toolbar__advanced .el-form-item').filter({ hasText: '物品' }).locator('input') await advancedItem.fill('完整测试条件') await page.getByRole('button', { name: /收起\s*(1)/ }).click() await page.getByRole('button', { name: '搜索', exact: true }).click() await page.waitForFunction(() => !document.querySelector('.purchase-sheet .el-loading-mask')) assert.equal(queries.at(-1).materialName, '完整测试条件') assert.equal(await advancedItem.inputValue(), '完整测试条件') await page.getByRole('button', { name: '重置', exact: true }).click() await page.getByRole('button', { name: '更多筛选', exact: true }).waitFor() assert.ok(!queries.at(-1).materialName) console.log('PASS collapsed advanced filters still reach the query; reset clears their values and indicator') for (const width of [1366, 1440, 1920]) { await page.setViewportSize({ width, height: 900 }) for (const name of ['紧凑', '标准', '宽松']) { await page.locator('#size-select').click(); await page.getByRole('menuitem', { name, exact: true }).click() await page.waitForTimeout(100) const geometry = await page.locator('.query-toolbar').evaluate(e => { const primary = [...e.querySelectorAll('.query-toolbar__primary > .el-form-item')] const buttons = [...e.querySelectorAll('.query-toolbar__actions button')] const r = e.getBoundingClientRect() return { primaryTops: primary.map(e => Math.round(e.getBoundingClientRect().top)), buttonTops: buttons.map(e => Math.round(e.getBoundingClientRect().top)), outside: [...primary, ...buttons].some(e => e.getBoundingClientRect().right > r.right + 2), widths: primary.map(e => e.querySelector('.el-input__wrapper,.el-select__wrapper')?.getBoundingClientRect().width || 0) } }) assert.equal(new Set(geometry.primaryTops).size, 1, width + '/' + name) assert.equal(new Set(geometry.buttonTops).size, 1, width + '/' + name) assert.equal(geometry.outside, false, width + '/' + name) assert.ok(geometry.widths.every(w => w >= 130), width + '/' + name + ': squeezed input') } } console.log('PASS purchase search/new actions stay aligned with usable inputs at 3 widths × 3 densities') await ready('/businessBasics/product') const nameCell = page.locator('.desktop-viewport .el-table__body tr').first().locator('td').nth(1).locator('.cell') assert.equal(await nameCell.evaluate(e => getComputedStyle(e).whiteSpace), 'nowrap') await nameCell.hover() await page.getByRole('tooltip').filter({ hasText: long }).waitFor() console.log('PASS long item names keep one row and the tooltip retains the complete value') for (const route of ['/system/menu', '/system/dict-data/index/1']) { await ready(route) const positions = await page.locator('.desktop-viewport .el-table__body tr').first().locator('td').last().locator('button').evaluateAll(buttons => buttons.map(b => Math.round(b.getBoundingClientRect().top))) assert.ok(positions.length >= 2) assert.equal(new Set(positions).size, 1, route) } console.log('PASS menu and dictionary link actions remain on one line') assert.deepEqual(errors, []) console.log('WRAP LAYOUT PASS; business writes blocked') } finally { await browser.close() } })().catch(error => { console.error(error); process.exitCode = 1 })