cmvr-wms/ruoyi-project/scripts/ui-check.mjs

56 lines
4.1 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'
import { mkdir } from 'node:fs/promises'
import { resolve } from 'node:path'
import { seedDemo } from './demo.mjs'
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 demo = await seedDemo()
const frontend = process.env.PM_FRONTEND_URL || 'http://127.0.0.1:8088'
const output = resolve('.codex-tmp/pm-ui'); await mkdir(output, { recursive: true })
const browser = await chromium.launch({ channel: 'chrome', headless: true })
const context = await browser.newContext({ viewport: { width: 1440, height: 1000 } })
await context.addCookies([{ name: 'Admin-Token', value: demo.token, url: frontend }])
const page = await context.newPage(), errors = []
page.on('pageerror', e => errors.push(e.message))
// 转发到真实验证服务而非 Mock;不改动用户正在 IDE 调试的 8080 服务或 Vite 代理配置。
if (process.env.PM_DIRECT_PROXY !== 'true') await page.route('**/*-api/**', async route => {
const path = new URL(route.request().url()).pathname.replace(/^\/(dev|prod)-api/, '')
const response = await route.fetch({ url: demo.base + path + new URL(route.request().url()).search })
await route.fulfill({ response })
})
try {
await page.goto(frontend + '/project/collaboration', { waitUntil: 'networkidle' })
await page.locator('.pm-app').waitFor()
const selector = page.locator('.workspace-select .el-select').nth(1)
await selector.click(); await page.getByRole('option').filter({ hasText: demo.project.name }).click()
await page.locator('.work-surface .el-link').filter({ hasText: '任务 C:联调测试' }).waitFor()
assert.equal(await page.locator('.work-surface .el-table__body tr').count(), 5)
await page.screenshot({ path: resolve(output, 'list.png'), fullPage: true })
await page.locator('.work-surface .el-link').filter({ hasText: '任务 C:联调测试' }).click()
const drawer = page.locator('.el-drawer').filter({ hasText: '任务 C:联调测试' })
await drawer.waitFor()
assert.ok((await drawer.innerText()).includes('已满足 1/2 个条件'))
assert.ok((await drawer.innerText()).includes('2026-10-22'))
assert.equal(await drawer.getByRole('button', { name: '开始', exact: true }).isDisabled(), true)
await page.screenshot({ path: resolve(output, 'dependencies.png'), fullPage: true })
await drawer.locator('input[type=file]').setInputFiles({ name: '附件验证.txt', mimeType: 'text/plain', buffer: Buffer.from('真实附件上传与受鉴权下载验证') })
const attachment = drawer.locator('.attachment .el-link').filter({ hasText: '附件验证.txt' }).last()
await attachment.waitFor()
const download = page.waitForEvent('download'); await attachment.click(); assert.equal((await download).suggestedFilename(), '附件验证.txt')
await page.screenshot({ path: resolve(output, 'attachments.png'), fullPage: true })
await drawer.locator('.el-drawer__close-btn').click()
await page.getByRole('tab', { name: '看板', exact: true }).click(); assert.equal(await page.locator('.work-card').count(), 5)
await page.screenshot({ path: resolve(output, 'board.png'), fullPage: true })
await page.getByRole('tab', { name: '甘特排期', exact: true }).click(); assert.equal(await page.locator('.bar').count(), 4)
await page.screenshot({ path: resolve(output, 'gantt.png'), fullPage: true })
await page.getByRole('tab', { name: '成员', exact: true }).click(); await page.getByText('项目成员', { exact: true }).waitFor()
await page.screenshot({ path: resolve(output, 'settings.png'), fullPage: true })
assert.deepEqual(errors, [])
console.log('真实 API 页面验证 PASS:列表、任务依赖、开始禁用、附件上传/下载、看板、甘特、成员;截图在 .codex-tmp/pm-ui')
} catch (error) {
await page.screenshot({ path: resolve(output, 'failure.png'), fullPage: true })
console.error(JSON.stringify({ url: page.url(), pageErrors: errors, visibleText: (await page.locator('body').innerText()).slice(0, 1500) }))
throw error
} finally { await browser.close() }