Files
xianyan/test/l10n/translation_coverage_test.dart
Developer 10a917adf6 修补
2026-06-26 09:07:55 +08:00

82 lines
2.8 KiB
Dart
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
/// ============================================================
/// 闲言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');
}
}
}
}
});
});
}