|
@@ -0,0 +1,39 @@
|
|
|
|
|
+
|
|
|
|
|
+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 baseFleet = JSON.parse(readFileSync(resolve(HERE, '_fleet_fixture.json'), 'utf8'))
|
|
|
|
|
+const vib = readFileSync(resolve(HERE, '_vibcms_fixture.json'), 'utf8')
|
|
|
|
|
+async function run(fleet, tag) {
|
|
|
|
|
+ const dom = new JSDOM(idx.replace('</head>', '<style>' + css + '</style></head>'),
|
|
|
|
|
+ { url: 'http://127.0.0.1:28084/detail/v2#tab=vibration', runScripts: 'outside-only', pretendToBeVisual: true, virtualConsole: new VirtualConsole() })
|
|
|
|
|
+ const w = dom.window
|
|
|
|
|
+ w.fetch = async (u) => { const s = String(u)
|
|
|
|
|
+ const body = /fleet/.test(s) ? JSON.stringify(fleet) : (/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, 120)) }
|
|
|
|
|
+ for (let i = 0; i < 24; i++) { await new Promise((r) => setTimeout(r, 400)); if (w.document.querySelector('[data-fsub]')) break }
|
|
|
|
|
+ const pills = Array.from(w.document.querySelectorAll('[data-fsub]')).map((b) => b.textContent.trim())
|
|
|
|
|
+ const p6 = w.document.querySelector('[data-fsub="portal_cms"]')
|
|
|
|
|
+ if (p6) p6.dispatchEvent(new w.MouseEvent('click', { bubbles: true }))
|
|
|
|
|
+ await new Promise((r) => setTimeout(r, 2000))
|
|
|
|
|
+ const root = w.document.querySelector('#root') || w.document.body
|
|
|
|
|
+ const txt = (root.textContent || '').replace(/\s+/g, ' ')
|
|
|
|
|
+ const chips = Array.from(root.querySelectorAll('.chip')).map((c) => c.textContent.trim())
|
|
|
|
|
+ console.log(tag + ' PILLS ' + JSON.stringify(pills))
|
|
|
|
|
+ console.log(tag + ' CHIPS ' + JSON.stringify(chips.slice(0, 6)))
|
|
|
|
|
+ console.log(tag + ' HAS_HERO ' + /振动与 SCADA 联合分析|六层模型/.test(txt))
|
|
|
|
|
+}
|
|
|
|
|
+await run(baseFleet, 'A')
|
|
|
|
|
+const f2 = JSON.parse(JSON.stringify(baseFleet))
|
|
|
|
|
+f2.win = '全程'
|
|
|
|
|
+if (f2.fus && f2.fus.kpi) { f2.fus.kpi['候选观察'] = 9; f2.fus.kpi['全场'] = 38 }
|
|
|
|
|
+await run(f2, 'B')
|