为什么:a) 应用对外名称要统一成 FruitShorts(产品名,nontonki 是原型代号); b) 首发市场是印尼,界面必须有印尼语;c) 归档要求"新增 id-ID 与改名合并生成一次 l10n,别分两次"。 改名: - pubspec name: nontonki → fruitshorts(Dart 包名),description 同步;28 个文件的 package: 导入前缀替换 - Android android:label、iOS CFBundleDisplayName/CFBundleName → FruitShorts - 图标资源 assets/icon/nontonki.png → fruitshorts.png(含 pubspec 两处引用) - README 同步(补印尼语说明,顺带修掉写错的模块名 reelshort-app-api → fruitshorts-app-api) 文案: - 三份 arb 的 appName → FruitShorts、brandMark → FRUITSHORTS、shareFooter → FruitShorts(不留 demo 标记) - 新增 lib/l10n/app_id.arb:174 个值键与 en/zh 完全一致,按印尼语习惯翻译(Coin→Koin、Episode→Episode) - 一次性 flutter gen-l10n 生成 app_localizations_id.dart;id 自动进入 supportedLocales,默认 locale 未改 - 新增 test/config/l10n_id_test.dart:钉住 id 文案、supportedLocales 含 id、品牌文案无 demo 标记、占位符渲染 不动:applicationId / bundle id(lumadrama 遗留,等裁定)、目录名、业务逻辑与页面结构、语言选择页(仍只有 en/zh) 门禁:dart analyze lib test 零告警;flutter test 159 全过(基线 155 + 新增 4);残留扫描 0 命中; 三份 arb 键集一致(174/174/174);真机(iPhone iOS 26.6.1)构建安装启动成功,devicectl 列出显示名 FruitShorts
136 lines
4.1 KiB
Dart
136 lines
4.1 KiB
Dart
import 'dart:convert';
|
|
|
|
import 'package:flutter_test/flutter_test.dart';
|
|
import 'package:fruitshorts/core/data/models/engagement_snapshot.dart';
|
|
import 'package:fruitshorts/core/data/repositories/engagement_repository.dart';
|
|
import 'package:shared_preferences/shared_preferences.dart';
|
|
import 'package:shared_preferences_platform_interface/in_memory_shared_preferences_async.dart';
|
|
import 'package:shared_preferences_platform_interface/shared_preferences_async_platform_interface.dart';
|
|
|
|
/// Mirrors the private key used by [SharedPreferencesEngagementRepository].
|
|
const _key = 'engagement.v1.demo-local-v1';
|
|
|
|
void main() {
|
|
late SharedPreferencesAsync preferences;
|
|
|
|
setUp(() {
|
|
SharedPreferencesAsyncPlatform.instance =
|
|
InMemorySharedPreferencesAsync.empty();
|
|
preferences = SharedPreferencesAsync();
|
|
});
|
|
|
|
SharedPreferencesEngagementRepository repository() =>
|
|
SharedPreferencesEngagementRepository(preferences: preferences);
|
|
|
|
Future<EngagementSnapshot> loadRaw(String raw) async {
|
|
await preferences.setString(_key, raw);
|
|
return repository().load();
|
|
}
|
|
|
|
test('should_read_empty_snapshot_when_first_launch', () async {
|
|
final snapshot = await repository().load();
|
|
|
|
expect(snapshot.savedDramaIds, isEmpty);
|
|
expect(snapshot.likedDramaIds, isEmpty);
|
|
expect(snapshot.commentsByDrama, isEmpty);
|
|
});
|
|
|
|
test('should_survive_save_and_reload_round_trip_when_snapshot_is_stored', () async {
|
|
await repository().save(
|
|
const EngagementSnapshot(
|
|
savedDramaIds: {'signal', 'city'},
|
|
likedDramaIds: {'city'},
|
|
commentsByDrama: {
|
|
'signal': ['first note', 'second note'],
|
|
},
|
|
),
|
|
);
|
|
|
|
final loaded = await repository().load();
|
|
|
|
expect(loaded.savedDramaIds, {'signal', 'city'});
|
|
expect(loaded.likedDramaIds, {'city'});
|
|
expect(loaded.commentsByDrama, {
|
|
'signal': ['first note', 'second note'],
|
|
});
|
|
});
|
|
|
|
test('should_round_trip_as_empty_collections_when_snapshot_is_empty', () async {
|
|
await repository().save(const EngagementSnapshot());
|
|
|
|
final loaded = await repository().load();
|
|
|
|
expect(loaded.savedDramaIds, isEmpty);
|
|
expect(loaded.likedDramaIds, isEmpty);
|
|
expect(loaded.commentsByDrama, isEmpty);
|
|
});
|
|
|
|
test('should_fall_back_to_empty_snapshot_when_payload_is_corrupt_or_not_an_object', () async {
|
|
for (final raw in <String>[
|
|
'',
|
|
'not json at all',
|
|
'[]',
|
|
'"a bare string"',
|
|
'42',
|
|
'null',
|
|
]) {
|
|
final snapshot = await loadRaw(raw);
|
|
|
|
expect(snapshot.savedDramaIds, isEmpty, reason: raw);
|
|
expect(snapshot.likedDramaIds, isEmpty, reason: raw);
|
|
expect(snapshot.commentsByDrama, isEmpty, reason: raw);
|
|
}
|
|
});
|
|
|
|
test('should_drop_mistyped_fields_when_payload_has_wrong_types', () async {
|
|
final snapshot = await loadRaw(
|
|
jsonEncode({
|
|
'saved': 'signal',
|
|
'liked': {'city': true},
|
|
'comments': {
|
|
'signal': 'a plain string',
|
|
'city': ['kept', 7, null, true],
|
|
'town': <Object>[],
|
|
},
|
|
}),
|
|
);
|
|
|
|
expect(snapshot.savedDramaIds, isEmpty);
|
|
expect(snapshot.likedDramaIds, isEmpty);
|
|
expect(snapshot.commentsByDrama, {
|
|
'city': ['kept'],
|
|
'town': <String>[],
|
|
});
|
|
});
|
|
|
|
test('should_fall_back_per_field_when_payload_keys_are_missing', () async {
|
|
final snapshot = await loadRaw(jsonEncode({'saved': ['signal']}));
|
|
|
|
expect(snapshot.savedDramaIds, {'signal'});
|
|
expect(snapshot.likedDramaIds, isEmpty);
|
|
expect(snapshot.commentsByDrama, isEmpty);
|
|
});
|
|
|
|
test('should_write_only_json_primitives_when_saving', () async {
|
|
await repository().save(
|
|
const EngagementSnapshot(
|
|
savedDramaIds: {'signal'},
|
|
likedDramaIds: {'city'},
|
|
commentsByDrama: {
|
|
'signal': ['note'],
|
|
},
|
|
),
|
|
);
|
|
|
|
final raw = await preferences.getString(_key);
|
|
expect(raw, isNotNull);
|
|
|
|
final decoded = jsonDecode(raw!) as Map<String, dynamic>;
|
|
expect(decoded['saved'], ['signal']);
|
|
expect(decoded['liked'], ['city']);
|
|
expect(decoded['comments'], {
|
|
'signal': ['note'],
|
|
});
|
|
});
|
|
}
|