123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312 |
- /**
- * I18n Mock Handlers
- * 国际化相关的 mock 处理器
- */
- /**
- * 获取多语言列表 - 成功场景
- *
- * @description 获取系统支持的语言列表
- * @method GET
- * @url /dr/api/v1/pub/language
- * @access 公开接口
- *
- * @returns {Object[]} data - 语言列表
- * @returns {string} data[].language - 语言代码(en/zh)
- * @returns {string} data[].display - 语言显示名称
- *
- * @example
- * mockGetLanguageListSuccess();
- * cy.wait('@getLanguageListSuccess').its('response.body.data').should('have.length', 2);
- *
- * @see docs/DR.md - 章节4
- */
- export function mockGetLanguageListSuccess() {
- cy.intercept('GET', '/dr/api/v1/pub/language', {
- statusCode: 200,
- body: {
- code: "0x000000",
- data: [
- {
- language: "en",
- display: "English"
- },
- {
- language: "zh",
- display: "简体中文"
- }
- ],
- description: "Success",
- solution: ""
- }
- }).as('getLanguageListSuccess');
- }
- /**
- * 获取多语言列表 - 空列表场景
- *
- * @description 获取多语言列表,返回空列表
- * @method GET
- * @url /dr/api/v1/pub/language
- * @access 公开接口
- *
- * @returns {Object[]} data - 空语言列表
- *
- * @example
- * mockGetLanguageListEmpty();
- * cy.wait('@getLanguageListEmpty');
- *
- * @see docs/DR.md - 章节4
- */
- export function mockGetLanguageListEmpty() {
- cy.intercept('GET', '/dr/api/v1/pub/language', {
- statusCode: 200,
- body: {
- code: "0x000000",
- data: [],
- description: "Success",
- solution: ""
- }
- }).as('getLanguageListEmpty');
- }
- /**
- * 获取翻译文件 - 成功场景
- *
- * @description 获取指定语言的翻译文件
- * @method GET
- * @url /dr/api/v1/pub/trans/{locale}/{locale}.js
- * @access 公开接口
- *
- * @param {string} locale - 语言代码(zh/en)
- *
- * @returns {Object} 翻译键值对
- *
- * @example
- * mockI18nSuccess('zh');
- * cy.wait('@getI18nZHSuccess');
- *
- * @see docs/DR.md - 章节3
- */
- 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();
- }
|