64 lines
4.0 KiB
JavaScript
64 lines
4.0 KiB
JavaScript
|
|
/** 接入日期草稿与设置刷新的浏览器回归,接口全部隔离。 */
|
||
|
|
import assert from 'node:assert/strict'
|
||
|
|
import path from 'node:path'
|
||
|
|
import { createRequire } from 'node:module'
|
||
|
|
import { fileURLToPath } from 'node:url'
|
||
|
|
import vue from '@vitejs/plugin-vue'
|
||
|
|
import { createServer } from 'vite'
|
||
|
|
|
||
|
|
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 root = fileURLToPath(new URL('../', import.meta.url))
|
||
|
|
const id = 'virtual:business-sync-date'
|
||
|
|
const harness = `import {createApp,h} from 'vue';import {createPinia} from 'pinia';import ElementPlus from 'element-plus';import 'element-plus/dist/index.css';import Panel from '/src/views/system/tplus/BusinessSyncPanel.vue';import {useUserStore} from '/src/store/user.ts';const pinia=createPinia();createApp({setup(){useUserStore().userInfo={permissions:['tplus:view','tplus:import']};return()=>h(Panel)}}).use(pinia).use(ElementPlus).mount('#app')`
|
||
|
|
const server = await createServer({ configFile: false, root,
|
||
|
|
resolve: { alias: { '@': path.join(root, 'src') } },
|
||
|
|
define: { 'import.meta.env.VITE_API_BASE_URL': JSON.stringify('/api') },
|
||
|
|
cacheDir: path.resolve(root, '../.ai/business-sync-date-browser/vite-cache'),
|
||
|
|
plugins: [vue(), { name: 'business-sync-date-proof', resolveId: value => value === id ? '\0' + id : undefined,
|
||
|
|
load: value => value === '\0' + id ? harness : undefined,
|
||
|
|
configureServer(instance) { instance.middlewares.use('/__business-sync-date', async (_request, response) => {
|
||
|
|
response.setHeader('Content-Type', 'text/html; charset=utf-8')
|
||
|
|
response.end(await instance.transformIndexHtml('/__business-sync-date', '<!doctype html><html lang="zh-CN"><meta charset="UTF-8"><div id="app"></div><script type="module" src="/@id/__x00__virtual:business-sync-date"></script></html>'))
|
||
|
|
}) },
|
||
|
|
}], server: { host: '127.0.0.1', port: 0 }, optimizeDeps: { include: ['vue', 'element-plus', 'pinia'] } })
|
||
|
|
let browser
|
||
|
|
let settings = { enabled: false, start_date: '2026-03-01', version: 1, editable: true, last_error: null }
|
||
|
|
try {
|
||
|
|
await server.listen()
|
||
|
|
browser = await chromium.launch({ headless: true, channel: 'msedge' })
|
||
|
|
const page = await browser.newPage()
|
||
|
|
const errors = []
|
||
|
|
page.on('pageerror', error => errors.push(error.message))
|
||
|
|
await page.route(url => url.pathname.startsWith('/api/'), async route => {
|
||
|
|
const pathname = new URL(route.request().url()).pathname
|
||
|
|
const data = pathname.endsWith('/business-sync') ? settings : pathname.endsWith('/work-runs') ? { list: [], total: 0 } : null
|
||
|
|
assert.ok(data, '未预期接口:' + pathname)
|
||
|
|
await route.fulfill({ json: { code: 200, message: 'success', data } })
|
||
|
|
})
|
||
|
|
await page.goto(`http://127.0.0.1:${server.httpServer.address().port}/__business-sync-date`)
|
||
|
|
const input = page.locator('.el-date-editor input')
|
||
|
|
await input.waitFor()
|
||
|
|
await page.getByText('未开启', { exact: true }).waitFor()
|
||
|
|
await input.fill('2026-04-01')
|
||
|
|
await input.press('Tab')
|
||
|
|
await Promise.all([
|
||
|
|
page.waitForResponse(response => new URL(response.url()).pathname.endsWith('/work-runs')),
|
||
|
|
page.getByRole('button', { name: '刷新', exact: true }).click(),
|
||
|
|
])
|
||
|
|
assert.equal(await input.inputValue(), '2026-04-01', '刷新应保留正在填写的日期')
|
||
|
|
settings = { ...settings, enabled: true, start_date: '2026-05-01', version: 2 }
|
||
|
|
await Promise.all([
|
||
|
|
page.waitForResponse(response => new URL(response.url()).pathname.endsWith('/work-runs')),
|
||
|
|
page.getByRole('button', { name: '刷新', exact: true }).click(),
|
||
|
|
])
|
||
|
|
await page.getByText('已开启', { exact: true }).waitFor()
|
||
|
|
assert.equal(await input.inputValue(), '2026-05-01', '远程开启后应显示生效日期')
|
||
|
|
assert.equal(await input.isDisabled(), true)
|
||
|
|
assert.deepEqual(errors, [])
|
||
|
|
console.log('接入日期草稿、刷新与远程启用验证通过')
|
||
|
|
} finally {
|
||
|
|
if (browser) await browser.close()
|
||
|
|
await server.close()
|
||
|
|
}
|