yeg
2026-09-28 6a4ca47df73d99e952d926f6103bcccea1ecea89
tests/test-ticket11-browser.mjs
@@ -19,12 +19,16 @@
const live = { ...detail, updatedAt: time, sources: [], exceptions: [], testPlan: { currentCycleNo: 2, currentStepNo: 3, plannedCycleCount: 5, rows: [{ rowType: 'STEP', stepNo: 3, cyclePosition: 1, stepName: '设备计划放电', durationSeconds: 60, voltageV: 3.2, executionStatus: '进行中' }] } }
let liveReads = 0
let unavailable = false
let detailUnavailable = false
let forbidden = false
const requests = []
await context.addInitScript(() => localStorage.setItem('battery_detection_auth_token', 'ticket11-token'))
await page.route('http://ticket11.test/**', async route => {
  const url = new URL(route.request().url())
  if (url.pathname.startsWith('/dev-api/')) {
    requests.push(url.pathname)
    if (detailUnavailable && url.pathname.endsWith('/system/test/42')) return route.fulfill({ status: 503, json: { code: 503, msg: '测试配置暂时不可用' } })
    if (forbidden && /\/live(?:-state)?$/.test(url.pathname)) return route.fulfill({ status: 403, json: { code: 403, msg: '实时状态权限不足' } })
    if (unavailable && /\/live(?:-state)?$/.test(url.pathname)) return route.fulfill({ status: 503, json: { code: 503, msg: '后端暂时不可用' } })
    let result = detail
    if (url.pathname.endsWith('/live-state')) { liveReads++; result = live }
@@ -57,6 +61,8 @@
  assert.match(await page.locator('body').innerText(), /HUMIDITY.*41.*%/)
  assert.match(await page.locator('body').innerText(), /S-04/)
  assert.match(await page.locator('body').innerText(), /adapter-a:1:2:3:4/)
  await mkdir(new URL('../test-results/ticket11/', import.meta.url), { recursive: true })
  await page.screenshot({ path: new URL('../test-results/ticket11/source-desktop.png', import.meta.url).pathname.replace(/^\/(\w:)/, '$1'), fullPage: true })
  await panel.getByRole('button', { name: '编辑', exact: true }).click()
  const dialog = page.getByRole('dialog')
  await dialog.locator('label').filter({ hasText: '电压(V)' }).locator('input').fill('4.1256')
@@ -105,6 +111,7 @@
  await original.waitFor({ state: 'detached' })
  await page.reload()
  await page.getByText('IMPORT-REALTIME', { exact: true }).waitFor()
  await expect(panel.getByRole('button', { name: '实时', exact: true })).toHaveAttribute('aria-current', 'page')
  assert.equal(await page.getByText('RT-1', { exact: true }).count(), 0)
  await page.getByRole('button', { name: '工步', exact: true }).click()
  await page.getByText('STEP-1', { exact: true }).waitFor()
@@ -112,7 +119,7 @@
  await page.getByText('CYCLE-1', { exact: true }).waitFor()
  await page.reload()
  await page.getByText('CYCLE-1', { exact: true }).waitFor()
  await page.getByRole('button', { name: '实时数据', exact: true }).click()
  await page.getByRole('button', { name: '实时监控', exact: true }).click()
  await page.getByText('设备计划放电', { exact: true }).waitFor()
  assert.match(await page.locator('.project-meta').innerText(), /2 \/ 计划 5/)
  const before = liveReads
@@ -135,6 +142,14 @@
  await page.reload()
  await expect(page.locator('.reception-state')).toHaveText('暂停接收')
  await expect(page.locator('.metric-list .voltage')).toHaveText('-')
  forbidden = true
  await expect(page.locator('.live-error')).toContainText('权限不足', { timeout: 10000 })
  forbidden = false
  detailUnavailable = true
  await page.reload()
  await expect(page.locator('.live-error')).toContainText('测试配置暂时不可用')
  detailUnavailable = false
  await expect(page.locator('.reception-state')).toHaveText('暂停接收', { timeout: 10000 })
  assert.ok(requests.every(url => !url.includes('simulator') && !url.includes('overrides')))
  assert.deepEqual(errors, [])
  await mkdir(new URL('../test-results/ticket11/', import.meta.url), { recursive: true })