cmvr-wms/mobile-app/tests/arrival-list.test.mjs
lixiaolong d37b4ff379 refactor(mobile): 重构移动端应用结构和配置
- 将 Account 组件中的 Text 导入移动到顶部
- 移除 App.tsx 中的 expo-updates 相关代码
- 添加 PackageUpdates 相关组件和 hooks
- 更新应用名称从 "CMVR 物资管理" 为 "车研物资"
- 添加应用图标和自适应图标配置
- 更新 Android 权限配置,添加 REQUEST_INSTALL_PACKAGES 权限
- 修改堆栈导航数据结构,支持路由参数传递
- 添加阅读尺寸偏好设置功能
- 重构登录界面为独立组件 LoginView
- 添加文件库界面组件 FileLibrary
- 更新状态栏样式逻辑
- 调整 Tab 栏样式和尺寸
- 集成包更新和应用更新对话框
- 修复导入语句顺序和类型引用
- 优化业务列表组件的路由参数处理
- 添加作用域参数用于 API 请求区分
2026-10-28 17:30:35 +08:00

44 lines
3.8 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';
import {arrivalListQuery} from '../src/core/arrival-list.ts';
import {arrivalLayout} from '../src/core/arrival-layout.ts';
test('registration queue asks the server for confirmed eligible purchases, not all not-yet-accepted purchases',()=>{
assert.deepEqual(arrivalListQuery('arrival'),{pendingRegistration:true,arrivalReady:true,priceLocked:true});
assert.deepEqual(arrivalListQuery('accept'),{pendingAcceptance:true,priceLocked:true});
});
const require=createRequire(import.meta.url),React=require('react'),ts=require('typescript');
const source=readFileSync(new URL('../src/screens/ArrivalListParts.tsx',import.meta.url),'utf8');
const compiled=ts.transpileModule(source,{compilerOptions:{module:ts.ModuleKind.CommonJS,jsx:ts.JsxEmit.ReactJSX,esModuleInterop:true}}).outputText;
const exports={};
vm.runInNewContext(compiled,{exports,require:name=>({react:React,'react/jsx-runtime':require('react/jsx-runtime'),
'react-native':{ActivityIndicator:'Loading',Pressable:'Pressable',Text:'Text',TextInput:'TextInput',View:'View',useWindowDimensions:()=>({width:393,fontScale:1})},
'../typography':{Text:'Text',TextInput:'TextInput'},'../core/arrival-layout':{arrivalLayout},'../ui':{Card:'Card',Icon:'Icon',useTheme:()=>({})},'../core/modules':{display:v=>v==null?'—':String(v)}}[name]||require(name))});
function nodes(tree){const all=[];function walk(n){if(!n||typeof n!=='object')return;all.push(n);React.Children.toArray(n.props?.children).forEach(walk);}walk(tree);return all;}
test('compact queue tabs have equal width, correct state, accessible search and explicit clear',()=>{
const calls=[];const tree=exports.ArrivalListTools({query:'水冷',setQuery:v=>calls.push(v),queue:'accept',setQueue:v=>calls.push(v),busy:false,search:()=>calls.push('search'),reset:()=>calls.push('reset'),total:25,page:2});
const all=nodes(tree),tabs=all.filter(n=>n.props.accessibilityRole==='tab');
assert.equal(tabs.length,2);assert.deepEqual(tabs.map(n=>n.props.style.flex),[1,1]);
assert.deepEqual(tabs.map(n=>n.props.accessibilityState.selected),[false,true]);tabs[0].props.onPress();
all.find(n=>n.type==='TextInput').props.onSubmitEditing();all.find(n=>n.props.accessibilityLabel==='清除搜索').props.onPress();
assert.deepEqual(calls,['arrival','search','reset']);
});
test('acceptance card keeps quantity and unit together without a tall fixed-size badge',()=>{
const all=nodes(exports.ArrivalCard({item:{materialName:'很长的物品名称',materialParams:'规格',remainingQuantity:0,pendingArrivalQuantity:18,unit:'很长的测试单位'},queue:'accept',children:null}));
assert.ok(all.some(n=>n.type==='Text'&&n.props.children==='18'));
assert.ok(all.some(n=>n.type==='Text'&&n.props.children==='很长的测试单位'&&n.props.style.fontSize===14));
assert.ok(all.some(n=>n.type==='Text'&&n.props.children==='待验收'));
assert.ok(all.some(n=>n.type==='View'&&n.props.style.flexDirection==='row'&&React.Children.toArray(n.props.children).some(c=>c.props?.children==='18')&&React.Children.toArray(n.props.children).some(c=>c.props?.children==='很长的测试单位')));
assert.ok(all.filter(n=>n.type==='Text').every(n=>n.props.style.fontSize>=12));
assert.ok(all.filter(n=>n.type==='View').every(n=>n.props.style.width!==94));
});
test('query state survives queue changes and pagination uses applied search rather than unsent text',()=>{
const app=readFileSync(new URL('../src/screens/BusinessList.tsx',import.meta.url),'utf8');
assert.match(app,/arrivalListQuery\(arrivalQueue\)/);
assert.match(app,/load\(1,appliedQuery\.current\)/);
assert.match(app,/load\(page\+1,appliedQuery\.current,true\)/);
assert.doesNotMatch(app,/notArrived:arrivalQueue/);
});