重置高压发生器功能允许用户通过界面上的RESET按钮重置设备参数,将高压发生器恢复到初始状态。
UI Button (RESET)
↓
handleResetParameters()
↓
dispatch(resetDevices()) [Redux Thunk]
↓
resetAllDevices() [API]
↓
POST /auth/device/action
↓
设备重置完成
interface DeviceState {
status: 'idle' | 'loading' | 'succeeded' | 'failed';
error: string | null;
deviceError: string | null;
}
POST /auth/device/action
{
"deviceUri": "DIOS/DEVICE/Generator",
"reqName": "RESET",
"reqParam": "",
"reqTransaction": "",
"reqClientID": ""
}
成功响应:
{
"code": "0x000000",
"description": "Success",
"data": {}
}
失败响应:
{
"code": "0x010001",
"description": "设备通信失败",
"solution": "检查设备连接"
}
文件路径: cypress/e2e/exam/reset-generator.cy.ts
测试目标: 验证正常重置流程
前置条件:
测试步骤:
验证点:
Mock配置:
cy.intercept('POST', '/auth/device/action', (req) => {
if (req.body.reqName === 'RESET') {
req.reply({
statusCode: 200,
body: {
code: '0x000000',
description: 'Success',
data: {}
}
});
}
}).as('resetDevice');
测试目标: 验证重置失败时的错误处理
前置条件:
测试步骤:
验证点:
Mock配置:
cy.intercept('POST', '/auth/device/action', {
statusCode: 200,
body: {
code: '0x010001',
description: '设备通信失败',
solution: '检查设备连接'
}
}).as('resetDeviceFail');
测试目标: 验证loading期间按钮状态管理
前置条件:
测试步骤:
验证点:
Mock配置:
cy.intercept('POST', '/auth/device/action', (req) => {
req.reply({
statusCode: 200,
body: {
code: '0x000000',
description: 'Success',
data: {}
},
delay: 2000
});
}).as('resetDeviceDelay');
测试目标: 验证网络异常场景的错误处理
前置条件:
测试步骤:
验证点:
Mock配置:
cy.intercept('POST', '/auth/device/action', {
forceNetworkError: true
}).as('resetDeviceNetworkError');
测试目标: 验证loading状态下防止重复操作
前置条件:
测试步骤:
验证点:
Mock配置:
let requestCount = 0;
cy.intercept('POST', '/auth/device/action', (req) => {
requestCount++;
req.reply({
statusCode: 200,
body: {
code: '0x000000',
description: 'Success',
data: {}
},
delay: 3000
});
}).as('resetDeviceMultiple');
// 验证requestCount === 1
文件: cypress/support/pageObjects/ExamPage.ts
class ExamPage {
// ... 现有方法
/**
* 获取重置高压发生器按钮
*/
getResetGeneratorButton() {
return cy.get('[data-testid="reset-generator-btn"]');
}
/**
* 点击重置按钮
*/
clickResetGenerator() {
this.getResetGeneratorButton().click();
}
/**
* 验证重置按钮为启用状态
*/
verifyResetButtonEnabled() {
this.getResetGeneratorButton()
.should('be.visible')
.should('not.be.disabled');
}
/**
* 验证重置按钮为禁用状态
*/
verifyResetButtonDisabled() {
this.getResetGeneratorButton()
.should('be.visible')
.should('be.disabled');
}
/**
* 等待重置操作完成
*/
waitForResetComplete() {
cy.wait('@resetDevice');
this.verifyResetButtonEnabled();
}
/**
* 验证Redux设备状态
* @param expectedStatus - 期望的状态: 'idle' | 'loading' | 'succeeded' | 'failed'
*/
verifyDeviceStatus(expectedStatus: string) {
cy.window().its('store').invoke('getState')
.its('device').its('status')
.should('eq', expectedStatus);
}
/**
* 验证设备错误信息
* @param expectedError - 期望的错误信息,null表示无错误
*/
verifyDeviceError(expectedError: string | null) {
cy.window().its('store').invoke('getState')
.its('device').its('error')
.should('eq', expectedError);
}
}
文件: cypress/support/mock/handlers/deviceActions.ts
/**
* Mock设备重置成功响应
*/
export const mockResetDeviceSuccess = () => {
cy.intercept('POST', '/auth/device/action', (req) => {
if (req.body.reqName === 'RESET') {
req.reply({
statusCode: 200,
body: {
code: '0x000000',
description: 'Success',
data: {}
}
});
}
}).as('resetDevice');
};
/**
* Mock设备重置失败响应
* @param errorCode - 错误码,默认为'0x010001'
* @param description - 错误描述
*/
export const mockResetDeviceFail = (
errorCode: string = '0x010001',
description: string = '设备通信失败'
) => {
cy.intercept('POST', '/auth/device/action', {
statusCode: 200,
body: {
code: errorCode,
description: description,
solution: '检查设备连接'
}
}).as('resetDeviceFail');
};
/**
* Mock网络错误
*/
export const mockResetDeviceNetworkError = () => {
cy.intercept('POST', '/auth/device/action', (req) => {
if (req.body.reqName === 'RESET') {
req.reply({ forceNetworkError: true });
}
}).as('resetDeviceNetworkError');
};
/**
* Mock设备重置延迟响应
* @param delayMs - 延迟毫秒数
*/
export const mockResetDeviceDelay = (delayMs: number) => {
cy.intercept('POST', '/auth/device/action', (req) => {
if (req.body.reqName === 'RESET') {
req.reply({
statusCode: 200,
body: {
code: '0x000000',
description: 'Success',
data: {}
},
delay: delayMs
});
}
}).as('resetDeviceDelay');
};
/**
* Mock所有设备操作(用于其他测试场景)
*/
export const mockAllDeviceActions = () => {
cy.intercept('POST', '/auth/device/action', (req) => {
req.reply({
statusCode: 200,
body: {
code: '0x000000',
description: 'Success',
data: {}
}
});
}).as('deviceAction');
};
在RESET按钮添加测试标识:
<Button
data-testid="reset-generator-btn" // 新增测试标识
style={{ width: '1.5rem', height: '1.5rem' }}
icon={
<Icon
module="module-exam"
name="btn_ResetGenerator"
userId="base"
theme="default"
size="2x"
state="normal"
/>
}
title="重置参数"
onClick={handleResetParameters}
disabled={isResetting}
/>
每个测试用例都需要以下Mock:
多语言资源(必需)
mockI18nSuccess('zh_CN'); // 获取中文翻译资源
mockGetLanguageListSuccess(); // 获取语言列表
mockAllRequiredAPIs('zh_CN'); // Mock软件信息和日志API
权限检查 - LoginPage已处理
配额检查
Quota API Mock - LoginPage已处理
检查页面数据
患者信息 - WorklistPage已处理
体位列表 - 进入检查页面后自动加载
APR配置 - 进入检查页面后自动加载
// 测试前重置Redux状态
beforeEach(() => {
cy.window().its('store').invoke('dispatch', {
type: 'device/resetState'
});
});
错误码 | 描述 | 解决方案 |
---|---|---|
0x000000 | 成功 | - |
0x010001 | 设备通信失败 | 检查设备连接 |
0x010002 | 设备忙碌 | 等待设备空闲后重试 |
0x010003 | 参数错误 | 检查请求参数 |
0x010004 | 超时 | 检查网络连接 |
新建文件:
docs/测试/重置高压发生器功能测试方案.md
- 本文档cypress/e2e/exam/reset-generator.cy.ts
- 测试用例cypress/support/mock/handlers/deviceActions.ts
- Mock处理器修改文件:
cypress/support/pageObjects/ExamPage.ts
- 扩展POMsrc/pages/exam/ContentAreaLarge.tsx
- 添加data-testid接口: POST /auth/device/action
请求参数:
interface DeviceActionMessage {
deviceUri: string; // 设备URI
reqName: string; // 请求名称
reqParam: string; // 请求参数
reqTransaction: string; // 事务ID
reqClientID: string; // 客户端ID
}
响应格式:
interface DeviceActionResponse {
code: string; // 状态码
description: string; // 描述信息
solution?: string; // 解决方案(可选)
data?: any; // 响应数据(可选)
}