app scaffold

This commit is contained in:
Guangfei.Zhao
2026-08-17 15:29:55 +08:00
commit 681688dfae
301 changed files with 18414 additions and 0 deletions
@@ -0,0 +1,55 @@
import 'package:core_foundation/core_foundation.dart';
import 'package:flutter_test/flutter_test.dart';
void main() {
group('AppException', () {
test('每个子类都有稳定且互不冲突的 bridgeCode', () {
const List<AppException> all = <AppException>[
NetworkException('x'),
BusinessException(1, 'x'),
ServerException('x'),
UnauthorizedException(),
RequestCancelledException(),
PreconditionException('x'),
StorageException(),
NativeException(NativeErrorCode.permissionDenied, 'x'),
];
final Set<String> codes = all.map((AppException e) => e.bridgeCode).toSet();
expect(codes.length, all.length, reason: 'bridgeCode 是 H5 的分支依据,不能有重复');
for (final String code in codes) {
expect(code, matches(RegExp(r'^[A-Z][A-Z_]+$')), reason: '必须是大写下划线常量风格');
}
});
test('toString 带上 traceId 但不带堆栈', () {
const AppException e = ServerException('系统繁忙', statusCode: 502, traceId: 'abc123');
expect(e.toString(), contains('abc123'));
expect(e.toString(), contains('系统繁忙'));
});
});
group('AppFlavor', () {
test('只接受三个已知 flavor', () {
expect(AppFlavor.parse('dev'), AppFlavor.dev);
expect(AppFlavor.parse('uat'), AppFlavor.uat);
expect(AppFlavor.parse('prod'), AppFlavor.prod);
expect(() => AppFlavor.parse('staging'), throwsArgumentError);
});
});
group('AppEnv', () {
test('isProd / flavorSuffixVisible 按 flavor 判定', () {
const AppEnv env = AppEnv(
flavor: AppFlavor.dev,
apiBaseUrl: 'https://api-dev.conti.com',
enableLog: true,
sentryDsn: '',
h5AllowedHosts: <String>{'f6.conti.com'},
);
expect(env.isProd, isFalse);
expect(env.flavorSuffixVisible, isTrue);
expect(env.h5AllowedHosts, contains('f6.conti.com'));
});
});
}