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' ;(async () => { const login = await (await fetch((process.env.BACKEND_URL || 'http://127.0.0.1:8080') + '/login', { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ username: process.env.TEST_USERNAME || 'admin', password: process.env.TEST_PASSWORD || 'admin123', code: '', uuid: '' }) })).json() assert.equal(login.code, 200) const browser = await chromium.launch({ headless: true }) try { const context = await browser.newContext({ viewport: { width: 1440, height: 900 } }) await context.addCookies([{ name: 'Admin-Token', value: login.token, url: base }]) const page = await context.newPage(), errors = [], stockRequests = [], pendingRequests = [] page.setDefaultTimeout(12000) page.on('pageerror', error => errors.push(error.message)) let dictVersion = 1, dictCalls = 0, stockQuantity = 10, failLists = false, thirdStarted const thirdRequest = new Promise(resolve => { thirdStarted = resolve }) 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())) return route.abort('blockedbyclient') if (path === '/dev-api/system/dict/data/type/wms_in_status') { const version = dictVersion; dictCalls++ if (version === 3) {thirdStarted(); await new Promise(resolve => setTimeout(resolve, 200))} return route.fulfill({ json: { code: 200, data: [{ dictLabel: '状态版本' + version, dictValue: '0', listClass: 'danger' }] } }) } if (['/dev-api/warehouse/in/list', '/dev-api/warehouse/out/list'].includes(path)) { return route.fulfill({ json: failLists ? { code: 500, msg: '回归模拟查询失败' } : { code: 200, total: 1, rows: [{ id: 990101, inNo: 'RK-AUDIT', inStatus: 0, inNum: 5, productName: '验收测试物品' }] } }) } if (path === '/dev-api/warehouse/stock/list') { stockRequests.push(Object.fromEntries(url.searchParams)) return route.fulfill({ json: { code: 200, total: 1, rows: [{ id: 990102, projectId: 1, productId: 990103, productName: '缓存测试物品', stockNum: stockQuantity, areaName: '测试库区', unit: '个' }] } }) } if (path === '/dev-api/warehouse/in/pending-groups') { pendingRequests.push(Object.fromEntries(url.searchParams)) return route.fulfill({ json: { code: 200, data: { rows: [], total: 0, itemTotal: 0 } } }) } return route.continue() }) const navigate = path => page.locator('.desktop-viewport').evaluate(async (el, path) => { await el.__vueParentComponent.proxy.$router.push(path) }, path) const clearDict = () => page.locator('.desktop-viewport').evaluate(el => { el.__vueParentComponent.appContext.config.globalProperties.$pinia._s.get('dict').cleanDict() }) const settled = () => page.waitForFunction(() => ![...document.querySelectorAll('.desktop-viewport .el-loading-mask')].some(el => el.getClientRects().length)) await page.goto(base + '/warehouse/inRecord') await page.locator('.el-table__body').getByText('状态版本1', { exact: true }).waitFor() assert.equal(await page.locator('.el-table__body .el-tag--danger').count(), 1) dictVersion = 2; await clearDict() await page.locator('.el-table__body').getByText('状态版本2', { exact: true }).waitFor() assert.equal(dictCalls, 2) dictVersion = 3; await clearDict() await thirdRequest dictVersion = 4; await clearDict() await page.locator('.el-table__body').getByText('状态版本4', { exact: true }).waitFor() await page.waitForTimeout(250) assert.equal(await page.getByText('状态版本3', { exact: true }).count(), 0) console.log('PASS one live dictionary cache, configured tag colors, stale-response rejection') await navigate('/warehouse/stock') await page.waitForFunction(() => document.querySelector('.desktop-viewport .el-table__body')?.textContent.includes('缓存测试物品')); await settled() const nameInput = page.locator('.desktop-viewport .el-form-item').filter({ hasText: '关键词' }).locator('input') await nameInput.fill('保留筛选'); await page.getByRole('button', { name: '搜索', exact: true }).click(); await settled() const count = stockRequests.length; stockQuantity = 20 await navigate('/index'); await page.locator('.business-home').waitFor() await navigate('/warehouse/stock'); await settled() await page.waitForFunction(() => document.querySelector('.desktop-viewport .el-table__body')?.textContent.includes('20')) assert.equal(stockRequests.length, count + 1) assert.equal(stockRequests.at(-1).productName, '保留筛选') assert.equal(await nameInput.inputValue(), '保留筛选') console.log('PASS returning stock page refreshes quantities and preserves filters') await navigate('/warehouse/pending?sourceGroup=B%3A990001&projectId=2'); await settled() assert.equal(pendingRequests.at(-1).purchaseBatchId, '990001') await page.getByRole('button', { name: '重置', exact: true }).click(); await settled() await page.waitForURL(url => !url.searchParams.has('sourceGroup')) assert.equal(pendingRequests.at(-1).purchaseBatchId, undefined) assert.equal(pendingRequests.at(-1).sourceProjectId, undefined) assert.equal(pendingRequests.at(-1).inStatus, '0') console.log('PASS pending-receipt reset clears hidden and URL filters while retaining pending status') failLists = true for (const route of ['/warehouse/inRecord', '/warehouse/outRecord']) { const response = page.waitForResponse(r => /\/warehouse\/(in|out)\/list/.test(r.url())) await navigate(route); await response; await settled() assert.equal(await page.locator('.desktop-viewport .el-loading-mask:visible').count(), 0) } assert.deepEqual(errors, []) console.log('PASS failed queries release loading state without unhandled errors') console.log('CACHE/FILTER REGRESSION PASS (business writes blocked)') } finally { await browser.close() } })().catch(error => { console.error(error); process.exitCode = 1 })