2026-10-21 15:13:39 +08:00
|
|
|
import test from 'node:test';
|
|
|
|
|
import assert from 'node:assert/strict';
|
|
|
|
|
import {createRequire} from 'node:module';
|
|
|
|
|
import {readFileSync} from 'node:fs';
|
|
|
|
|
import vm from 'node:vm';
|
|
|
|
|
import {arrivalLayout} from '../src/core/arrival-layout.ts';
|
|
|
|
|
import {workspaceColumns} from '../src/core/workspace-layout.ts';
|
2026-10-28 17:30:35 +08:00
|
|
|
import {workspaceTasks,shortcutOrder} from '../src/core/workspace-tasks.ts';
|
2026-10-21 15:13:39 +08:00
|
|
|
import {modules} from '../src/core/modules.ts';
|
|
|
|
|
|
|
|
|
|
test('home tiles switch to a single column on narrow screens and larger system text',()=>{
|
|
|
|
|
for(const [width,fontScale,columns] of [[320,1,1],[360,1,2],[393,1,2],[480,1,2],[360,1.3,1],[393,1.6,1],[480,2,1]])
|
|
|
|
|
assert.equal(workspaceColumns(width,fontScale),columns,`${width}/${fontScale}`);
|
|
|
|
|
});
|
|
|
|
|
test('arrival labels never keep a fixed small column when system fonts need more room',()=>{
|
|
|
|
|
assert.equal(arrivalLayout(393,1).stackedHeader,false);
|
|
|
|
|
assert.equal(arrivalLayout(320,1).stackedHeader,true);
|
|
|
|
|
for(const width of [320,360,393,480])for(const scale of [1,1.3,1.6,2]){
|
|
|
|
|
const layout=arrivalLayout(width,scale);
|
|
|
|
|
assert.ok(layout.labelWidth>=58*scale);
|
|
|
|
|
if((Math.min(width,480)-60)/scale<240)assert.equal(layout.stackedDetails,true);
|
|
|
|
|
}
|
|
|
|
|
assert.deepEqual(arrivalLayout(NaN,NaN),arrivalLayout(360,1));
|
|
|
|
|
});
|
|
|
|
|
const require=createRequire(import.meta.url),React=require('react'),ts=require('typescript');
|
|
|
|
|
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;}
|
|
|
|
|
function compile(name,imports){const exports={};const code=ts.transpileModule(readFileSync(new URL('../src/'+name,import.meta.url),'utf8'),{compilerOptions:{module:ts.ModuleKind.CommonJS,jsx:ts.JsxEmit.ReactJSX,esModuleInterop:true}}).outputText;
|
|
|
|
|
vm.runInNewContext(code,{exports,require:n=>Object.hasOwn(imports,n)?imports[n]:n.endsWith('.png')?1:require(n)});return exports;}
|
|
|
|
|
test('home keeps all allowed field-operation shortcuts without the oversized marketing block',()=>{
|
|
|
|
|
for(const width of [320,360,393])for(const fontScale of [1,1.3,1.6]){
|
|
|
|
|
const opened=[],visited=[];
|
2026-10-28 17:30:35 +08:00
|
|
|
const module=compile('screens/Workspace.tsx',{react:{...React,useState:v=>[typeof v==='function'?v():v,()=>{}],useEffect:()=>{}},'react/jsx-runtime':require('react/jsx-runtime'),
|
2026-10-21 15:13:39 +08:00
|
|
|
'react-native':{Image:'Image',Pressable:'Pressable',ScrollView:'ScrollView',Text:'Text',View:'View',useWindowDimensions:()=>({width,fontScale})},
|
|
|
|
|
'expo-constants':{},'expo-updates':{},'../ui':{Card:'Card',Icon:'Icon',Avatar:'Avatar',Heading:'Heading',Note:'Note',s:{row:{},page:{}},useTheme:()=>({})},
|
2026-10-28 17:30:35 +08:00
|
|
|
'../typography':{Text:'Text',useReadingScale:()=>1},'../core/preferences':{},'../core/workspace-tasks':{workspaceTasks,shortcutOrder},'../core/workspace-layout':{workspaceColumns},'../core/account':{imagePath:()=>''},'../files':{usePrivateImage:()=>undefined}});
|
2026-10-21 15:13:39 +08:00
|
|
|
const all=nodes(module.Workspace({api:{},user:{userName:'测试管理员'},modules,ai:true,open:v=>opened.push(v),go:v=>visited.push(v)}));
|
2026-10-30 15:02:54 +08:00
|
|
|
for(const title of ['到货验收','待入库','物料领用','移库','现场盘点']){
|
2026-10-28 17:30:35 +08:00
|
|
|
const node=all.find(n=>n.props.accessibilityLabel===title&&typeof n.props.style==='function');assert.ok(node);node.props.onPress();
|
2026-10-21 15:13:39 +08:00
|
|
|
assert.equal(node.props.style({pressed:false}).flexBasis,workspaceColumns(width,fontScale)===1?'100%':'47%');
|
|
|
|
|
}
|
|
|
|
|
assert.deepEqual(opened,['arrival','pending','use','move','count']);
|
2026-10-28 17:30:35 +08:00
|
|
|
all.find(n=>n.props.title==='全部业务').props.onPress();assert.deepEqual(visited,['business']);
|
|
|
|
|
assert.ok(all.filter(n=>n.type==='Text').every(n=>(n.props.style.fontSize||0)<=22));
|
2026-10-21 15:13:39 +08:00
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
test('shared reading and button text have explicit sizes, wrap safely and keep system scaling enabled',()=>{
|
|
|
|
|
const ui=compile('ui.tsx',{react:{...React,useContext:()=>({mode:'light'})},'react/jsx-runtime':require('react/jsx-runtime'),
|
|
|
|
|
'react-native':{ActivityIndicator:'Loading',Image:'Image',Pressable:'Pressable',ScrollView:'ScrollView',Text:'Text',TextInput:'TextInput',View:'View',StyleSheet:{create:v=>v},useColorScheme:()=> 'light'},
|
2026-10-28 17:30:35 +08:00
|
|
|
'@expo/vector-icons/Ionicons':'Icon','./core/appearance':{lightTheme:{},darkTheme:{}},'./typography':{Text:'Text',TextInput:'TextInput'},'./controls/Choice':{Choice:'Choice'},'./controls/DateField':{DateField:'DateField'}});
|
2026-10-21 15:13:39 +08:00
|
|
|
const button=nodes(ui.Button({title:'核对后重试原请求',onPress(){}})).find(n=>n.type==='Text');
|
2026-10-28 17:30:35 +08:00
|
|
|
assert.equal(button.props.style.fontSize,14);assert.equal(button.props.style.flexShrink,1);
|
|
|
|
|
assert.equal(ui.Note({children:'说明'}).props.style.fontSize,13);
|
|
|
|
|
assert.equal(ui.Heading({children:'标题'}).props.style.fontSize,18);
|
2026-10-21 15:13:39 +08:00
|
|
|
assert.ok(ui.s.button.minHeight>=44);assert.equal(ui.s.button.height,undefined);
|
|
|
|
|
for(const file of ['ui.tsx','screens/Workspace.tsx','screens/ArrivalListParts.tsx'])assert.doesNotMatch(readFileSync(new URL('../src/'+file,import.meta.url),'utf8'),/allowFontScaling=\{false\}/);
|
|
|
|
|
});
|