cmvr-wms/ruoyi-project/scripts/flow-view-render-check.mjs

60 lines
6.9 KiB
JavaScript

import assert from 'node:assert/strict'
import { createRequire } from 'node:module'
import { mkdir, writeFile, unlink } from 'node:fs/promises'
import { resolve } from 'node:path'
const require = createRequire(import.meta.url)
const { chromium } = require(process.env.PM_PLAYWRIGHT || 'C:/Users/Administrator/.cache/codex-runtimes/codex-primary-runtime/dependencies/node/node_modules/playwright')
const frontend = process.env.PM_FRONTEND_URL || 'http://127.0.0.1:8093'
const file = resolve('ruoyi-ui-vue3/node_modules/.vite-pm/flow-view-render.html')
const stages = ['方案设计', '前端开发', '后端开发', '验收发布'].map((name, index) => ({ id: index + 1, name, sortOrder: [2, 3, 3, 4][index], ownerId: 1, ownerName: '张浩', description: '', version: 0, counts: { total: 0, READY: 0, IN_PROGRESS: 0, COMPLETED: 0, CANCELLED: 0, blocked: 0, scheduleIncomplete: 0 }, plannedStartAt: '2026-10-20T09:00:00+08:00', plannedEndAt: '2026-10-24T18:00:00+08:00', fullyScheduled: 0 }))
const names = ['客户门户升级', '技术方案设计', '前端页面开发', '接口开发', '联调与验收测试', '版本发布']
const items = names.map((title, index) => ({ id: index + 1, projectId: 1, stageId: [1, 1, 2, 3, 4, 4][index], type: index ? 'TASK' : 'REQUIREMENT', title, description: '', assigneeId: 1, priority: 'MEDIUM', status: index < 2 ? 'COMPLETED' : index === 2 ? 'IN_PROGRESS' : 'READY', version: 0, timezone: 'Asia/Shanghai', plannedStartAt: '2026-10-20T09:00:00+08:00', plannedEndAt: '2026-10-24T18:00:00+08:00', actualStartAt: null, actualEndAt: null, canStart: index === 3, blockedReasons: [], dependencyConditions: [], dependencyBlocked: index > 3, scheduleConstraints: { scheduleValidationStatus: 'VALID', sources: [], scheduleBlockedReasons: [], earliestPlannedStartAt: null } }))
const layout = { version: 0, positions: {}, collapsedStages: [], viewport: null, filters: null }
const view = { stages, items, unassigned: { counts: { total: 0 }, fullyScheduled: 0 }, dependencies: [[2, 3], [2, 4], [3, 5], [4, 5], [5, 6]].map(([source, target], index) => ({ id: index + 1, predecessorTaskId: source, successorTaskId: target, version: 0 })), sharedLayout: layout, personalLayout: layout }
for (const item of items) { item.dependencyConditions = view.dependencies.filter(edge => edge.successorTaskId === item.id).map(edge => { const source = items.find(other => other.id === edge.predecessorTaskId); return { id: edge.id, version: 0, conditionType: 'TASK_COMPLETED', sourceId: source.id, sourceWorkItemId: source.id, sourceName: source.title, currentStatus: source.status, expectedStatus: 'COMPLETED', satisfied: source.status === 'COMPLETED', participatesInSchedule: true } }); const stage = stages.find(value => value.id === item.stageId); stage.counts.total++; stage.counts[item.status]++; stage.counts.blocked += Number(item.dependencyBlocked); stage.fullyScheduled++ }
// 仅视觉/第三方真实画布验收夹具,不替代 flow-view-ui-check 的真实登录与数据库业务验收。
const html = `<!DOCTYPE html><html><head><meta charset="UTF-8"><title>流程画布渲染验收</title></head><body style="margin:20px;background:#f6f8fc"><div id="app"></div><script type="module">
import { createApp, h, ref } from 'vue'
import ElementPlus from 'element-plus'
import 'element-plus/dist/index.css'
import WorkFlow from '/src/views/project/manage/components/WorkFlow.vue'
import ItemEditor from '/src/views/project/manage/components/ItemEditor.vue'
const view = ${JSON.stringify(view)}
createApp({ setup() { const visible = ref(false), stageId = ref(null); return () => h('div', [
h(WorkFlow, { view, projectId: 1, members: [{userId:1,name:'张浩',role:'MANAGER'}], canWrite: true, canManage: true, active: true, filters: {}, onCreate(id) { stageId.value = id; visible.value = true } }),
h(ItemEditor, { visible: visible.value, defaultStageId: stageId.value, projectId: 1, zone: 'Asia/Shanghai', item: null, members: [], stages: view.stages, onClose() { visible.value = false } })
]) } }).use(ElementPlus).mount('#app')
</script></body></html>`
await mkdir(resolve('ruoyi-ui-vue3/node_modules/.vite-pm'), { recursive: true }); await writeFile(file, html)
const browser = await chromium.launch({ channel: 'chrome', headless: true })
try {
const page = await browser.newPage({ viewport: { width: 1600, height: 900 } }), errors = []
page.on('pageerror', error => { errors.push(error.message); console.error(error.stack) })
await page.goto(frontend + '/node_modules/.vite-pm/flow-view-render.html', { waitUntil: 'networkidle' })
await page.locator('.flow-item').first().waitFor()
assert.equal(await page.locator('.flow-item').count(), 6)
assert.deepEqual((await page.locator('.vue-flow__edge').evaluateAll(elements => elements.map(element => element.getAttribute('data-id')))).sort(), ['stage:1:2', 'stage:1:3', 'stage:2:4', 'stage:3:4'])
assert.equal(await page.locator('.flow-item .vue-flow__handle').count(), 0)
const pending = page.locator('.flow-item[data-work-item="5"]')
assert.ok((await pending.innerText()).includes('已满足 0/2')); assert.ok((await pending.innerText()).includes('前端页面开发')); assert.ok((await pending.innerText()).includes('接口开发'))
await page.getByRole('button', { name: '适应画布', exact: true }).click()
const handle = page.locator('.flow-item[data-work-item="4"] .item-drag'), box = await handle.boundingBox(); assert.ok(box)
const node = page.locator('.vue-flow__node[data-id="w:4"]'), before = await node.getAttribute('style')
await page.mouse.move(box.x + 20, box.y + 8); await page.mouse.down(); await page.mouse.move(box.x + 20, box.y + 40, { steps: 12 }); await page.mouse.up()
assert.notEqual(await node.getAttribute('style'), before, '真实 Vue Flow 节点应响应拖动')
assert.ok((await page.locator('.flow-view').innerText()).includes('个人视图未保存'))
await mkdir('.codex-tmp/pm-ui', { recursive: true })
await page.screenshot({ path: '.codex-tmp/pm-ui/flow-view-render.png', fullPage: true, animations: 'disabled' })
await page.getByRole('button', { name: '折叠全部', exact: true }).click()
assert.equal(await page.locator('.flow-item').count(), 0)
await page.getByRole('button', { name: '展开全部', exact: true }).click()
assert.equal(await page.locator('.flow-item').count(), 6)
await page.locator('[data-stage="3"] .stage-create').click()
const dialog = page.locator('.el-dialog').filter({ hasText: '新建工作项' }); await dialog.waitFor()
assert.ok((await dialog.locator('.el-form-item').filter({ hasText: '所属阶段' }).innerText()).includes('后端开发'))
assert.equal(await dialog.locator('.picker-only .el-date-editor').count(), 2)
await dialog.getByRole('button', { name: '取消', exact: true }).click()
assert.deepEqual(errors, [])
console.log('PASS: 真实 Vue Flow 2→3/3→4 阶段边/无任务连线端口/前置摘要/拖动/折叠/阶段新建默认归属;使用视觉夹具,不代表登录业务端到端验收')
} finally { await browser.close(); await unlink(file) }