cmvr-wms/mobile-app/tests/update-dialog.test.mjs
lixiaolong 6b43b0104f feat(app): 优化移动端应用配置和功能实现
- 添加生产环境服务器地址配置支持内外网切换
- 实现采购列表只看我创建的功能开关
- 更新构建脚本中的默认生产环境API地址
- 优化采购单表格单元格编辑体验改用自动补全组件
- 调整应用更新检查逻辑增强生产环境兼容性
- 修复开发服务器切换时的一些验证问题
- 增强应用启动时的服务地址配置灵活性
2026-10-30 15:02:54 +08:00

13 lines
2.3 KiB
JavaScript

import test from 'node:test';import assert from 'node:assert/strict';import {readFileSync} from 'node:fs';import {createRequire} from 'node:module';import vm from 'node:vm';
const require=createRequire(import.meta.url),React=require('react'),ts=require('typescript');
const imports={'./typography':{Text:'Text'},'./UpdateNotes':{UpdateNotes:'UpdateNotes'},react:React,'react/jsx-runtime':require('react/jsx-runtime'),'react-native':{Modal:'Modal',View:'View',Text:'Text',ScrollView:'ScrollView'},'./ui':{Button:'Button',Icon:'Icon',Note:'Note',useTheme:()=>({})}};
const module={exports:{}};vm.runInNewContext(ts.transpileModule(readFileSync(new URL('../src/AppUpdateDialog.tsx',import.meta.url),'utf8'),{compilerOptions:{module:ts.ModuleKind.CommonJS,jsx:ts.JsxEmit.ReactJSX,esModuleInterop:true}}).outputText,{module,exports:module.exports,require:n=>imports[n]||require(n)});
function render(patch={}){const called=[];const tree=module.exports.AppUpdateDialog({view:{state:'ready',visible:true,restarting:false,error:'',...patch},later:()=>called.push('later'),restart:()=>called.push('restart')});const nodes=[];function walk(n){if(!n||typeof n!=='object')return;nodes.push(n);React.Children.toArray(n.props?.children).forEach(walk);}walk(tree);return {tree,nodes,called};}
test('the update popup waits for readiness and exposes explicit postpone/restart actions',()=>{
assert.equal(render({visible:false}).tree,null);const r=render();assert.deepEqual(r.called,[]);assert.equal(r.tree.type,'Modal');const buttons=r.nodes.filter(n=>n.type==='Button');assert.deepEqual(buttons.map(n=>n.props.title),['重启并更新','稍后再说']);buttons[1].props.onPress();buttons[0].props.onPress();assert.deepEqual(r.called,['later','restart']);assert(r.nodes.some(n=>n.type==='Note'&&String(n.props.children).includes('未提交的内容不会保留')));
});
test('reload progress disables postponing; failure stays visible with retry instructions',()=>{
const busy=render({restarting:true});assert.equal(busy.nodes.find(n=>n.type==='Button'&&n.props.title==='稍后再说').props.disabled,true);assert.equal(busy.nodes.find(n=>n.type==='Button'&&n.props.title==='正在重启…').props.busy,true);
const failed=render({error:'请重试'});assert(failed.nodes.some(n=>n.type==='Text'&&n.props.children==='请重试'));assert.equal(failed.tree.props.onRequestClose instanceof Function,true);
});