为什么: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
257 lines
7.3 KiB
Dart
257 lines
7.3 KiB
Dart
import 'dart:async';
|
|
|
|
import 'package:flutter/material.dart';
|
|
import 'package:flutter_test/flutter_test.dart';
|
|
import 'package:fruitshorts/core/config/locale_controller.dart';
|
|
import 'package:fruitshorts/core/data/models/drama.dart';
|
|
import 'package:fruitshorts/l10n/app_localizations.dart';
|
|
import 'package:fruitshorts/pages/mine/mine_logic.dart';
|
|
import 'package:provider/provider.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';
|
|
|
|
import '../support/fake_watch_history.dart';
|
|
|
|
Drama _drama(String id, {List<int> numbers = const [1, 2, 3]}) => Drama(
|
|
id: id,
|
|
title: id,
|
|
synopsis: 'synopsis',
|
|
posterUrl: '/files/poster.png',
|
|
episodes: [
|
|
for (final number in numbers)
|
|
Episode(
|
|
id: '$id-$number',
|
|
number: number,
|
|
title: 'Episode $number',
|
|
videoUrl: 'https://example.test/clip.mp4',
|
|
isFree: true,
|
|
),
|
|
],
|
|
);
|
|
|
|
void main() {
|
|
TestWidgetsFlutterBinding.ensureInitialized();
|
|
|
|
test('should_keep_requested_section_and_read_episode_one_when_constructed', () async {
|
|
final history = FakeWatchHistory()..saved = const Duration(seconds: 7);
|
|
final logic = MineLogic(
|
|
history: history,
|
|
drama: _drama('signal'),
|
|
initialSection: 1,
|
|
);
|
|
|
|
expect(logic.section, 1);
|
|
expect(logic.filter, 0);
|
|
expect(await logic.position, const Duration(seconds: 7));
|
|
expect(history.reads, ['demo-local-v1|signal|signal-1']);
|
|
logic.dispose();
|
|
});
|
|
|
|
test('should_resume_from_last_watch_when_list_card_has_no_episodes', () async {
|
|
final history = FakeWatchHistory()
|
|
..saved = const Duration(seconds: 7)
|
|
..lastEpisode = 'signal-3';
|
|
final logic = MineLogic(
|
|
history: history,
|
|
drama: _drama('signal', numbers: const []),
|
|
initialSection: 1,
|
|
);
|
|
|
|
expect(await logic.position, const Duration(seconds: 7));
|
|
expect(history.reads, ['demo-local-v1|signal|signal-3']);
|
|
logic.dispose();
|
|
});
|
|
|
|
test('should_notify_when_section_and_filter_are_selected', () {
|
|
final logic = MineLogic(
|
|
history: FakeWatchHistory(),
|
|
drama: _drama('s'),
|
|
initialSection: 0,
|
|
);
|
|
var notifications = 0;
|
|
logic.addListener(() => notifications++);
|
|
|
|
logic.selectSection(1);
|
|
expect(logic.section, 1);
|
|
expect(notifications, 1);
|
|
|
|
logic.selectFilter(2);
|
|
expect(logic.filter, 2);
|
|
expect(notifications, 2);
|
|
logic.dispose();
|
|
});
|
|
|
|
test('should_adopt_drama_only_when_page_is_active', () {
|
|
final history = FakeWatchHistory();
|
|
final logic = MineLogic(
|
|
history: history,
|
|
drama: _drama('signal'),
|
|
initialSection: 0,
|
|
);
|
|
|
|
void sync(
|
|
Drama next, {
|
|
required bool active,
|
|
required bool wasActive,
|
|
required bool dramaChanged,
|
|
int sectionRequest = 0,
|
|
int previousSectionRequest = 0,
|
|
int initialSection = 0,
|
|
}) => logic.syncPage(
|
|
active: active,
|
|
wasActive: wasActive,
|
|
nextDrama: next,
|
|
dramaChanged: dramaChanged,
|
|
sectionRequest: sectionRequest,
|
|
previousSectionRequest: previousSectionRequest,
|
|
initialSection: initialSection,
|
|
);
|
|
|
|
sync(_drama('city'), active: false, wasActive: true, dramaChanged: true);
|
|
expect(logic.drama.id, 'signal');
|
|
|
|
sync(_drama('city'), active: true, wasActive: false, dramaChanged: false);
|
|
expect(logic.drama.id, 'city');
|
|
|
|
history.reads.clear();
|
|
sync(_drama('vengeance'), active: true, wasActive: true, dramaChanged: true);
|
|
expect(logic.drama.id, 'vengeance');
|
|
expect(history.reads, ['demo-local-v1|vengeance|vengeance-1']);
|
|
|
|
history.reads.clear();
|
|
sync(_drama('other'), active: true, wasActive: true, dramaChanged: false);
|
|
expect(logic.drama.id, 'vengeance');
|
|
expect(history.reads, isEmpty);
|
|
logic.dispose();
|
|
});
|
|
|
|
test('should_reset_section_when_section_request_arrives_while_page_is_inactive', () {
|
|
final logic = MineLogic(
|
|
history: FakeWatchHistory(),
|
|
drama: _drama('s'),
|
|
initialSection: 0,
|
|
);
|
|
|
|
logic.syncPage(
|
|
active: false,
|
|
wasActive: false,
|
|
nextDrama: logic.drama,
|
|
dramaChanged: false,
|
|
sectionRequest: 1,
|
|
previousSectionRequest: 0,
|
|
initialSection: 1,
|
|
);
|
|
|
|
expect(logic.section, 1);
|
|
logic.dispose();
|
|
});
|
|
|
|
testWidgets('should_return_choice_and_forward_it_when_act_runs_embedded', (
|
|
tester,
|
|
) async {
|
|
final logic = MineLogic(
|
|
history: FakeWatchHistory(),
|
|
drama: _drama('s'),
|
|
initialSection: 0,
|
|
);
|
|
final forwarded = <MyPageAction>[];
|
|
final popped = Completer<MyPageAction?>();
|
|
late BuildContext pageContext;
|
|
|
|
await tester.pumpWidget(
|
|
MaterialApp(
|
|
home: Builder(
|
|
builder: (context) => TextButton(
|
|
onPressed: () => Navigator.of(context)
|
|
.push<MyPageAction>(
|
|
MaterialPageRoute<MyPageAction>(
|
|
builder: (inner) {
|
|
pageContext = inner;
|
|
return const SizedBox.shrink();
|
|
},
|
|
),
|
|
)
|
|
.then(popped.complete),
|
|
child: const Text('open'),
|
|
),
|
|
),
|
|
),
|
|
);
|
|
|
|
await tester.tap(find.text('open'));
|
|
await tester.pumpAndSettle();
|
|
|
|
logic.act(
|
|
pageContext,
|
|
MyPageAction.discover,
|
|
embedded: true,
|
|
onAction: forwarded.add,
|
|
);
|
|
expect(forwarded, [MyPageAction.discover]);
|
|
expect(Navigator.of(pageContext).canPop(), isTrue);
|
|
|
|
logic.act(pageContext, MyPageAction.resume, embedded: false);
|
|
await tester.pumpAndSettle();
|
|
|
|
await expectLater(popped.future, completion(MyPageAction.resume));
|
|
logic.dispose();
|
|
});
|
|
|
|
testWidgets('should_switch_app_locale_when_language_sheet_is_used', (tester) async {
|
|
SharedPreferencesAsyncPlatform.instance =
|
|
InMemorySharedPreferencesAsync.empty();
|
|
final locale = LocaleController();
|
|
final logic = MineLogic(
|
|
history: FakeWatchHistory(),
|
|
drama: _drama('s'),
|
|
initialSection: 0,
|
|
);
|
|
late BuildContext context;
|
|
|
|
await tester.pumpWidget(
|
|
ChangeNotifierProvider<LocaleController>.value(
|
|
value: locale,
|
|
child: MaterialApp(
|
|
locale: const Locale('en'),
|
|
localizationsDelegates: AppLocalizations.localizationsDelegates,
|
|
supportedLocales: AppLocalizations.supportedLocales,
|
|
home: Builder(
|
|
builder: (inner) {
|
|
context = inner;
|
|
return const Scaffold(body: SizedBox.shrink());
|
|
},
|
|
),
|
|
),
|
|
),
|
|
);
|
|
|
|
unawaited(logic.showLanguage(context));
|
|
await tester.pumpAndSettle();
|
|
|
|
final l10n = AppLocalizations.of(context)!;
|
|
expect(find.text(l10n.english), findsOneWidget);
|
|
expect(find.text(l10n.simplifiedChinese), findsOneWidget);
|
|
|
|
await tester.tap(find.text(l10n.simplifiedChinese));
|
|
await tester.pumpAndSettle();
|
|
|
|
expect(locale.locale, const Locale('zh'));
|
|
logic.dispose();
|
|
});
|
|
|
|
test('should_do_nothing_when_notifying_after_dispose', () {
|
|
final logic = MineLogic(
|
|
history: FakeWatchHistory(),
|
|
drama: _drama('s'),
|
|
initialSection: 0,
|
|
);
|
|
var notifications = 0;
|
|
logic.addListener(() => notifications++);
|
|
|
|
logic.dispose();
|
|
logic.notify();
|
|
|
|
expect(notifications, 0);
|
|
});
|
|
}
|