162 lines
12 KiB
JavaScript
162 lines
12 KiB
JavaScript
|
|
const assert = require('node:assert/strict')
|
||
|
|
const fs = require('node:fs'), path = require('node:path')
|
||
|
|
const { chromium, frontend: base, backend, username, password } = require('./vue3-test-runtime.cjs')
|
||
|
|
const out = path.resolve(__dirname, '../../.codex-tmp/vue3-list-layout')
|
||
|
|
|
||
|
|
;(async () => {
|
||
|
|
let login
|
||
|
|
for (let attempt = 0; attempt < 8; attempt++) {
|
||
|
|
try { login = await (await fetch(backend + '/login', { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ username, password, code: '', uuid: '' }) })).json(); break }
|
||
|
|
catch (error) { if (attempt === 7) throw error; await new Promise(resolve => setTimeout(resolve, 750)) }
|
||
|
|
}
|
||
|
|
assert.equal(login.code, 200)
|
||
|
|
fs.mkdirSync(out, { recursive: true })
|
||
|
|
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: base }])
|
||
|
|
const page = await context.newPage(), errors = [], writes = []
|
||
|
|
page.setDefaultTimeout(15000)
|
||
|
|
page.on('pageerror', error => errors.push(error.message))
|
||
|
|
let stockEmpty = true, stockGate = null, releaseStock
|
||
|
|
const stockRows = Array.from({ length: 60 }, (_, i) => ({ id: 990100 + i, projectId: 1, productId: 990300 + i, projectName: '布局回归项目', areaId: 1, areaName: '布局库区', productName: '布局测试物品 ' + i, brand: '品牌', spec: '规格 ' + i, unit: '个', stockNum: 100 + i, averageUnitCost: 10, stockAmount: 1000, finishedProduct: false }))
|
||
|
|
const receiptRows = [{ id: 990500, inNo: 'RK-UI-1', inStatus: 0, inNum: 5, sourceProjectId: 1, sourceProjectName: '布局回归项目', productId: 990300, productName: '分组待入库物品', spec: 'S-1', unit: '个' }]
|
||
|
|
await page.route('**/dev-api/**', async route => {
|
||
|
|
const req = route.request(), url = new URL(req.url()), path = url.pathname
|
||
|
|
if (!['GET', 'HEAD'].includes(req.method())) { writes.push(path); return route.abort('blockedbyclient') }
|
||
|
|
if (path === '/dev-api/warehouse/stock/list') {
|
||
|
|
if (stockGate) await stockGate
|
||
|
|
return route.fulfill({ json: { code: 200, total: stockEmpty ? 0 : 60, rows: stockEmpty ? [] : stockRows } })
|
||
|
|
}
|
||
|
|
if (path === '/dev-api/warehouse/in/pending-groups') return route.fulfill({ json: { code: 200, data: { total: 1, itemTotal: 1, rows: [{ key: 'B:990700', title: '布局采购批次', projects: '布局回归项目', supplierName: '测试供应商', recordCount: 1 }] } } })
|
||
|
|
if (path.startsWith('/dev-api/warehouse/in/pending-groups/')) return route.fulfill({ json: { code: 200, data: receiptRows } })
|
||
|
|
if (path === '/dev-api/warehouse/in/list') return route.fulfill({ json: { code: 200, total: 1, rows: receiptRows } })
|
||
|
|
return route.continue()
|
||
|
|
})
|
||
|
|
const container = () => page.locator('.desktop-viewport .business-list-page').first()
|
||
|
|
async function ready() {
|
||
|
|
await container().waitFor()
|
||
|
|
await page.waitForFunction(() => ![...document.querySelectorAll('.desktop-viewport .el-loading-mask')].some(el => el.getClientRects().length))
|
||
|
|
await page.waitForTimeout(100)
|
||
|
|
}
|
||
|
|
const navigate = path => page.locator('.desktop-viewport').evaluate((el, path) => el.__vueParentComponent.proxy.$router.push(path), path)
|
||
|
|
const geometry = () => container().evaluate(el => {
|
||
|
|
const table = el.querySelector('.business-list-page__table > .el-table'), content = el.querySelector('.business-list-page__content'), footer = el.querySelector('.business-list-page__footer')
|
||
|
|
return { table: table.getBoundingClientRect().height, content: content.getBoundingClientRect().height, bottom: footer.getBoundingClientRect().bottom, height: innerHeight, documentHeight: document.documentElement.scrollHeight, pageOverflow: el.scrollHeight - el.clientHeight }
|
||
|
|
})
|
||
|
|
const storage = () => page.evaluate(() => Object.fromEntries(Object.keys(localStorage).filter(key => key.startsWith('business-columns:')).map(key => [key, JSON.parse(localStorage.getItem(key))])))
|
||
|
|
const header = name => container().locator('.el-table__header-wrapper').first().getByRole('columnheader', { name, exact: true })
|
||
|
|
async function columns() {
|
||
|
|
await container().getByRole('button', { name: '列设置', exact: true }).click()
|
||
|
|
const menu = page.locator('.el-popover:visible').filter({ has: page.getByRole('button', { name: '恢复默认', exact: true }) })
|
||
|
|
await menu.waitFor(); await page.waitForTimeout(180)
|
||
|
|
return menu
|
||
|
|
}
|
||
|
|
|
||
|
|
await page.goto(base + '/warehouse/stock'); await ready()
|
||
|
|
const emptyHeight = await geometry()
|
||
|
|
stockGate = new Promise(resolve => { releaseStock = resolve })
|
||
|
|
await container().getByRole('button', { name: '搜索', exact: true }).click()
|
||
|
|
await container().locator('.el-loading-mask:visible').waitFor()
|
||
|
|
const loadingHeight = await geometry()
|
||
|
|
stockEmpty = false; releaseStock(); stockGate = null
|
||
|
|
await container().locator('.product-name').filter({ hasText: '布局测试物品 0' }).waitFor(); await ready()
|
||
|
|
const populatedHeight = await geometry()
|
||
|
|
await page.screenshot({ path: path.join(out, 'stock-1366-populated.png'), animations: 'disabled' })
|
||
|
|
assert.ok(emptyHeight.table > 250)
|
||
|
|
assert.ok(Math.abs(emptyHeight.table - loadingHeight.table) <= 2)
|
||
|
|
assert.ok(Math.abs(emptyHeight.table - populatedHeight.table) <= 2, JSON.stringify({ emptyHeight, populatedHeight }))
|
||
|
|
console.log('PASS empty/loading/populated stock table reserves a stable viewport')
|
||
|
|
|
||
|
|
const selection = await container().locator('.business-list-page__table > .el-table').evaluate(el => {
|
||
|
|
let table = el.__vueParentComponent
|
||
|
|
while (table && table.type.name !== 'BusinessTable') table = table.parent
|
||
|
|
let owner = table.parent
|
||
|
|
while (owner && !owner.proxy?.stockList) owner = owner.parent
|
||
|
|
table.exposed.toggleRowSelection(owner.proxy.stockList[0], true)
|
||
|
|
const selected = table.exposed.getSelectionRows().length
|
||
|
|
table.exposed.clearSelection()
|
||
|
|
return { selected, cleared: table.exposed.getSelectionRows().length, api: typeof table.exposed.toggleRowExpansion }
|
||
|
|
})
|
||
|
|
assert.deepEqual(selection, { selected: 1, cleared: 0, api: 'function' })
|
||
|
|
await container().locator('.el-table__body-wrapper .el-checkbox').first().click()
|
||
|
|
assert.equal(await container().getByRole('button', { name: '批量操作', exact: true }).isEnabled(), true)
|
||
|
|
console.log('PASS table selection events and public ref methods are preserved')
|
||
|
|
|
||
|
|
let menu = await columns()
|
||
|
|
await page.screenshot({ path: path.join(out, 'stock-column-settings.png'), animations: 'disabled' })
|
||
|
|
await menu.locator('.el-checkbox').filter({ hasText: '平均单价' }).click()
|
||
|
|
await container().getByRole('button', { name: '列设置', exact: true }).click()
|
||
|
|
assert.equal(await header('平均单价').count(), 0)
|
||
|
|
const cell = header('所属项目'), oldBox = await cell.boundingBox()
|
||
|
|
await page.mouse.move(oldBox.x + oldBox.width - 2, oldBox.y + oldBox.height / 2)
|
||
|
|
await page.mouse.down(); await page.mouse.move(oldBox.x + oldBox.width + 88, oldBox.y + oldBox.height / 2, { steps: 12 }); await page.mouse.up()
|
||
|
|
await page.waitForTimeout(150)
|
||
|
|
const settings = await storage(), stockKey = Object.keys(settings).find(key => settings[key].projectName?.width)
|
||
|
|
assert.ok(stockKey, 'Dragging the column border must persist a width')
|
||
|
|
assert.ok(settings[stockKey].projectName.width > oldBox.width + 50)
|
||
|
|
await page.reload(); await ready()
|
||
|
|
assert.equal(await header('平均单价').count(), 0)
|
||
|
|
assert.ok(Math.abs((await header('所属项目').boundingBox()).width - settings[stockKey].projectName.width) <= 2)
|
||
|
|
await navigate('/businessBasics/area'); await ready()
|
||
|
|
assert.equal(await header('库区名称').count(), 1)
|
||
|
|
const other = await columns()
|
||
|
|
assert.equal(await other.getByRole('checkbox', { name: '库区名称', exact: true }).isChecked(), true)
|
||
|
|
await container().getByRole('button', { name: '列设置', exact: true }).click()
|
||
|
|
await navigate('/warehouse/stock'); await ready()
|
||
|
|
assert.equal(await header('平均单价').count(), 0)
|
||
|
|
menu = await columns(); await menu.getByRole('button', { name: '恢复默认', exact: true }).click()
|
||
|
|
await container().getByRole('button', { name: '列设置', exact: true }).click()
|
||
|
|
await header('平均单价').waitFor()
|
||
|
|
assert.deepEqual((await storage())[stockKey], {})
|
||
|
|
console.log('PASS column visibility/real mouse resize persist, stay page-scoped, and reset to defaults')
|
||
|
|
|
||
|
|
const densities = []
|
||
|
|
for (const [label, value] of [['紧凑', 'small'], ['宽松', 'large'], ['标准', 'default']]) {
|
||
|
|
await page.locator('#size-select').click(); await page.getByRole('menuitem', { name: label, exact: true }).click()
|
||
|
|
await page.waitForFunction(value => document.documentElement.dataset.density === value, value)
|
||
|
|
await page.waitForTimeout(100)
|
||
|
|
const data = await container().locator('.business-list-page__table > .el-table').evaluate(el => {
|
||
|
|
const row = el.querySelector('.el-table__body tr'), wrap = el.querySelector('.el-table__body-wrapper .el-scrollbar__wrap')
|
||
|
|
wrap.scrollLeft = wrap.scrollWidth
|
||
|
|
wrap.scrollTop = wrap.scrollHeight
|
||
|
|
return { row: row.getBoundingClientRect().height, font: getComputedStyle(el).fontSize, horizontal: wrap.scrollLeft, vertical: wrap.scrollTop }
|
||
|
|
})
|
||
|
|
densities.push(data)
|
||
|
|
assert.ok(data.horizontal > 0, label + ' horizontal scrolling')
|
||
|
|
assert.ok(data.vertical > 0, label + ' vertical table scrolling')
|
||
|
|
}
|
||
|
|
assert.ok(densities[1].row > densities[0].row)
|
||
|
|
console.log('PASS all three densities and independent horizontal/vertical table scrolling')
|
||
|
|
|
||
|
|
await navigate('/warehouse/pending?sourceGroup=B%3A990700'); await ready()
|
||
|
|
await container().getByText('分组待入库物品').waitFor()
|
||
|
|
assert.equal(await container().locator('.el-table__expanded-cell').count(), 1)
|
||
|
|
await container().locator('.el-table__expanded-cell .el-checkbox').last().click()
|
||
|
|
assert.equal(await container().getByRole('button', { name: '批量入库', exact: true }).first().isEnabled(), true)
|
||
|
|
await container().locator('.el-table__expand-icon').first().click()
|
||
|
|
assert.equal(await container().locator('.el-table__expanded-cell').count(), 0)
|
||
|
|
await container().locator('.el-table__expand-icon').first().click()
|
||
|
|
await container().getByText('分组待入库物品').waitFor()
|
||
|
|
console.log('PASS pending-receipt grouping, automatic ref expansion and nested selection')
|
||
|
|
|
||
|
|
const routes = ['/warehouse/stock', '/warehouse/inRecord', '/warehouse/outRecord', '/warehouse/stockCheck', '/businessBasics/area', '/businessBasics/product', '/project/info']
|
||
|
|
for (const width of [1366, 1920]) {
|
||
|
|
await page.setViewportSize({ width, height: 900 })
|
||
|
|
for (const route of routes) {
|
||
|
|
await navigate(route); await ready()
|
||
|
|
const metrics = await geometry()
|
||
|
|
assert.ok(metrics.table > 100, route + ': ' + JSON.stringify(metrics))
|
||
|
|
assert.ok(metrics.bottom <= metrics.height + 2, route + ': footer outside viewport ' + JSON.stringify(metrics))
|
||
|
|
assert.ok(metrics.documentHeight <= metrics.height + 2, route + ': document scrolls ' + JSON.stringify(metrics))
|
||
|
|
assert.ok(metrics.pageOverflow <= 2, route + ': page overflow ' + JSON.stringify(metrics))
|
||
|
|
if (route === '/warehouse/stock') await page.screenshot({ path: path.join(out, 'stock-' + width + '.png'), animations: 'disabled' })
|
||
|
|
if (width === 1366 && route === '/warehouse/inRecord') await page.screenshot({ path: path.join(out, 'in-record-1366.png'), animations: 'disabled' })
|
||
|
|
}
|
||
|
|
}
|
||
|
|
assert.deepEqual(errors, [])
|
||
|
|
assert.deepEqual(writes, [])
|
||
|
|
console.log('PASS seven list pages fit 1366px/1920px viewports; no business writes or runtime errors')
|
||
|
|
} finally { await browser.close() }
|
||
|
|
})().catch(error => { console.error(error); process.exitCode = 1 })
|