fix(i18n): 印尼语内容缺失时不再回退中文
This commit is contained in:
1 parent
9ef8eb15b0
commit
19196ceb8e
13 files changed
+261
-95
No files matched your search
@@ -1,37 +1,44 @@
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:fruitshorts/core/data/models/drama.dart';
|
||||
import 'package:fruitshorts/core/formatting/localized_content.dart';
|
||||
import 'package:fruitshorts/core/formatting/content_locale_guard.dart';
|
||||
import 'package:fruitshorts/l10n/app_localizations_en.dart';
|
||||
import 'package:fruitshorts/l10n/app_localizations_id.dart';
|
||||
import 'package:fruitshorts/l10n/app_localizations_zh.dart';
|
||||
|
||||
Drama _drama({required String id, String title = 'raw', String synopsis = 'raw'}) =>
|
||||
Drama(
|
||||
id: id,
|
||||
title: title,
|
||||
synopsis: synopsis,
|
||||
posterUrl: '/files/poster.png',
|
||||
episodes: const [],
|
||||
);
|
||||
Drama _drama({
|
||||
required String id,
|
||||
String title = 'raw',
|
||||
String synopsis = 'raw',
|
||||
}) => Drama(
|
||||
id: id,
|
||||
title: title,
|
||||
synopsis: synopsis,
|
||||
posterUrl: '/files/poster.png',
|
||||
episodes: const [],
|
||||
);
|
||||
|
||||
void main() {
|
||||
final en = AppLocalizationsEn();
|
||||
final zh = AppLocalizationsZh();
|
||||
final id = AppLocalizationsId();
|
||||
|
||||
test('should_map_each_seeded_drama_to_its_own_localized_copy_when_looked_up', () {
|
||||
final signal = _drama(id: 'the-signal-demo');
|
||||
final city = _drama(id: 'city-lights-demo');
|
||||
final vengeance = _drama(id: 'vengeance-demo');
|
||||
test(
|
||||
'should_map_each_seeded_drama_to_its_own_localized_copy_when_looked_up',
|
||||
() {
|
||||
final signal = _drama(id: 'the-signal-demo');
|
||||
final city = _drama(id: 'city-lights-demo');
|
||||
final vengeance = _drama(id: 'vengeance-demo');
|
||||
|
||||
expect(localizedDramaTitle(en, signal), en.dramaSignalTitle);
|
||||
expect(localizedDramaTitle(en, city), en.dramaCityTitle);
|
||||
expect(localizedDramaTitle(en, vengeance), en.dramaVengeanceTitle);
|
||||
expect(localizedDramaTitle(en, signal), en.dramaSignalTitle);
|
||||
expect(localizedDramaTitle(en, city), en.dramaCityTitle);
|
||||
expect(localizedDramaTitle(en, vengeance), en.dramaVengeanceTitle);
|
||||
|
||||
expect(localizedDramaSynopsis(en, signal), en.dramaSignalSynopsis);
|
||||
expect(localizedDramaSynopsis(en, city), en.dramaCitySynopsis);
|
||||
expect(localizedDramaSynopsis(en, vengeance), en.dramaVengeanceSynopsis);
|
||||
});
|
||||
expect(localizedDramaSynopsis(en, signal), en.dramaSignalSynopsis);
|
||||
expect(localizedDramaSynopsis(en, city), en.dramaCitySynopsis);
|
||||
expect(localizedDramaSynopsis(en, vengeance), en.dramaVengeanceSynopsis);
|
||||
},
|
||||
);
|
||||
|
||||
test('should_keep_two_dramas_apart_when_localized_copy_is_mapped', () {
|
||||
final titles = {
|
||||
@@ -70,6 +77,47 @@ void main() {
|
||||
expect(localizedDramaSynopsis(zh, custom), 'Custom synopsis');
|
||||
});
|
||||
|
||||
test('should_not_fall_back_to_chinese_when_indonesian_copy_is_missing', () {
|
||||
const drama = Drama(
|
||||
id: 'missing-id-copy',
|
||||
title: '古城',
|
||||
synopsis: '中文简介',
|
||||
titleLocales: {'zh': '古城'},
|
||||
synopsisLocales: {'zh': '中文简介'},
|
||||
posterUrl: '/files/poster.png',
|
||||
);
|
||||
|
||||
expect(drama.localizedTitle('id'), isEmpty);
|
||||
expect(drama.localizedSynopsis('id'), isEmpty);
|
||||
});
|
||||
|
||||
test('should_filter_incomplete_indonesian_content_from_visible_list', () {
|
||||
const complete = Drama(
|
||||
id: 'complete-id-copy',
|
||||
title: 'Kota Lama',
|
||||
synopsis: 'Kisah dari kota lama.',
|
||||
titleLocales: {'id': 'Kota Lama'},
|
||||
synopsisLocales: {'id': 'Kisah dari kota lama.'},
|
||||
posterUrl: '/files/complete.png',
|
||||
);
|
||||
const incomplete = Drama(
|
||||
id: 'incomplete-id-copy',
|
||||
title: '古城',
|
||||
synopsis: '中文简介',
|
||||
titleLocales: {'zh': '古城'},
|
||||
synopsisLocales: {'zh': '中文简介'},
|
||||
posterUrl: '/files/incomplete.png',
|
||||
);
|
||||
|
||||
expect(isDramaCompleteForLocale(complete, 'id'), isTrue);
|
||||
expect(isDramaCompleteForLocale(incomplete, 'id'), isFalse);
|
||||
expect(visibleDramasForLocale([complete, incomplete], 'id'), [complete]);
|
||||
expect(visibleDramasForLocale([complete, incomplete], 'en'), [
|
||||
complete,
|
||||
incomplete,
|
||||
]);
|
||||
});
|
||||
|
||||
test('should_ignore_raw_catalog_text_when_drama_is_seeded', () {
|
||||
final signal = _drama(
|
||||
id: 'the-signal-demo',
|
||||
@@ -107,7 +155,7 @@ void main() {
|
||||
|
||||
expect(copies, hasLength(3));
|
||||
for (final copy in copies) {
|
||||
expect(copy, contains('FruitShorts'));
|
||||
expect(copy, contains('ymb'));
|
||||
expect(copy.split('\n'), hasLength(3));
|
||||
expect(copy.split('\n').every((line) => line.isNotEmpty), isTrue);
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user