82 lines
2.8 KiB
Dart
82 lines
2.8 KiB
Dart
/// ============================================================
|
||
/// 闲言APP — 翻译覆盖率检测测试
|
||
/// 创建时间: 2026-05-29
|
||
/// 更新时间: 2026-06-26
|
||
/// 作用: CI翻译覆盖率检测,确保各语言翻译完整度
|
||
/// 上次更新: 添加 avoid_print 文件级忽略(测试诊断输出)
|
||
/// ============================================================
|
||
|
||
// ignore_for_file: avoid_print
|
||
|
||
import 'package:flutter_test/flutter_test.dart';
|
||
import 'package:xianyan/l10n/translation_coverage.dart';
|
||
|
||
void main() {
|
||
group('TranslationCoverage', () {
|
||
test('totalFieldCount should be positive', () {
|
||
expect(TranslationCoverage.totalFieldCount, greaterThan(0));
|
||
});
|
||
|
||
test('zh_CN should have 100% coverage', () {
|
||
expect(TranslationCoverage.getProgressPercent('zh_CN'), equals(100));
|
||
});
|
||
|
||
test('all languages should have at least 50% coverage', () {
|
||
final report = TranslationCoverage.fullReport();
|
||
for (final entry in report.entries) {
|
||
final percent = entry.value['percent'] as int;
|
||
expect(
|
||
percent,
|
||
greaterThanOrEqualTo(50),
|
||
reason: '${entry.key} has only $percent% coverage',
|
||
);
|
||
}
|
||
});
|
||
|
||
test('no language should have zero translations', () {
|
||
final report = TranslationCoverage.fullReport();
|
||
for (final entry in report.entries) {
|
||
final translated = entry.value['translated'] as int;
|
||
expect(
|
||
translated,
|
||
greaterThan(0),
|
||
reason: '${entry.key} has zero translations',
|
||
);
|
||
}
|
||
});
|
||
|
||
test('coverage report should include all languages', () {
|
||
final report = TranslationCoverage.fullReport();
|
||
expect(report.containsKey('zh_CN'), isTrue);
|
||
expect(report.containsKey('en'), isTrue);
|
||
expect(report.containsKey('ja'), isTrue);
|
||
expect(report.containsKey('zh_TW'), isTrue);
|
||
expect(report.containsKey('es'), isTrue);
|
||
expect(report.containsKey('ar'), isTrue);
|
||
expect(report.containsKey('bn'), isTrue);
|
||
expect(report.containsKey('hi'), isTrue);
|
||
expect(report.containsKey('pt'), isTrue);
|
||
expect(report.containsKey('ru'), isTrue);
|
||
expect(report.containsKey('fr'), isTrue);
|
||
});
|
||
|
||
test('checkCoverage should detect empty fields', () {
|
||
final report = TranslationCoverage.fullReport();
|
||
for (final entry in report.entries) {
|
||
if (entry.key != 'zh_CN') {
|
||
final missing = entry.value['missing'] as List;
|
||
if (missing.isNotEmpty) {
|
||
print('${entry.key}: ${missing.length} missing fields');
|
||
for (final field in missing.take(5)) {
|
||
print(' - $field');
|
||
}
|
||
if (missing.length > 5) {
|
||
print(' ... and ${missing.length - 5} more');
|
||
}
|
||
}
|
||
}
|
||
}
|
||
});
|
||
});
|
||
}
|