为什么:红线第 8 条门禁立即生效,要求 Flutter 测试命名合规;此前 155 条用例名是英文自然语言 或中文描述,合规数 0/155,属存量欠账,按"先补齐再上新功能"在本批处理。 - 25 个测试文件、155 条用例改名,按「文件 + 旧名」精确定位,每条断言命中恰好 1 次才替换 - 只改名字字面量:改动行 155 删 + 155 增,无一行不含字符串字面量(断言与用例体零改动) - 门禁:dart analyze lib test = No issues found;flutter test = 155 全过
97 lines
3.6 KiB
Dart
97 lines
3.6 KiB
Dart
import 'package:flutter_test/flutter_test.dart';
|
|
import 'package:nontonki/core/data/models/drama.dart';
|
|
import 'package:nontonki/core/formatting/localized_content.dart';
|
|
import 'package:nontonki/l10n/app_localizations_en.dart';
|
|
import 'package:nontonki/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();
|
|
|
|
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));
|
|
});
|
|
}
|