yeg
2026-09-08 eb02e33a51ceb129eaa9e8a7ba72ca65854f9053
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
import { expect, test } from '@playwright/test'
 
test('暂停停止系统请求、继续恢复请求并可停止测试', async ({ page }) => {
  const base = {
    testId: 42, testName: 'Ticket10 生命周期测试', testStatus: 'RUNNING', receptionStatus: 'RECEIVING',
    batteries: [], planSteps: [], thresholds: [], fieldSnapshots: [], runtimeAttach: false,
  }
  let status = 'RECEIVING'
  let testStatus = 'RUNNING'
  const actionRequests: string[] = []
  await page.addInitScript(() => localStorage.setItem('battery_detection_auth_token', 'ticket10-test-token'))
  await page.route('**/system/test/42**', async route => {
    const request = route.request()
    if (request.method() === 'POST' && request.url().endsWith('/reception/pause')) { status = 'PAUSED'; actionRequests.push('pause') }
    if (request.method() === 'POST' && request.url().endsWith('/reception/resume')) { status = 'RECEIVING'; actionRequests.push('resume') }
    if (request.method() === 'POST' && (request.url().endsWith('/stop') || request.url().endsWith('/reception/end'))) { status = 'ENDED'; testStatus = 'COMPLETED'; actionRequests.push('stop') }
    if (request.url().endsWith('/live-state')) {
      await route.fulfill({ status: 200, contentType: 'application/json', body: JSON.stringify({ code: 200, data: { testId: 42, testStatus, receptionStatus: status, updatedAt: '2026-08-30T06:00:00Z', sources: [], exceptions: [] } }) })
      return
    }
    if (request.url().endsWith('/live')) {
      await route.fulfill({ status: 200, contentType: 'text/event-stream', body: 'event: heartbeat\ndata: {"at":"2026-08-30T06:00:00Z"}\n\n' })
      return
    }
    if (request.method() === 'POST') {
      await route.fulfill({ status: 200, contentType: 'application/json', body: JSON.stringify({ code: 200, data: { ...base, receptionStatus: status, testStatus } }) })
      return
    }
    await route.fulfill({ status: 200, contentType: 'application/json', body: JSON.stringify({ code: 200, data: { ...base, receptionStatus: status, testStatus } }) })
  })
  await page.goto('/test-list/42/console')
  await expect(page.getByRole('button', { name: '暂停接收', exact: true })).toBeVisible()
  await page.getByRole('button', { name: '暂停接收', exact: true }).click()
  await expect(page.getByText('暂停接收将停止系统向检测柜和采集器请求新数据,但设备仍继续运行,不会向设备发送暂停命令,是否继续?', { exact: true })).toBeVisible()
  await page.getByRole('button', { name: '暂停接收', exact: true }).last().click()
  await expect(page.locator('.reception-state')).toHaveText('暂停接收')
  await expect(page.getByText('已暂停接收,系统已停止请求新数据', { exact: true })).toBeVisible()
  await page.getByRole('button', { name: '继续接收', exact: true }).click()
  await page.getByRole('button', { name: '继续接收', exact: true }).last().click()
  await expect(page.locator('.reception-state')).toHaveText('接收中')
  await expect(page.getByText('已继续接收,系统已恢复数据请求', { exact: true })).toBeVisible()
  await page.getByRole('button', { name: '停止测试', exact: true }).click()
  await page.getByRole('button', { name: '停止测试', exact: true }).last().click()
  await expect(page.locator('.running-state')).toHaveText('检测完成')
  await expect(page.locator('.reception-state')).toHaveText('已结束接收')
  await expect(page.locator('button.danger-button')).toBeDisabled()
  await expect(page.locator('.interval-count')).toHaveCount(0)
  expect(actionRequests).toEqual(['pause', 'resume', 'stop'])
})