| 123456789101112131415161718192021222324252627282930313233343536373839404142434445 |
- // P80:就地切换时间窗,看「振动 CMS」的 chip 是否随之变化(真实交互路径:#win 下拉 change → App 重新取数)
- import { readFileSync } from 'node:fs'
- import { fileURLToPath } from 'node:url'
- import { dirname, resolve } from 'node:path'
- import { JSDOM, VirtualConsole } from 'jsdom'
- const HERE = dirname(fileURLToPath(import.meta.url))
- const dist = resolve(HERE, '../../../release/web')
- const idx = readFileSync(dist + '/index.html', 'utf8')
- const jsFile = (idx.match(/src="([^"]+\.js)"/) || [])[1].replace(/^.*\//, '')
- const cssFile = (idx.match(/href="([^"]+\.css)"/) || [])[1].replace(/^.*\//, '')
- const code = readFileSync(dist + '/assets/' + jsFile, 'utf8')
- const css = readFileSync(dist + '/assets/' + cssFile, 'utf8')
- const fleetA = JSON.parse(readFileSync(resolve(HERE, '_fleet_fixture.json'), 'utf8')) // 2026年
- const fleetB = JSON.parse(JSON.stringify(fleetA)); fleetB.win = '全程'
- fleetB.kpi = Object.assign({}, fleetA.kpi || {}, { '关注台': 4, '报警台': 19, '全场': 38 })
- const vib = readFileSync(resolve(HERE, '_vibcms_fixture.json'), 'utf8')
- const calls = []
- let useB = false
- const dom = new JSDOM(idx.replace('</head>', '<style>' + css + '</style></head>'),
- { url: 'http://127.0.0.1:28084/detail/v2#tab=vibration:portal_cms', runScripts: 'outside-only', pretendToBeVisual: true, virtualConsole: new VirtualConsole() })
- const w = dom.window
- w.fetch = async (u) => {
- const s = String(u); calls.push(s)
- const f = useB ? fleetB : fleetA
- const body = /fleet/.test(s) ? JSON.stringify(f) : (/vibcms/.test(s) ? vib : '{}')
- return { ok: true, status: 200, json: async () => JSON.parse(body), text: async () => body }
- }
- try { w.eval(code) } catch (e) { console.log('EVAL_ERR ' + String(e).slice(0, 140)) }
- for (let i = 0; i < 20; i++) { await new Promise((r) => setTimeout(r, 400)); if (/振动与 SCADA/.test(w.document.body.textContent || '')) break }
- const chips = () => Array.from((w.document.querySelector('#root') || w.document.body).querySelectorAll('span'))
- .map((s) => s.textContent.trim()).filter((x) => /时间窗 ·|关注台|报警台|全场|证据窗末/.test(x))
- console.log('BEFORE ' + JSON.stringify(chips()))
- // 真实交互:改 #win 下拉并派发 change
- const sel = w.document.querySelector('#win')
- console.log('SELECT ' + (sel ? 'Y' : 'N') + ' options=' + (sel ? sel.querySelectorAll('option').length : 0))
- if (sel) {
- useB = true
- sel.value = '近30日'
- sel.dispatchEvent(new w.Event('change', { bubbles: true }))
- }
- for (let i = 0; i < 20; i++) { await new Promise((r) => setTimeout(r, 500)); if (calls.some((c) => /win=/.test(c))) break }
- await new Promise((r) => setTimeout(r, 2500))
- console.log('AFTER ' + JSON.stringify(chips()))
- console.log('CALLS ' + JSON.stringify(calls.slice(-6)))
- console.log('WINDOW_FETCH ' + calls.some((c) => /win=/.test(c)))
|