cmvr-wms/mobile-app/tests/usability-regression.test.mjs
lixiaolong cd86623061 feat(app): 添加服务器连接管理和到货操作功能
- 集成 ServerConnection 组件用于开发环境服务器切换
- 实现多服务器令牌隔离存储机制
- 添加 ArrivalOperation 屏幕处理到货和验收流程
- 支持待登记到货和待验收状态切换
- 优化库存操作界面的字段显示逻辑
- 增强 Excel 文件分片上传支持产品文件识别
- 添加 AI 助手会话滚动跟踪功能
- 实现开发服务器地址持久化存储
- 优化登录界面集成服务器连接组件
- 添加领用出库功能支持项目物资使用
- 改进盘点确认生效的操作流程
- 增强采购到货登记和验收的权限控制
- 优化移动端文件上传的断点续传机制
- 添加服务器切换时的数据清理保护机制
- 实现紧凑金额显示模式减少界面冗余
- 增强库存操作的数量验证和错误提示
- 优化 AI 助手的会话状态同步机制
2026-10-20 10:04:17 +08:00

62 lines
5.2 KiB
JavaScript

import test from 'node:test';
import assert from 'node:assert/strict';
import {readFile} from 'node:fs/promises';
import {createRequire} from 'node:module';
import vm from 'node:vm';
import * as helpers from '../src/core/assistant-display.ts';
const require=createRequire(import.meta.url),React=require('react'),{renderToStaticMarkup}=require('react-dom/server'),ts=require('typescript');
test('cancelled, completed and parked drafts cannot become active confirmations',()=>{
for(const status of ['CANCELLED','SUCCEEDED','PAUSED'])assert.equal(helpers.isActiveDraft({id:1,status},1),false);
assert.equal(helpers.draftStatus('PAUSED'),'已暂存');
assert.equal(helpers.isActiveDraft({id:1,status:'WAIT_CONFIRM'},'1'),true);
assert.equal(helpers.isActiveDraft({id:1,status:'WAIT_CONFIRM',readOnly:true},1),false);
assert.equal(helpers.isActiveDraft({id:2,status:'WAIT_CONFIRM'},1),false);
assert.equal(helpers.isActiveDraft({},undefined),false);
});
test('inventory prioritizes model and quantity; technical, empty and overflow values are recoverable',()=>{
const fields=['version','projectName','id','productName','spec','brand','stockNum','unit','areaName','remark','averageUnitCost'].map(key=>({key,label:key}));
const rows=[{id:1,version:0,productName:'路由器',spec:'AX5400',brand:null,stockNum:0,unit:'个',areaName:'A',projectName:'项目',averageUnitCost:0}];
const result=helpers.queryColumnGroups(fields,rows);
assert.deepEqual(result.primary.map(c=>c.key),['productName','spec','stockNum','unit','areaName','projectName','averageUnitCost']);
assert.equal(result.primary.length+result.details.length,fields.length);
assert.ok(result.details.some(c=>c.key==='version'));
});
// Render real TSX with strict native View doubles. An empty string is a text node,
// even though a browser may visually ignore it; Android cannot render it in View.
async function renderAssistant(session=null){
const source=await readFile(new URL('../src/screens/Assistant.tsx',import.meta.url),'utf8');
const compiled=ts.transpileModule(source,{compilerOptions:{module:ts.ModuleKind.CommonJS,jsx:ts.JsxEmit.ReactJSX,esModuleInterop:true}}).outputText;
const View=({children})=>{for(const value of React.Children.toArray(children))assert.ok(typeof value!=='string'&&typeof value!=='number','View contains bare text');return React.createElement('div',null,children);};
const Text=({children})=>React.createElement('span',null,children);
let calls=0;const mockReact={...React,useState:initial=>React.useState(calls++===0?session:initial)};
const module={exports:{}};
const imports={react:mockReact,'react/jsx-runtime':require('react/jsx-runtime'),'react-native':{View,Text,Pressable:View,ScrollView:View,KeyboardAvoidingView:View,ActivityIndicator:()=>null,Image:()=>null,Platform:{OS:'web'}},'../dialogs':{Dialog:{alert(){}}},'expo-document-picker':{},'../ui':{useTheme:()=>({text:'#000',muted:'#666',line:'#ddd'}),s:{},Button:({title})=>React.createElement(Text,null,title),Card:View,Heading:Text,Note:Text,Field:()=>null,Icon:()=>null},'../files':{ProtectedImage:()=>null},'../core/modules':{display:String},'../core/assistant-display':helpers};
vm.runInNewContext(compiled,{module,exports:module.exports,require:name=>name.endsWith('.png')?'asset':name in imports?imports[name]:require(name),setInterval,clearInterval});
return renderToStaticMarkup(React.createElement(module.exports.Assistant,{api:{}}));
}
test('initial empty session has no raw empty text under native View',async()=>{assert.match(await renderAssistant(),/不知道从哪里开始/);});
test('historical draft details are initially collapsed; current draft stays fully visible',async()=>{
const draft={id:1,label:'采购',status:'CANCELLED',rows:[{name:'HISTORICAL-DETAIL'}],fields:[{key:'name',label:'物品'}]};
assert.ok(!(await renderAssistant({messages:[{role:'assistant',content:'旧草稿',draft}]})).includes('HISTORICAL-DETAIL'));
const active={...draft,id:2,status:'WAIT_CONFIRM',rows:[{name:'ACTIVE-DETAIL'}],ready:false};
assert.match(await renderAssistant({messages:[{role:'assistant',content:'当前草稿',draft:active}],draft:active}),/ACTIVE-DETAIL/);
});
test('preview confirmation portal is not mounted beneath later business dialogs',async()=>{
const source=await readFile(new URL('../src/dialogs.tsx',import.meta.url),'utf8');
assert.match(source,/if\(Platform\.OS!=='web'\|\|!prompt\)return null/);
});
test('move form shows availability, has fill-all action, and keeps overstock validation',async()=>{
const source=await readFile(new URL('../src/App.tsx',import.meta.url),'utf8');
assert.match(source,/当前可用数量/);assert.match(source,/title="全部移库"/);
assert.match(source,/n>Number\(row.stockNum\)/);
assert.match(source,/本次数量超过当前可用库存(\$\{display\(row.stockNum\)\}/);
});
test('expanding history and more fields does not force readers back to the latest message',async()=>{
const source=await readFile(new URL('../src/screens/Assistant.tsx',import.meta.url),'utf8');
assert.match(source,/inspectHistory=\(\)=>\{followLatest.current=false/);
assert.match(source,/if\(followLatest.current\)scroll.current\?\.scrollToEnd/);
assert.match(source,/onInspect\(\);setHistoryOpen/);assert.match(source,/onInspect\(\);setMore/);
});