// I18n-related mock handlers // 封装获取多语言资源成功的 mock export function mockI18nSuccess(locale: 'zh' | 'en') { const mockData = locale === 'zh' ? { greeting: '你好,世界!', name: '张三', patient: '患者管理', register: '注册', tasklist: '任务清单', historylist: '历史清单', archivelist: '归档清单', bin: '回收站', outputlist: '传输清单', exam: '检查', examlist: '检查清单', process: '处理', print: '打印', printlist: '打印清单', worklist: '任务清单', 'worklist.operationPanel': '操作面板', 'register.basicInfoPanel': '基本信息表单区域', 'register.protocolListPanel': '待选择协议列表区域', 'register.selectedProtocolListPanel': '已选择协议列表区域', 'worklistTable.patientId': '患者编号', 'worklistTable.name': '患者姓名', 'register.patientId': '患者编号', 'register.patientName': '患者姓名', 'register.gender': '性别', 'register.gender.male': '男', 'register.gender.female': '女' } : { greeting: 'Hello, world!', name: 'John Doe', patient: 'Patient Management', register: 'Register', tasklist: 'Task List', historylist: 'History List', archivelist: 'Archive List', bin: 'Recycle Bin', outputlist: 'Transfer List', exam: 'Examination', examlist: 'Examination List', process: 'Process', print: 'Print', printlist: 'Print List', worklist: 'Task List', 'worklist.operationPanel': 'Operation Panel', 'register.basicInfoPanel': 'Basic Information Form Area', 'register.protocolListPanel': 'Protocol Selection List Area', 'register.selectedProtocolListPanel': 'Selected Protocol List Area', 'worklistTable.patientId': 'Patient ID', 'worklistTable.name': 'Patient Name', 'register.patientId': 'Patient ID', 'register.patientName': 'Patient Name', 'register.gender': 'Gender', 'register.gender.male': 'Male', 'register.gender.female': 'Female' }; cy.intercept('GET', `/dr/api/v1/pub/trans/${locale}/${locale}.js`, (req) => { req.reply({ statusCode: 200, body: mockData }); }).as(`getI18n${locale.toUpperCase()}Success`); } // 封装获取多语言资源失败的 mock (404错误) export function mockI18nError(locale: 'zh' | 'en') { cy.intercept('GET', `/dr/api/v1/pub/trans/${locale}/${locale}.js`, (req) => { req.reply({ statusCode: 404, body: { message: 'Not Found', error: 'Translation file not found' } }); }).as(`getI18n${locale.toUpperCase()}Error`); } // 封装获取多语言资源服务器错误的 mock (500错误) export function mockI18nServerError(locale: 'zh' | 'en') { cy.intercept('GET', `/dr/api/v1/pub/trans/${locale}/${locale}.js`, (req) => { req.reply({ statusCode: 500, body: { message: 'Internal Server Error', error: 'Server error occurred' } }); }).as(`getI18n${locale.toUpperCase()}ServerError`); } // 封装获取多语言资源超时的 mock export function mockI18nTimeout(locale: 'zh' | 'en') { cy.intercept('GET', `/dr/api/v1/pub/trans/${locale}/${locale}.js`, (req) => { req.reply({ delay: 30000, // 30秒延迟,模拟超时 statusCode: 200, body: {} }); }).as(`getI18n${locale.toUpperCase()}Timeout`); } // 封装获取多语言资源格式错误的 mock export function mockI18nInvalidFormat(locale: 'zh' | 'en') { cy.intercept('GET', `/dr/api/v1/pub/trans/${locale}/${locale}.js`, (req) => { req.reply({ statusCode: 200, body: "invalid json format" // 返回非JSON格式数据 }); }).as(`getI18n${locale.toUpperCase()}InvalidFormat`); } // 封装获取多语言资源空数据的 mock export function mockI18nEmptyData(locale: 'zh' | 'en') { cy.intercept('GET', `/dr/api/v1/pub/trans/${locale}/${locale}.js`, (req) => { req.reply({ statusCode: 200, body: {} // 返回空对象 }); }).as(`getI18n${locale.toUpperCase()}EmptyData`); } // 封装获取多语言资源网络错误的 mock export function mockI18nNetworkError(locale: 'zh' | 'en') { cy.intercept('GET', `/dr/api/v1/pub/trans/${locale}/${locale}.js`, (req) => { req.reply({ forceNetworkError: true }); }).as(`getI18n${locale.toUpperCase()}NetworkError`); } // 封装软件信息API的 mock,避免影响页面加载 export function mockSoftwareInfo() { cy.intercept('GET', '/dr/api/v1/pub/software_info', (req) => { req.reply({ statusCode: 200, body: { code: "0x000000", data: { FPD: "Simulator", GEN: "Simulator", guest: "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJleHAiOjE3NTY3MjAxMTUsImlkIjoyLCJuYW1lIjoiZ3Vlc3QifQ.cDkkxM2mkiCQf7T87WsCMewITk13c7jSDoniT7gDHXQ", language: ["en", "zh"], product: "DROS", server: { auth: { build: "2025-08-25 17:45:18", desc: "Authentication Server repo", submodule: ["3a167dd4[rpc_idl]"], version: "0.3.0-13-g8b85622" }, dcmtk: { build: "2025-08-25 13:43:16", desc: "Dcmtk Server repo", submodule: ["0fc2b1e4[rpc_idl]"], version: "0.3.0-12-gff618d4" }, imgProc: { build: "2025-08-25 13:46:23", desc: "Img Proc Server repo", submodule: [ "5e507af7[auto_wwwl]", "3a75bb1f[collimator_circle]", "e7b69785[collimator_rect]", "6b7fbbd1[enhance]", "5905e001[rpc_idl]" ], version: "0.3.0-7-gbb2ee0b" }, protocol: { build: "2025-08-25 17:45:23", desc: "Protocol Server repo", submodule: ["3a167dd4[rpc_idl]"], version: "0.3.0-7-g1954756" }, resource: { build: "2025-08-25 17:45:27", desc: "Resource Server repo", submodule: ["0fc2b1e4[rpc_idl]"], version: "0.3.0-12-g60e37c1" }, study: { build: "2025-08-25 17:45:25", desc: "Study Server repo", submodule: ["3a167dd4[rpc_idl]"], version: "0.3.0-11-g784ba1b" }, task: { build: "2025-08-25 17:45:29", desc: "Task Server repo", submodule: ["0fc2b1e4[rpc_idl]"], version: "0.3.0-20-ge9ec04a" } }, sn: "2edbc382-044adc78-95bed11b-51c9328a" }, description: "Success", solution: "" } }); }).as('getSoftwareInfo'); } // 封装logger API的 mock,避免影响页面加载 export function mockLogger() { cy.intercept('POST', '/log', (req) => { req.reply({ statusCode: 204, // No Content - 更适合日志请求,不会被误认为页面导航 body: null, // 明确返回 null,避免任何可能的页面影响 headers: { 'content-type': 'application/json', 'cache-control': 'no-cache' } }); }).as('postLog'); } // 封装所有必要的API mock,避免影响页面加载 export function mockAllRequiredAPIs() { mockSoftwareInfo(); mockLogger(); }