2026-10-18 08:49:30 +08:00
import test from 'node:test' ;
import assert from 'node:assert/strict' ;
import { readFileSync } from 'node:fs' ;
import ts from 'typescript' ;
const source = name => readFileSync ( new URL ( ` ../src/ ${ name } ` , import . meta . url ) , 'utf8' ) ;
test ( 'mobile JSX has no unexpected literal text below a native View' , ( ) => {
2026-10-30 15:02:54 +08:00
for ( const file of [ 'App.tsx' , 'AppUpdates.tsx' , 'AppUpdateDialog.tsx' , 'VersionUpdates.tsx' , 'UpdateNotes.tsx' , 'PackageUpdates.tsx' , 'ui.tsx' , 'files.tsx' , 'dialogs.tsx' , 'screens/Account.tsx' , 'screens/Feedback.tsx' , 'screens/Workspace.tsx' , 'screens/Assistant.tsx' , 'screens/ArrivalOperation.tsx' , 'screens/ArrivalActions.tsx' , 'screens/ArrivalListParts.tsx' , 'screens/ServerConnection.tsx' , 'screens/BusinessList.tsx' , 'screens/BatchOperation.tsx' , 'screens/NoticeContent.tsx' , 'screens/FileLibrary.tsx' , 'controls/Choice.tsx' , 'controls/DateField.tsx' ] ) {
2026-10-18 08:49:30 +08:00
const parsed = ts . createSourceFile ( file , source ( file ) , ts . ScriptTarget . Latest , true , ts . ScriptKind . TSX ) ;
function walk ( node ) { if ( ts . isJsxElement ( node ) && [ 'View' , 'ScrollView' , 'Pressable' , 'KeyboardAvoidingView' , 'SafeAreaView' ] . includes ( node . openingElement . tagName . getText ( parsed ) ) ) for ( const child of node . children ) if ( ts . isJsxText ( child ) ) assert . equal ( child . text . trim ( ) , '' , ` ${ file } has bare native text ` ) ; ts . forEachChild ( node , walk ) ; } walk ( parsed ) ;
}
2026-10-28 17:30:35 +08:00
assert . match ( source ( 'screens/BusinessList.tsx' ) , /\{!!module\.search&&/ , 'an empty search key must not render a raw string in View' ) ;
2026-10-18 08:49:30 +08:00
} ) ;
test ( 'mobile feedback is always scoped to my records and never calls administrative handling' , ( ) => {
const file = source ( 'screens/Feedback.tsx' ) ; assert . match ( file , /all:false/ ) ; assert . doesNotMatch ( file , /all:true|\/handle/ ) ;
assert . match ( file , /setUncertain\(unknown\)/ ) ; assert . match ( file , /lock\.current\|\|uncertain/ ) ;
} ) ;
test ( 'AI stays mounted across tab switches; no implicit business submit or reload on update' , ( ) => {
const app = source ( 'App.tsx' ) ; assert . match ( app , /aiVisited&&ai/ ) ; assert . match ( app , /display:!page&&tab==='assistant'\?'flex':'none'/ ) ;
2026-10-20 10:04:17 +08:00
assert . match ( source ( 'screens/Assistant.tsx' ) , /onAction=\{draftAction\}/ ) ; assert . match ( source ( 'screens/Assistant.tsx' ) , /onAction\(draft,'execute'\)/ ) ; assert . match ( source ( 'screens/Assistant.tsx' ) , /Alert\.alert\('确认执行业务'/ ) ;
2026-10-18 08:49:30 +08:00
assert . doesNotMatch ( app , /reloadAsync/ ) ;
} ) ;