cmvr-wms/scripts/projectdev/vue3-production-flow-regression.cjs
lixiaolong e78ed25668 refactor(components): 优化组件交互和数据验证逻辑
- 为对话框添加防止意外关闭的安全措施
- 实现表单提交时的数据有效性验证
- 集成远程选择器组件提升用户体验
- 更新表格组件样式适配新设计规范
- 优化列表页面加载和错误处理机制
- 统一组件尺寸设置和存储管理
2026-10-14 09:11:33 +08:00

365 lines
30 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

const assert = require('node:assert/strict')
const fs = require('node:fs')
const path = require('node:path')
const { chromium, frontend } = require('./vue3-test-runtime.cjs')
;(async () => {
const browser = await chromium.launch()
const writes = [], reads = [], errors = [], blocked = [], checks = []
const out = path.resolve(__dirname, '../../.codex-tmp/vue3-production-flow')
fs.mkdirSync(out, { recursive: true })
const item = { id: 900, productName: '流程模拟机器人', brand: '内部', spec: 'R1', unit: '台', category: '整机' }
const material = { id: 101, productName: '流程模拟电机', brand: '内部', spec: 'M1', unit: '个', category: '机电' }
const stock = { id: 501, projectId: 1, projectName: '模拟项目甲', productId: 101, productName: material.productName, brand: '内部', spec: 'M1', unit: '个', areaId: 1, areaName: '库区甲', stockNum: 40, finishedProduct: false }
const finished = { ...stock, id: 503, productId: 900, productName: item.productName, spec: 'R1', unit: '台', stockNum: 3, finishedProduct: true }
const stocks = [stock, { ...stock, id: 502, productId: 102, productName: '无关物品' }, finished, { ...stock, id: 504, projectId: 2, projectName: '模拟项目乙', areaId: 2, areaName: '库区乙' }]
let product, bom, task, receipt, loan, failReturn = true, failAction = true, failLoans = false, failHistory = false, failCost = true, failBatchReturn = true, failStockOperation = true, failWithdrawal = true
const failSaves=new Set(['/production/product','/production/bom','/production/tasks'])
const tick = ms => new Promise(resolve => setTimeout(resolve, ms))
try {
const context = await browser.newContext({ viewport: { width: 1366, height: 768 } })
await context.route('**/dev-api/**', async route => {
const req = route.request(), url = new URL(req.url()), p = url.pathname.replace('/dev-api', ''), q = url.searchParams
const json = data => route.fulfill({ json: { code: 200, data } })
const rows = data => route.fulfill({ json: { code: 200, rows: data, total: data.length } })
if (req.method() === 'GET') {
reads.push(p)
if (p === '/captchaImage') return route.fulfill({ json: { code: 200, captchaEnabled: false } })
if (p === '/project/info/options') return json([{ id: 1, projectName: '模拟项目甲' }, { id: 2, projectName: '模拟项目乙' }])
if (p === '/warehouse/area/optionselect') return json([{ id: 1, areaName: '库区甲' }, { id: 2, areaName: '库区乙' }])
if (p === '/production/product/list') return rows(product ? [product] : [])
if (p === '/production/product/options-page') return rows(product ? [product] : [])
if (p === '/production/bom/items-page') return rows([item, material])
if (p === '/production/bom/options') return json(bom && Number(q.get('itemId')) === 900 ? [bom] : [])
if (p === '/production/bom/91') return json(bom)
if (p === '/production/product/project/1') return json(product && bom ? [{ ...product, bomId: bom.id }] : [])
if (p === '/production/tasks/page') return json({ rows: task ? [task] : [], total: task ? 1 : 0 })
if (p === '/production/tasks/700') return json(task)
if (p === '/production/tasks/actions/page') { if(failHistory){failHistory=false;return route.fulfill({json:{code:500,msg:'模拟追溯列表失败'}})} return json({ rows: task?.actions || [], total: task?.actions.length || 0 }) }
if (p === '/production/tasks/cost-history') {
if(q.get('itemId')==='901' && failCost){failCost=false;return route.fulfill({json:{code:500,msg:'模拟成本查询失败'}})}
await tick(150);return json([{id:700,status:'SETTLED',item_name:item.productName,material_recorded:1,material_cost:60,unit_cost:30,good_quantity:2,project_name:'模拟项目甲'}])
}
if (p === '/production/tasks/product-totals/1') return json([])
if (p === '/warehouse/in/list') return rows(receipt ? [receipt] : [])
if (p === '/warehouse/in/801') return json(receipt)
if (p === '/warehouse/stock/list') {
if (q.get('productName') === 'slow') await tick(180)
return rows(stocks.filter(s => (!q.get('projectId') || s.projectId === Number(q.get('projectId'))) && (!q.get('productId') || s.productId === Number(q.get('productId'))) && (!q.get('excludeProjectId') || s.projectId !== Number(q.get('excludeProjectId')))))
}
if (p === '/project/loans') {
if (failLoans) { failLoans = false; return route.fulfill({ json: { code: 500, msg: '模拟借还列表失败' } }) }
const projectId = Number(q.get('projectId'))
await tick(projectId === 1 ? 150 : 10)
return rows(loan ? [{ ...loan, remark: '项目' + projectId }] : [])
}
if (p === '/project/loans/800/returns') return json([{ returnType: 'STOCK', quantity: 1, amount: 5, active: true, businessKey: 'mock-return' }])
// No real authenticated reads or writes can escape this isolated fixture.
if (p.startsWith('/system/dict/data/type/')) return json([])
blocked.push('GET ' + p); return route.abort('blockedbyclient')
}
const data = req.postData() ? req.postDataJSON() : undefined
writes.push({ method: req.method(), path: p, data })
if(failSaves.delete(p)){await tick(100);return route.fulfill({json:{code:500,msg:'模拟保存失败,请重试'}})}
if (p === '/production/product') { await tick(100); product = { id: 901, itemId: 900, itemName: item.productName, ...data, brand: item.brand, spec: item.spec, unit: item.unit }; return json(product) }
if (p === '/production/bom') { await tick(100); bom = { ...data, id: 91, itemName: item.productName, version: 1 }; return json(bom) }
if (p === '/production/tasks') {
await tick(100); task = { id: 700, task_no: 'SC2610001', project_id: data.projectId, project_name: '模拟项目甲', item_id: data.itemId, item_name: item.productName, bom_id: data.bomId, status: 'OPEN', version: 1, planned_quantity: data.quantity, good_quantity: 0, scrap_quantity: 0, needs: [{ itemId: 101, required: 6, issued: 0, returned: 0, scrapped: 0, available: 40 }], actions: [] }; return json(task)
}
if (p === '/production/tasks/actions') {
await tick(120)
if (data.remark === 'retry' && failAction) { failAction = false; return route.fulfill({ json: { code: 500, msg: '模拟生产操作失败' } }) }
if (data.remark === 'batch-retry' && data.itemId === 102 && failStockOperation) { failStockOperation = false; return route.fulfill({ json: { code: 500, msg: '模拟批量第二项失败' } }) }
const action = { ...data, id: 1000 + task.actions.length, project_id: data.projectId, item_id: data.itemId, area_id: data.areaId, task_id: data.taskId, active: true, handled_quantity: 0 }
task.actions.push(action)
if (data.kind === 'COMPLETE') { task.good_quantity += data.quantity; receipt = { id: 801, receiptRoot: true, productId: 900, productName: item.productName, unit: '台', sourceProjectName: '模拟项目甲', inNum: data.quantity, inStatus: 0 } }
return json(action)
}
if (p === '/warehouse/in/receive/801') { await tick(100); receipt.inStatus = 1; return json(receipt) }
if (p === '/production/tasks/700/settle') { await tick(100); task.status = 'SETTLED'; task.version++; return json(task) }
if (p === '/production/tasks/700/reopen') { await tick(100); task.status = 'OPEN'; task.version++; return json(task) }
if (p === '/warehouse/withdrawals') {
await tick(180)
if (failWithdrawal) { failWithdrawal = false; return route.fulfill({ json: { code: 500, msg: '模拟后续库存业务未撤销,请先处理后续记录' } }) }
return json({ id: 1 })
}
if (p === '/warehouse/stock/move') return json({id:1})
if (p === '/project/loans') { await tick(100); loan = { id: 800, lenderProjectId: data.lenderProjectId, borrowerProjectId: data.borrowerProjectId, itemId: data.itemId, originalAreaId: data.fromAreaId, active: true, quantity: data.quantity, returnedQuantity: 0, outstandingQuantity: data.quantity, lenderProjectName: '模拟项目甲', borrowerProjectName: '模拟项目乙', itemName: material.productName }; return json(loan) }
if (p === '/project/loans/800/return') { await tick(100); if (failReturn) { failReturn = false; return route.fulfill({ json: { code: 500, msg: '模拟归还失败' } }) } loan.returnedQuantity += data.quantity; loan.outstandingQuantity -= data.quantity; return json(loan) }
if (['/project/loans/810/return','/project/loans/811/return'].includes(p)) {await tick(100);if(p.includes('/811/')&&failBatchReturn){failBatchReturn=false;return route.fulfill({json:{code:500,msg:'模拟第二笔归还失败'}})}return json({id:Number(p.split('/')[3])})}
blocked.push(req.method() + ' ' + p); return route.abort('blockedbyclient')
})
const page = await context.newPage()
page.setDefaultTimeout(12000)
page.on('pageerror', error => errors.push(error.message))
await page.goto(frontend + '/login')
await page.evaluate(async () => {
const { createApp, h, ElementPlus, nextTick } = await import('/tests/browser-runtime.js')
const { default: store } = await import('/src/store/index.js'), { default: useUser } = await import('/src/store/modules/user.js')
const { default: business } = await import('/src/plugins/business.js'), { default: Pagination } = await import('/src/components/Pagination/index.vue')
useUser(store).permissions = ['*:*:*']; document.querySelector('#app')?.remove(); window.messages = []
window.mountFlow = async (path, props = {}) => {
window.flowApp?.unmount(); document.getElementById('flow')?.remove()
const el = document.createElement('div'); el.id = 'flow'; el.style.height = '100vh'; document.body.append(el)
const Component = (await import(path)).default
const app = createApp({ render: () => h(Component, { ...props, ref: 'child' }) })
app.use(store); app.use(ElementPlus); business(app); app.component('Pagination', Pagination)
Object.assign(app.config.globalProperties, { $route: { path: '/flow', fullPath: '/flow', query: {} }, parseTime: () => '2026-10-14', $auth: { hasPermi: () => true }, $modal: { msgSuccess: text => window.messages.push(text), msgWarning: text => window.messages.push(text), msgError: text => window.messages.push(text), confirm: (...args) => app.config.globalProperties.$confirm(...args) }, download() {} })
window.flowApp = app; window.flowRoot = app.mount(el); await nextTick(); window.vm = window.flowRoot.$refs.child
}
})
const record = name => { checks.push(name); console.log('PASS ' + name) }
await page.evaluate(() => window.mountFlow('/src/views/production/product/index.vue'))
await page.getByRole('button', { name: '新增', exact: true }).click()
await page.locator('.el-dialog:visible .el-select').click()
await page.locator('.el-select-dropdown:visible .el-select-dropdown__item').filter({ hasText: item.productName }).click()
await page.evaluate(() => { window.vm.save(); window.vm.save() })
await page.waitForFunction(()=>!window.vm.saving)
assert.equal(await page.evaluate(()=>window.vm.open&&window.vm.form.itemId===900),true)
await page.evaluate(() => { window.vm.save(); window.vm.save() })
await page.waitForFunction(() => !window.vm.open && window.vm.rows.length === 1)
assert.equal(writes.filter(r => r.path === '/production/product').length, 2)
record('产品选择已有物品,保存失败保留并可立即重试、双击只提交一次')
await page.evaluate(() => window.mountFlow('/src/components/BomEditor/index.vue'))
await page.evaluate(item => window.vm.open({ item, makeDefault: true }), item)
await page.locator('.el-dialog:visible .el-form-item').filter({ hasText: '版本号' }).locator('input').fill('V1')
await page.getByRole('button', { name: '添加用料', exact: true }).click()
await page.locator('.el-dialog:visible .el-table .el-select').first().click()
await page.locator('.el-select-dropdown:visible .el-select-dropdown__item').filter({ hasText: material.productName }).click()
await page.evaluate(() => { window.vm.form.lines[0].unitQuantity = 2; window.vm.save(); window.vm.save() })
await page.waitForFunction(()=>!window.vm.saving)
assert.equal(await page.evaluate(()=>window.vm.visible&&window.vm.form.lines[0].unitQuantity===2),true)
await page.evaluate(() => { window.vm.save(); window.vm.save() })
await page.waitForFunction(() => !window.vm.visible)
assert.equal(bom.lines[0].itemId, 101); assert.equal(bom.lines[0].unitQuantity, 2); assert.equal(bom.isDefault, true)
assert.equal(writes.filter(r => r.path === '/production/bom').length, 2)
record('BOM用料自动带规格、默认版本及单台用量保存,失败保留草稿并重试')
await page.evaluate(() => window.mountFlow('/src/views/production/tasks/index.vue', { projectId: 1 }))
await page.evaluate(() => window.vm.edit())
await page.locator('.el-dialog:visible .el-form-item').filter({ hasText: '产品' }).locator('.el-select').click()
await page.locator('.el-select-dropdown:visible .el-select-dropdown__item').filter({ hasText: item.productName }).click()
await page.waitForFunction(() => !window.vm.bomLoading && window.vm.form.bomId === 91)
await page.evaluate(() => { window.vm.form.quantity = 3; window.vm.save(); window.vm.save() })
await page.waitForFunction(()=>!window.vm.saving)
const taskKey=await page.evaluate(()=>window.vm.form.key)
assert.equal(await page.evaluate(()=>window.vm.editOpen&&window.vm.form.quantity===3),true)
await page.evaluate(() => { window.vm.save(); window.vm.save() })
await page.waitForFunction(() => !window.vm.editOpen && window.vm.rows.length === 1)
const createdTasks=writes.filter(r => r.path === '/production/tasks')
assert.equal(createdTasks.length, 2);assert.equal(createdTasks[0].data.key,taskKey);assert.equal(createdTasks[1].data.key,taskKey)
assert.equal(task.bom_id, 91)
record('任务仅选产品并使用项目/默认BOM,失败立即重试保持业务标识,防重复创建')
await page.evaluate(() => window.mountFlow('/src/components/Production/ActionDialog.vue'))
await page.evaluate(task => window.vm.open('ISSUE', { task }), task)
assert.deepEqual(await page.evaluate(() => window.vm.stocks.map(s => s.productId)), [101])
await page.evaluate(() => { window.vm.stockId = 501; window.vm.selectStock(501); window.vm.form.quantity = 6; window.vm.form.remark = 'retry' })
await page.locator('.el-dialog:visible').getByRole('button', { name: '确认', exact: true }).click()
await page.waitForFunction(() => !window.vm.saving)
assert.equal(await page.evaluate(() => window.vm.visible), true)
const originalKey = await page.evaluate(() => window.vm.form.key)
await page.evaluate(() => { window.vm.save(); window.vm.save() })
await page.waitForFunction(() => !window.vm.visible)
const issueWrites = writes.filter(r => r.path === '/production/tasks/actions')
assert.equal(issueWrites.length, 2); assert.equal(issueWrites[1].data.key, originalKey)
record('生产领料排除非BOM/成品,失败保留数据与业务标识,立即重试与双击')
const perform = async (kind, context, changes = {}) => {
await page.evaluate(({ kind, context }) => window.vm.open(kind, context), { kind, context })
await page.evaluate(changes => Object.assign(window.vm.form, changes), { quantity: 1, ...changes })
await page.evaluate(() => window.vm.save())
await page.waitForFunction(() => !window.vm.visible)
}
const issue = { ...task.actions[0], item_name: material.productName }
await perform('RETURN', { source: issue }, { areaId: 1 })
await perform('SCRAP_ISSUED', { source: issue }, { reason: '损坏' })
await perform('COMPLETE', { task }, { quantity: 2 })
assert.equal(receipt.inNum, 2)
record('领料→部分退料/已领零件报废→完工验收→生成待入库')
await page.evaluate(() => window.mountFlow('/src/components/ReceiptDialog/index.vue'))
await page.evaluate(() => window.vm.open({ id: 801 }))
await page.locator('.el-dialog:visible').getByRole('button', { name: '确认入库', exact: true }).click()
assert.equal(writes.some(r => r.path === '/warehouse/in/receive/801'), false)
await page.evaluate(() => { window.vm.form.areaId = 1; window.vm.submit(); window.vm.submit() })
await page.waitForFunction(() => !window.vm.visible)
assert.equal(writes.filter(r => r.path === '/warehouse/in/receive/801').length, 1)
record('完工入库必须选择库区,双击不重复入库')
await page.evaluate(() => window.mountFlow('/src/components/Production/ActionDialog.vue'))
await page.evaluate(stock => window.vm.open('DELIVERY', { stock }), stock)
assert.equal(await page.evaluate(() => window.vm.visible), false)
await page.evaluate(stock => window.vm.open('DELIVERY', { stock }), finished)
const countBefore = writes.length
await page.evaluate(() => window.vm.save())
assert.equal(writes.length, countBefore, 'Missing recipient must be rejected before sending')
await page.evaluate(() => { window.vm.form.recipient = '模拟接收方'; window.vm.form.date = null; return window.vm.save() })
assert.equal(writes.length, countBefore, 'Missing business date must be rejected before sending')
await page.evaluate(() => { window.vm.form.date = '2026-10-14'; return window.vm.save() })
const delivery = { ...task.actions.at(-1), item_name: item.productName }
await perform('DELIVERY_RETURN', { source: delivery }, { quantity: 0.5, areaId: 2 })
await perform('SCRAP_FINISHED', { stock: finished }, { quantity: 0.5, reason: '损坏' })
await perform('SCRAP_ASSEMBLY', { task }, { quantity: 1, reason: '组装损坏' })
await perform('SCRAP_STOCK', { stock }, { quantity: 1, reason: '库存损坏' })
record('非成品禁止交付,接收方/日期校验;交付退回及三类报废入口/数量/原因')
await page.evaluate(() => window.mountFlow('/src/views/production/tasks/index.vue', { projectId: 1 }))
await page.evaluate(() => window.vm.show(700))
await page.evaluate(() => { window.vm.settle(); window.vm.settle() })
await page.getByRole('button', { name: '取消', exact: true }).last().click()
await page.waitForFunction(() => !window.vm.settling)
await page.locator('.el-message-box:visible').waitFor({ state: 'hidden' })
assert.equal(writes.some(r => r.path.endsWith('/settle')), false)
await page.evaluate(() => { window.vm.settle(); window.vm.settle() })
await page.locator('.el-message-box:visible').getByRole('button', { name: '结束并结算', exact: true }).click()
await page.waitForFunction(() => !window.vm.settling && window.vm.detail.status === 'SETTLED')
await page.evaluate(() => { window.vm.reopen(); window.vm.reopen() })
await page.locator('.el-message-box:visible').getByRole('button', { name: '继续生产', exact: true }).click()
await page.waitForFunction(() => !window.vm.settling && window.vm.detail.status === 'OPEN')
assert.equal(writes.filter(r => r.path.endsWith('/settle')).length, 1)
assert.equal(writes.filter(r => r.path.endsWith('/reopen')).length, 1)
record('结束生产有影响说明和取消;可恢复生产,重复点击无重复请求')
await page.evaluate(() => window.mountFlow('/src/components/ProjectLoans/index.vue', { embedded: true }))
await page.evaluate(() => window.vm.open({ id: 2, projectName: '模拟项目乙' }))
await page.evaluate(() => window.vm.openBorrow())
await page.evaluate(() => { window.vm.form.stockId = 501; window.vm.chooseStock(501); window.vm.form.quantity = 3; window.vm.form.borrowerProjectId = 1; return window.vm.changeBorrower() })
assert.equal(await page.evaluate(() => window.vm.form.stockId), undefined)
const borrowBefore = writes.length
await page.evaluate(() => window.vm.save()); assert.equal(writes.length, borrowBefore)
await page.evaluate(() => { window.vm.form.borrowerProjectId = 2; return window.vm.changeBorrower() })
await page.evaluate(() => { window.vm.form.stockId = 501; window.vm.chooseStock(501); window.vm.form.quantity = 3; window.vm.save(); window.vm.save() })
await page.waitForFunction(() => !window.vm.editOpen && window.vm.rows.length === 1)
assert.equal(writes.filter(r => r.path === '/project/loans').length, 1)
record('跨项目借用;切换为借出项目自动清空无效库存,数量上限与双击保护')
await page.evaluate(async () => { window.vm.query.projectId = 1; const old = window.vm.load(); window.vm.query.projectId = 2; await Promise.all([old, window.vm.load()]) })
assert.equal(await page.evaluate(() => window.vm.rows[0].remark), '项目2')
failLoans = true
await page.evaluate(() => window.vm.load())
assert.equal(await page.evaluate(() => window.vm.loading), false)
assert.match(await page.locator('#flow').innerText(), /模拟借还列表失败/)
await page.getByRole('button', { name: /重试/ }).first().click()
await page.waitForFunction(() => !window.vm.loadError && window.vm.rows.length === 1)
record('借还列表快速切换无旧结果覆盖,失败后可重试')
await page.evaluate(loan => window.vm.openReturn(loan), loan)
await page.evaluate(() => { window.vm.form.stockId = 504; window.vm.chooseStock(504); window.vm.form.quantity = 1; window.vm.save(); window.vm.save() })
await page.waitForFunction(() => !window.vm.saving)
assert.equal(await page.evaluate(() => window.vm.editOpen), true)
const key = await page.evaluate(() => window.vm.form.key)
await page.evaluate(() => window.vm.save())
await page.waitForFunction(() => !window.vm.editOpen)
const returns = writes.filter(r => r.path === '/project/loans/800/return')
assert.equal(returns.length, 2); assert.equal(returns[0].data.key, key); assert.equal(returns[1].data.key, key)
assert.equal(loan.outstandingQuantity, 2)
await page.evaluate(() => window.vm.details(window.vm.rows[0]))
assert.match(await page.locator('.el-dialog:visible').filter({ hasText: '归还明细' }).innerText(), /现有库存归还/)
await page.locator('.el-dialog').filter({hasText:'用现有库存归还'}).waitFor({state:'hidden'})
await page.evaluate(()=>window.flowApp.config.globalProperties.$message.closeAll())
await page.waitForTimeout(250)
await page.screenshot({ path: path.join(out, 'loan-return.png'), fullPage: true })
record('部分归还→失败保持可编辑→立即重试同业务标识→归还明细')
await page.evaluate(() => window.mountFlow('/src/components/ProjectLoans/BatchReturn.vue'))
await page.evaluate(loan => window.vm.open([{...loan,id:810,outstandingQuantity:30},{...loan,id:811,outstandingQuantity:30}]),loan)
await page.evaluate(()=>window.vm.allocate())
assert.deepEqual(await page.evaluate(()=>window.vm.rows.map(row=>row.quantity)),[30,10])
await page.evaluate(()=>{window.vm.save();window.vm.save()})
await page.waitForFunction(()=>!window.vm.saving)
assert.deepEqual(await page.evaluate(()=>window.vm.rows.map(row=>row.done)),[true,false])
await page.evaluate(()=>window.vm.save())
assert.deepEqual(await page.evaluate(()=>window.vm.rows.map(row=>row.done)),[true,true])
assert.equal(writes.filter(r=>r.path==='/project/loans/810/return').length,1)
const retriedReturns=writes.filter(r=>r.path==='/project/loans/811/return')
assert.equal(retriedReturns.length,2);assert.equal(retriedReturns[0].data.key,retriedReturns[1].data.key)
record('批量归还按共享库存分配,不超量;失败只重试失败行')
await page.evaluate(()=>window.mountFlow('/src/components/Production/StockOperations.vue'))
await page.evaluate(rows=>window.vm.open(rows,'DELIVERY'),[stock,finished])
assert.equal(await page.evaluate(()=>window.vm.visible),false)
await page.evaluate(rows=>window.vm.open(rows,'SCRAP_STOCK'),stocks.slice(0,2))
await page.evaluate(()=>{window.vm.reason='报废';window.vm.remark='batch-retry';window.vm.submit();window.vm.submit()})
await page.waitForFunction(()=>!window.vm.saving)
assert.deepEqual(await page.evaluate(()=>window.vm.rows.map(row=>row.done)),[true,false])
await page.evaluate(()=>window.vm.submit(true))
assert.deepEqual(await page.evaluate(()=>window.vm.rows.map(row=>row.done)),[true,true])
const stockRuns=writes.filter(r=>r.data?.remark==='batch-retry')
assert.equal(stockRuns.length,3);assert.equal(stockRuns[1].data.key,stockRuns[2].data.key)
await page.evaluate(rows=>window.vm.open(rows,'MOVE'),[stock])
const beforeMove=writes.length
await page.evaluate(()=>window.vm.submit());assert.equal(writes.length,beforeMove)
await page.evaluate(()=>{window.vm.toAreaId=2;return window.vm.submit()})
assert.equal(writes.at(-1).path,'/warehouse/stock/move')
record('批量库存按成品/零件控制入口,失败行独立重试;移库必选其他库区')
await page.evaluate(()=>window.mountFlow('/src/components/Production/BatchActions.vue'))
await page.evaluate(task=>window.vm.open([task],'COMPLETE'),task)
await page.evaluate(()=>{window.vm.rows[0].quantity=5;window.vm.rows[0].adjustPlan=true;window.vm.save();window.vm.save()})
assert.equal(await page.locator('.el-message-box:visible').count(),1)
await page.locator('.el-message-box:visible').getByRole('button',{name:'取消',exact:true}).click()
await page.waitForFunction(()=>!window.vm.saving)
record('批量超计划完工确认框防重复打开,取消后可继续修改')
await page.evaluate(() => window.mountFlow('/src/components/Production/WithdrawAction.vue'))
await page.evaluate(() => window.vm.open({ id: 901, outNum: 5 }, 'OUT'))
const beforeWithdrawal = writes.length
await page.evaluate(async () => {
const v = window.vm
v.form.reason = ' '; await v.save(); v.form.reason = '测试撤销领料'
for (const quantity of [0, -1, 6, null, NaN]) { v.form.quantity = quantity; await v.save() }
v.form.quantity = 2
})
assert.equal(writes.length, beforeWithdrawal)
const withdrawalKey = await page.evaluate(() => window.vm.form.key)
await page.evaluate(() => { const v = window.vm; v.save(); v.save(); v.open({ id: 902, outNum: 8 }, 'OUT') })
assert.equal(await page.evaluate(() => window.vm.form.id), 901)
assert.equal(await page.evaluate(() => window.vm.form.key), withdrawalKey)
const withdrawal = page.getByRole('dialog', { name: '按原记录撤销', exact: true })
assert.equal(await withdrawal.getByRole('button', { name: '取消', exact: true }).isDisabled(), true)
assert.equal(await withdrawal.getByRole('spinbutton').isDisabled(), true)
await page.waitForFunction(() => !window.vm.saving)
assert.equal(await page.evaluate(() => window.vm.visible && window.vm.form.quantity === 2 && window.vm.form.id === 901), true)
assert.equal(writes.filter(row => row.path === '/warehouse/withdrawals').length, 1)
await withdrawal.getByRole('button', { name: '确认撤销', exact: true }).click()
await page.waitForFunction(() => !window.vm.visible)
const withdrawalRequests = writes.filter(row => row.path === '/warehouse/withdrawals')
assert.equal(withdrawalRequests.length, 2)
assert.deepEqual(withdrawalRequests[0].data, withdrawalRequests[1].data)
assert.equal(withdrawalRequests[0].data.key, withdrawalKey)
await page.evaluate(() => { window.vm.open({ id: 903, quantity: 3 }); window.vm.form.reason = '测试撤销生产记录'; window.vm.save(); window.vm.save() })
await page.waitForFunction(() => !window.vm.saving && !window.vm.visible)
assert.equal(writes.filter(row => row.path === '/warehouse/withdrawals').length, 3)
assert.equal(writes.at(-1).data.type, 'PRODUCTION')
assert.equal(writes.at(-1).data.id, 903)
assert.notEqual(writes.at(-1).data.key, withdrawalKey)
record('共享撤销校验数量和原因;保存期间阻止双击、关窗与切单;业务失败保留同标识重试,无未捕获错误')
const clearedCost = await page.evaluate(async()=>{
const Component=(await import('/src/components/Production/CostHistory.vue')).default
const fake={itemId:900,rows:[],loading:false,loadError:''}
const first=Component.methods.load.call(fake);fake.itemId=undefined
await Component.methods.load.call(fake);await first
return {rows:fake.rows,loading:fake.loading}
})
assert.deepEqual(clearedCost,{rows:[],loading:false})
await page.evaluate(()=>window.mountFlow('/src/components/Production/CostHistory.vue',{itemId:901}))
await page.waitForFunction(()=>!window.vm.loading&&!!window.vm.loadError)
await page.getByRole('button',{name:/重试/}).click()
await page.waitForFunction(()=>!window.vm.loading&&window.vm.rows.length===1)
failHistory=true
await page.evaluate(()=>window.mountFlow('/src/components/Production/ActionHistory.vue',{taskId:700}))
await page.waitForFunction(()=>!window.vm.loading&&!!window.vm.loadError)
await page.getByRole('button',{name:/重试/}).click()
await page.waitForFunction(()=>!window.vm.loading&&window.vm.rows.length>0)
record('清空产品立即清空成本且旧请求不回填;成本/追溯失败有重试入口')
assert.deepEqual(errors, [])
assert.deepEqual(blocked, [])
fs.writeFileSync(path.join(out, 'result.json'), JSON.stringify({ checks, requests: writes, readEndpoints: [...new Set(reads)], errors, blocked, note: 'All API traffic is a stateful browser fixture. No database or real business data changed.' }, null, 2))
console.log(`PRODUCTION FLOW PASS: ${checks.length} scenarios, ${writes.length} mocked writes, ${new Set(reads).size} read endpoints; no real business data changed`)
} finally { await browser.close() }
})().catch(error => { console.error(error); process.exit(1) })