PayrollManagementSystem/frontend/e2e/batch-categories.mjs
liuwenxin 1e53792ad6 feat(T+): 完成数据贯通与自动接入闭环
打通 T+ 快照、业务、发货、回款和核算准备链路,保留来源差异并提供待补状态。
新增业务自动接入任务、跨平台读取服务托管、权限复核、来源关联和前端核对页面。
补充迁移、隔离集成测试、浏览器模拟验收及角色授权边界修复。
2026-11-05 18:47:13 +08:00

63 lines
4.2 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.

/** 使用隔离模拟接口验证真实页面的批量分类交互。 */
import assert from 'node:assert/strict'
import { createRequire } from 'node:module'
const require = createRequire(import.meta.url)
const { chromium } = require(process.env.PLAYWRIGHT_MODULE || 'C:/Users/Administrator/.cache/codex-runtimes/codex-primary-runtime/dependencies/node/node_modules/playwright')
const base = process.env.OPS_UI_URL || 'http://127.0.0.1:5173'
const calls = []
const state = { customers: null, products: null, owner: null }
const browser = await chromium.launch({ headless: true, channel: 'msedge' })
try {
const page = await browser.newPage({ viewport: { width: 1440, height: 900 } })
const errors = []
page.on('pageerror', error => errors.push(error.message))
await page.addInitScript(() => localStorage.setItem('ys_token', 'synthetic-batch-ui'))
await page.route(url => url.pathname.startsWith('/api/'), async route => {
const req = route.request(), url = new URL(req.url()), path = url.pathname.replace('/api/v1', '')
let data = []
if (path === '/auth/me') data = { id: 1, username: 'ui-test', roles: ['admin'], permissions: ['base:customers:view', 'base:customers:update', 'base:customers:ownership', 'base:products:view', 'base:products:update'] }
else if (path.endsWith('/batch-ownership')) {
const payload = req.postDataJSON(); calls.push({kind: 'ownership', ...payload}); state.owner = payload.new_owner_personnel_id; data = {updated: payload.ids.length}
}
else if (path.endsWith('/batch-category')) {
const payload = req.postDataJSON(), kind = path.includes('customers') ? 'customers' : 'products'
calls.push({kind, ...payload}); state[kind] = payload.category; data = { updated: payload.ids.length }
} else if (path === '/base/customers') {
data = {list: [{id: 11, company_name: '测试待分类客户', owner_name: '', customer_type: state.customers, owner_personnel_id: state.owner, owner_personnel_name: state.owner ? '测试归属人' : null, rating_score: null}], total: 1, pageNum: 1, pageSize: 20}
} else if (path === '/base/products') {
data = {list: [{id: 12, product_name: '测试待分类产品', spec_model: '', unit: '件', product_category: state.products, status: 1, stock_quantity: null, sale_price: null}], total: 1, pageNum: 1, pageSize: 20}
} else if (path.includes('/meta/')) data = url.searchParams.get('resource') === 'personnel' ? [{id: 21, personnel_name: '测试归属人', status: 1}] : []
await route.fulfill({ json: { code: 200, message: 'success', data } })
})
for (const [kind, label, category, id] of [['customers', '测试待分类客户', '企业户', 11], ['products', '测试待分类产品', '市政水利', 12]]) {
await page.goto(`${base}/base/${kind}`)
const row = page.getByRole('row').filter({hasText: label})
await row.waitFor()
await row.locator('label.el-checkbox').click()
await page.locator('.toolbar .el-select').first().click()
await page.getByRole('option', { name: category, exact: true }).click()
await page.getByRole('button', {name: '批量补充分类(1)'}).click()
await page.getByRole('dialog').getByRole('button', {name: '确定'}).click()
await row.getByText(category, {exact: true}).waitFor()
assert.equal(calls.at(-1).kind, kind)
assert.deepEqual(calls.at(-1).ids, [id])
}
await page.goto(`${base}/base/customers`)
const customer = page.getByRole('row').filter({hasText: '测试待分类客户'})
await customer.waitFor()
await customer.locator('label.el-checkbox').click()
await page.locator('.toolbar .el-select').nth(1).click()
await page.getByRole('option', {name: '测试归属人', exact: true}).click()
await page.getByRole('button', {name: '批量补充归属(1)'}).click()
await page.getByRole('dialog').getByRole('button', {name: '确定'}).click()
await customer.getByText('测试归属人', {exact: true}).waitFor()
assert.equal(calls.at(-1).kind, 'ownership')
assert.deepEqual(calls.at(-1).ids, [11])
assert.equal(calls.at(-1).new_owner_personnel_id, 21)
assert.deepEqual(errors, [])
process.stdout.write('客户和产品批量分类及客户批量归属页面交互通过(模拟接口)。\n')
} finally {
await browser.close()
}