116 lines
4.3 KiB
Dart
116 lines
4.3 KiB
Dart
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/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 [],
|
|
);
|
|
|
|
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');
|
|
|
|
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);
|
|
});
|
|
|
|
test('should_keep_two_dramas_apart_when_localized_copy_is_mapped', () {
|
|
final titles = {
|
|
localizedDramaTitle(en, _drama(id: 'the-signal-demo')),
|
|
localizedDramaTitle(en, _drama(id: 'city-lights-demo')),
|
|
localizedDramaTitle(en, _drama(id: 'vengeance-demo')),
|
|
};
|
|
final synopses = {
|
|
localizedDramaSynopsis(en, _drama(id: 'the-signal-demo')),
|
|
localizedDramaSynopsis(en, _drama(id: 'city-lights-demo')),
|
|
localizedDramaSynopsis(en, _drama(id: 'vengeance-demo')),
|
|
};
|
|
|
|
expect(titles, hasLength(3));
|
|
expect(synopses, hasLength(3));
|
|
});
|
|
|
|
test('should_translate_localized_copy_when_content_is_looked_up', () {
|
|
final signal = _drama(id: 'the-signal-demo');
|
|
|
|
expect(localizedDramaTitle(zh, signal), zh.dramaSignalTitle);
|
|
expect(localizedDramaSynopsis(zh, signal), zh.dramaSignalSynopsis);
|
|
expect(localizedDramaTitle(zh, signal), isNot(en.dramaSignalTitle));
|
|
});
|
|
|
|
test('should_keep_catalog_text_in_every_locale_when_drama_is_unknown', () {
|
|
final custom = _drama(
|
|
id: 'custom-demo',
|
|
title: 'Custom Title',
|
|
synopsis: 'Custom synopsis',
|
|
);
|
|
|
|
expect(localizedDramaTitle(en, custom), 'Custom Title');
|
|
expect(localizedDramaTitle(zh, custom), 'Custom Title');
|
|
expect(localizedDramaSynopsis(en, custom), 'Custom synopsis');
|
|
expect(localizedDramaSynopsis(zh, custom), 'Custom synopsis');
|
|
});
|
|
|
|
test('should_ignore_raw_catalog_text_when_drama_is_seeded', () {
|
|
final signal = _drama(
|
|
id: 'the-signal-demo',
|
|
title: 'stale title',
|
|
synopsis: 'stale synopsis',
|
|
);
|
|
|
|
expect(localizedDramaTitle(en, signal), isNot('stale title'));
|
|
expect(localizedDramaSynopsis(en, signal), isNot('stale synopsis'));
|
|
});
|
|
|
|
test('should_use_named_titles_when_episode_number_is_one_to_four', () {
|
|
expect(localizedEpisodeTitle(en, 1), en.episodeOneTitle);
|
|
expect(localizedEpisodeTitle(en, 2), en.episodeTwoTitle);
|
|
expect(localizedEpisodeTitle(en, 3), en.episodeThreeTitle);
|
|
expect(localizedEpisodeTitle(en, 4), en.episodeFourTitle);
|
|
});
|
|
|
|
test('should_fall_back_to_numbered_label_when_episode_number_is_later', () {
|
|
for (final number in <int>[5, 12, 100]) {
|
|
expect(localizedEpisodeTitle(en, number), en.episodeLabel(number));
|
|
expect(localizedEpisodeTitle(en, number), contains('$number'));
|
|
}
|
|
expect(localizedEpisodeTitle(zh, 12), zh.episodeLabel(12));
|
|
});
|
|
|
|
test('should_build_share_copy_from_localized_title_synopsis_and_footer', () {
|
|
final signal = _drama(id: 'the-signal-demo');
|
|
final copies = {
|
|
for (final l10n in [en, zh, id])
|
|
'${localizedDramaTitle(l10n, signal)}\n'
|
|
'${localizedDramaSynopsis(l10n, signal)}\n'
|
|
'${l10n.shareFooter}',
|
|
};
|
|
|
|
expect(copies, hasLength(3));
|
|
for (final copy in copies) {
|
|
expect(copy, contains('FruitShorts'));
|
|
expect(copy.split('\n'), hasLength(3));
|
|
expect(copy.split('\n').every((line) => line.isNotEmpty), isTrue);
|
|
}
|
|
});
|
|
}
|