139 lines
10 KiB
JavaScript
139 lines
10 KiB
JavaScript
|
|
const assert = require('node:assert/strict')
|
|||
|
|
const { chromium } = require('./vue3-test-runtime.cjs')
|
|||
|
|
const base = process.env.VUE3_URL || 'http://127.0.0.1:8088'
|
|||
|
|
const delay = ms => new Promise(resolve => setTimeout(resolve, ms))
|
|||
|
|
|
|||
|
|
;(async () => {
|
|||
|
|
const browser = await chromium.launch({ headless: true })
|
|||
|
|
const errors = [], writes = [], purchaseQueries = [], batchRequests = []
|
|||
|
|
let accepted = false
|
|||
|
|
try {
|
|||
|
|
const context = await browser.newContext({ viewport: { width: 412, height: 900 } })
|
|||
|
|
const page = await context.newPage()
|
|||
|
|
page.setDefaultTimeout(12000)
|
|||
|
|
page.on('pageerror', error => errors.push(error.message))
|
|||
|
|
await page.goto(base + '/login?redirect=/mobile')
|
|||
|
|
await page.getByPlaceholder('账号').fill(process.env.TEST_USERNAME || 'admin')
|
|||
|
|
await page.getByPlaceholder('密码', { exact: true }).fill(process.env.TEST_PASSWORD || 'admin123')
|
|||
|
|
await page.waitForFunction(() => !document.querySelector('input[placeholder="验证码"]'))
|
|||
|
|
await page.getByRole('button', { name: /登\s*录/ }).click()
|
|||
|
|
await page.locator('.mobile-app').waitFor()
|
|||
|
|
|
|||
|
|
const purchases = [
|
|||
|
|
{ id: 970001, materialName: '已到齐待验收物品', projectName: '测试项目', purchaseBatchNo: 'CG2610001', quantity: 3, remainingQuantity: 0, pendingArrivalQuantity: 3, purchaseStatus: 4, priceLocked: true, unit: '件' },
|
|||
|
|
{ id: 970002, materialName: '尚未到货物品', projectName: '测试项目', purchaseBatchNo: 'CG2610002', quantity: 4, remainingQuantity: 4, pendingArrivalQuantity: 0, purchaseStatus: 1, priceLocked: true, unit: '件' }
|
|||
|
|
]
|
|||
|
|
await context.route('**/dev-api/**', async route => {
|
|||
|
|
const request = route.request(), url = new URL(request.url()), pathname = url.pathname
|
|||
|
|
const reply = data => route.fulfill({ json: { code: 200, ...data } })
|
|||
|
|
// Only this in-memory acceptance is permitted. All other business writes are blocked.
|
|||
|
|
if (request.method() === 'PUT' && pathname === '/dev-api/warehouse/purchase/arrival/980001/accept') {
|
|||
|
|
writes.push({ path: pathname, data: request.postDataJSON() }); accepted = true
|
|||
|
|
return reply({ data: null })
|
|||
|
|
}
|
|||
|
|
if (!['GET', 'HEAD'].includes(request.method())) {
|
|||
|
|
writes.push({ blocked: true, path: pathname })
|
|||
|
|
return route.abort('blockedbyclient')
|
|||
|
|
}
|
|||
|
|
if (pathname === '/dev-api/warehouse/stock/list') return reply({ rows: [{ id: 960001, productName: '测试库存', stockNum: 5, unit: '件' }], total: 1 })
|
|||
|
|
if (pathname === '/dev-api/warehouse/in/list') return reply({ rows: [{ id: 960002, productName: '测试待入库', inStatus: 0, inNum: 5, unit: '件' }], total: 1 })
|
|||
|
|
if (pathname === '/dev-api/warehouse/suppliers') return reply({ data: [{ id: 990001, name: '测试供应商甲' }, { id: 990002, name: '测试供应商乙' }] })
|
|||
|
|
if (pathname === '/dev-api/warehouse/purchase/list') {
|
|||
|
|
purchaseQueries.push(Object.fromEntries(url.searchParams))
|
|||
|
|
return reply({ rows: purchases.map(row => row.id === 970001 && accepted ? { ...row, pendingArrivalQuantity: 0, acceptedQuantity: 3 } : row), total: 2 })
|
|||
|
|
}
|
|||
|
|
if (pathname === '/dev-api/warehouse/purchase/arrival/970001') return reply({ data: [{ id: 980001, arrivalNo: 'DH2610001', arrivalQuantity: 3, acceptanceStatus: accepted ? 1 : 0 }] })
|
|||
|
|
if (pathname === '/dev-api/warehouse/batch/list') return reply({ rows: [{ id: 950001, jobNo: '任务 A', status: 1 }, { id: 950002, jobNo: '任务 B', status: 2 }], total: 2 })
|
|||
|
|
const match = pathname.match(/^\/dev-api\/warehouse\/batch\/(95000[123])(\/items)?$/)
|
|||
|
|
if (match) {
|
|||
|
|
const id = Number(match[1]), items = !!match[2]
|
|||
|
|
batchRequests.push({ id, items })
|
|||
|
|
await delay(id === 950002 ? 30 : 650)
|
|||
|
|
return reply(items ? { data: [{ id: id * 10, productName: id === 950002 ? 'B 的明细' : 'A 的明细', rowNo: 1, status: 1 }] } : { data: { id, jobNo: id === 950002 ? '任务 B' : '迟到的任务 A', status: id === 950003 ? 2 : 1 } })
|
|||
|
|
}
|
|||
|
|
return route.continue()
|
|||
|
|
})
|
|||
|
|
const vm = (selector, code, args) => page.locator(selector).first().evaluate((el, { code, args }) => Function('v', 'args', 'return (' + code + ')(v,args)')(el.__vueParentComponent.proxy, args), { code, args })
|
|||
|
|
|
|||
|
|
for (const [tab, label, list, selected, load, busy] of [
|
|||
|
|
['stock', '选择本条库存', 'stockList', 'selectedStockIds', 'loadStock', 'stockLoading'],
|
|||
|
|
['in', '选择本条待入库', 'inList', 'selectedInIds', 'loadInRecords', 'inLoading']
|
|||
|
|
]) {
|
|||
|
|
await vm('.mobile-app', '(v, tab) => v.switchTab(tab)', tab)
|
|||
|
|
await page.waitForFunction(({ list, busy }) => { const v = document.querySelector('.mobile-app').__vueParentComponent.proxy; return v[list].length === 1 && !v[busy] }, { list, busy })
|
|||
|
|
const checkbox = page.getByRole('checkbox', { name: label, exact: true })
|
|||
|
|
await page.getByText(label, { exact: true }).click()
|
|||
|
|
assert.equal(await vm('.mobile-app', '(v, key) => v[key].length', selected), 1)
|
|||
|
|
await vm('.mobile-app', '(v, method) => v[method](true)', load)
|
|||
|
|
await page.waitForFunction(({ busy }) => !document.querySelector('.mobile-app').__vueParentComponent.proxy[busy], { busy })
|
|||
|
|
assert.equal(await checkbox.isChecked(), false)
|
|||
|
|
assert.equal(await vm('.mobile-app', '(v, key) => v[key].length', selected), 0)
|
|||
|
|
}
|
|||
|
|
console.log('PASS mobile stock / receipt checkbox UI and selected state reset together')
|
|||
|
|
|
|||
|
|
await vm('.mobile-app', 'v => v.switchTab("purchase")')
|
|||
|
|
await page.locator('.mobile-purchase-module').waitFor()
|
|||
|
|
await page.waitForFunction(() => { const v = document.querySelector('.mobile-purchase-module').__vueParentComponent.proxy; return v.list.length === 2 && !v.loading })
|
|||
|
|
await page.getByText('选择本条采购', { exact: true }).first().click()
|
|||
|
|
const arrivalButton = page.getByRole('button', { name: '批量到货(0)', exact: true })
|
|||
|
|
assert.equal(await arrivalButton.isDisabled(), true)
|
|||
|
|
await page.getByRole('button', { name: '批量验收(1)', exact: true }).click()
|
|||
|
|
const acceptance = page.getByRole('dialog', { name: '批量验收', exact: true })
|
|||
|
|
await acceptance.waitFor()
|
|||
|
|
await acceptance.getByText('选择本条', { exact: true }).waitFor()
|
|||
|
|
const checkboxes = acceptance.getByRole('checkbox')
|
|||
|
|
assert.equal(await checkboxes.first().isChecked(), true)
|
|||
|
|
assert.equal(await checkboxes.nth(1).isChecked(), true)
|
|||
|
|
await checkboxes.first().locator('..').click()
|
|||
|
|
assert.equal(await acceptance.getByRole('button', { name: '确认本次验收', exact: true }).isDisabled(), true)
|
|||
|
|
await checkboxes.first().locator('..').click()
|
|||
|
|
await acceptance.locator('.el-input-number input').first().fill('1')
|
|||
|
|
await acceptance.locator('.el-input-number input').first().blur()
|
|||
|
|
await acceptance.getByRole('button', { name: '确认本次验收', exact: true }).click()
|
|||
|
|
await acceptance.getByText('已验收 3', { exact: true }).waitFor()
|
|||
|
|
assert.equal(writes.length, 1)
|
|||
|
|
assert.equal(writes[0].data.defectiveQuantity, 1)
|
|||
|
|
assert.equal(writes[0].blocked, undefined)
|
|||
|
|
await acceptance.getByRole('button', { name: '关闭', exact: true }).click()
|
|||
|
|
console.log('PASS zero remaining purchase accepts existing arrival; all-select and partial rejection; no duplicate arrival')
|
|||
|
|
|
|||
|
|
await page.getByText('选择本条采购', { exact: true }).click()
|
|||
|
|
await page.locator('.mobile-purchase-module .business-embedded-panel .el-select').first().click()
|
|||
|
|
await page.getByRole('option', { name: '测试供应商乙', exact: true }).click()
|
|||
|
|
await page.waitForFunction(() => !document.querySelector('.mobile-purchase-module').__vueParentComponent.proxy.loading)
|
|||
|
|
assert.equal(purchaseQueries.at(-1).supplierId, '990002')
|
|||
|
|
assert.equal(await vm('.mobile-purchase-module', 'v => v.selectedIds.length'), 0)
|
|||
|
|
assert.equal(await page.getByRole('checkbox', { name: '选择本条采购', exact: true }).isChecked(), false)
|
|||
|
|
console.log('PASS supplier Vue3 update event filters immediately and clears stale selection')
|
|||
|
|
|
|||
|
|
await vm('.mobile-app', 'v => v.switchTab("batch")')
|
|||
|
|
await vm('.mobile-app', 'v => v.selectBatchJob({id:950001,jobNo:"任务 A",status:1})')
|
|||
|
|
await delay(60)
|
|||
|
|
await vm('.mobile-app', 'v => v.selectBatchJob({id:950002,jobNo:"任务 B",status:2})')
|
|||
|
|
await delay(850)
|
|||
|
|
const mobileBatch = await vm('.mobile-app', 'v => ({ id:v.batch.currentJob.id, name:v.batch.currentJob.jobNo, item:v.batch.items[0].productName, polling:!!v.batch.pollTimer })')
|
|||
|
|
assert.deepEqual(mobileBatch, { id: 950002, name: '任务 B', item: 'B 的明细', polling: false })
|
|||
|
|
await vm('.mobile-app', 'v => v.selectBatchJob({id:950003,jobNo:"离开前任务",status:1})')
|
|||
|
|
await vm('.mobile-app', 'v => v.switchTab("home")')
|
|||
|
|
await delay(850)
|
|||
|
|
assert.deepEqual(await vm('.mobile-app', 'v => ({name:v.batch.currentJob.jobNo,items:v.batch.items.length,polling:!!v.batch.pollTimer,active:v.batch.active})'), { name: '离开前任务', items: 0, polling: false, active: false })
|
|||
|
|
console.log('PASS mobile batch task switch and leaving module reject late responses')
|
|||
|
|
|
|||
|
|
await page.setViewportSize({ width: 1366, height: 900 })
|
|||
|
|
await page.goto(base + '/warehouse/batch-import')
|
|||
|
|
await page.locator('.batch-page').waitFor()
|
|||
|
|
await vm('.batch-page', 'v => v.selectJob({id:950001,jobNo:"任务 A",status:1})')
|
|||
|
|
await delay(60)
|
|||
|
|
await vm('.batch-page', 'v => v.selectJob({id:950002,jobNo:"任务 B",status:2})')
|
|||
|
|
await delay(850)
|
|||
|
|
assert.deepEqual(await vm('.batch-page', 'v => ({id:v.currentJob.id,name:v.currentJob.jobNo,item:v.items[0].productName,polling:!!v.pollTimer})'), { id: 950002, name: '任务 B', item: 'B 的明细', polling: false })
|
|||
|
|
await vm('.batch-page', 'v => {window.__batchRegression=v;v.selectJob({id:950003,jobNo:"离开前任务",status:1});return v.$router.push("/index")}')
|
|||
|
|
await page.locator('.business-home').waitFor()
|
|||
|
|
await delay(850)
|
|||
|
|
assert.deepEqual(await page.evaluate(() => { const v = window.__batchRegression; return { name: v.currentJob.jobNo, items: v.items.length, polling: !!v.pollTimer, active: v.pageActive } }), { name: '离开前任务', items: 0, polling: false, active: false })
|
|||
|
|
console.log('PASS desktop batch task / detail coherence and cached page polling cleanup')
|
|||
|
|
assert.deepEqual(errors, [])
|
|||
|
|
console.log('PASS mobile / import regressions; one mocked acceptance and zero real business writes')
|
|||
|
|
} finally { await browser.close() }
|
|||
|
|
})().catch(error => { console.error(error); process.exitCode = 1 })
|