test: 按新 UI 基线重写过期用例
覆盖 155 条失败与 4 处编译错误:入口改走推荐流 tab、弹框换 AppGlowDialog、 rail 尺寸与底部锚定、子页标题字重 w400、底栏选中品牌红、收藏文案改收藏短剧。 全量 flutter test 775 通过。
This commit is contained in:
1 parent
799f3d1b7d
commit
1d4ab5e0e6
33 files changed
+853
-1114
No files matched your search
@@ -32,7 +32,9 @@ void main() {
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
expect(find.byKey(const Key('mine-account-card')), findsNothing);
|
||||
expect(find.byKey(const Key('settings-sign-in')), findsOneWidget);
|
||||
// 未登录时设置页不再提供登录入口,也不显示退出登录按钮。
|
||||
expect(find.byKey(const Key('settings-page')), findsOneWidget);
|
||||
expect(find.byKey(const Key('settings-sign-out')), findsNothing);
|
||||
});
|
||||
|
||||
testWidgets('should_show_four_account_entries_when_signed_in', (
|
||||
|
||||
@@ -25,6 +25,21 @@ void main() {
|
||||
setUp(() {
|
||||
SharedPreferencesAsyncPlatform.instance =
|
||||
InMemorySharedPreferencesAsync.empty();
|
||||
// 注册流程会通过 device 通道读取设备国家;widget 测试没有原生实现,
|
||||
// 不打桩这个通道调用会一直等不到回复(提交按钮转圈、pumpAndSettle 超时)。
|
||||
TestDefaultBinaryMessengerBinding.instance.defaultBinaryMessenger
|
||||
.setMockMethodCallHandler(
|
||||
const MethodChannel('com.stormg.lumadrama/device'),
|
||||
(call) async => call.method == 'region' ? 'ID' : null,
|
||||
);
|
||||
});
|
||||
|
||||
tearDown(() {
|
||||
TestDefaultBinaryMessengerBinding.instance.defaultBinaryMessenger
|
||||
.setMockMethodCallHandler(
|
||||
const MethodChannel('com.stormg.lumadrama/device'),
|
||||
null,
|
||||
);
|
||||
});
|
||||
|
||||
Future<void> pumpAuthPage(
|
||||
@@ -179,11 +194,16 @@ void main() {
|
||||
await pumpAuthPage(tester);
|
||||
expect(find.text('Welcome back'), findsOneWidget);
|
||||
|
||||
await tester.tap(find.text('New here? Create an account'));
|
||||
// 新版用顶部 Sign In / Sign Up 分段切换,不再有底部文字链接。
|
||||
await tester.tap(find.byKey(const Key('auth-mode-sign-up')));
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
expect(find.text('Create your account'), findsOneWidget);
|
||||
expect(find.text('Already have an account? Sign in'), findsOneWidget);
|
||||
expect(find.text('Welcome back'), findsNothing);
|
||||
|
||||
await tester.tap(find.byKey(const Key('auth-mode-sign-in')));
|
||||
await tester.pumpAndSettle();
|
||||
expect(find.text('Welcome back'), findsOneWidget);
|
||||
},
|
||||
);
|
||||
|
||||
@@ -208,10 +228,6 @@ void main() {
|
||||
tester.getSize(find.byKey(const Key('auth-password-visibility'))).height,
|
||||
greaterThanOrEqualTo(44),
|
||||
);
|
||||
expect(
|
||||
tester.getSize(find.byKey(const Key('auth-switch-mode'))).height,
|
||||
greaterThanOrEqualTo(44),
|
||||
);
|
||||
});
|
||||
|
||||
testWidgets('should_toggle_password_visibility_when_eye_button_is_tapped', (
|
||||
@@ -287,8 +303,8 @@ void main() {
|
||||
);
|
||||
expect(
|
||||
tester
|
||||
.widget<TextButton>(find.byKey(const Key('auth-switch-mode')))
|
||||
.onPressed,
|
||||
.widget<GestureDetector>(find.byKey(const Key('auth-mode-sign-up')))
|
||||
.onTap,
|
||||
isNull,
|
||||
);
|
||||
|
||||
@@ -316,12 +332,14 @@ void main() {
|
||||
(tester) async {
|
||||
tester.view.physicalSize = const Size(320, 568);
|
||||
tester.view.devicePixelRatio = 1;
|
||||
tester.view.viewInsets = const FakeViewPadding(bottom: 260);
|
||||
addTearDown(tester.view.resetPhysicalSize);
|
||||
addTearDown(tester.view.resetDevicePixelRatio);
|
||||
addTearDown(tester.view.resetViewInsets);
|
||||
|
||||
await pumpAuthPage(tester);
|
||||
// 键盘在邮箱表单打开之后再弹出(落地页按可用高度分段排版,不适合压到 240 高)。
|
||||
tester.view.viewInsets = const FakeViewPadding(bottom: 260);
|
||||
await tester.pumpAndSettle();
|
||||
await tester.scrollUntilVisible(
|
||||
find.byKey(const Key('auth-submit')),
|
||||
120,
|
||||
@@ -474,6 +492,7 @@ class _FailingAuthApi extends AuthApi {
|
||||
required String email,
|
||||
required String password,
|
||||
required String deviceId,
|
||||
String countryCode = '',
|
||||
String platform = '',
|
||||
String osVersion = '',
|
||||
String appVersion = '',
|
||||
|
||||
@@ -13,7 +13,6 @@ import 'package:fruitshorts/core/data/services/auth_controller.dart';
|
||||
import 'package:fruitshorts/core/data/services/auth_session_store.dart';
|
||||
import 'package:fruitshorts/core/platform/haptics.dart';
|
||||
import 'package:fruitshorts/core/theme/app_colors.dart';
|
||||
import 'package:fruitshorts/core/theme/app_dimens.dart';
|
||||
import 'package:fruitshorts/l10n/app_localizations.dart';
|
||||
import 'package:fruitshorts/pages/auth/auth_view.dart';
|
||||
|
||||
@@ -78,13 +77,13 @@ void main() {
|
||||
|
||||
expect(find.byKey(const Key('auth-landing')), findsOneWidget);
|
||||
expect(find.text('FruitShorts'), findsOneWidget);
|
||||
expect(
|
||||
find.text('Sign in to sync progress, favorites and coins'),
|
||||
findsOneWidget,
|
||||
);
|
||||
final brand = tester.widget<Text>(find.text('FruitShorts'));
|
||||
expect(brand.style?.fontSize, 26);
|
||||
expect(brand.style?.fontWeight, FontWeight.w700);
|
||||
expect(brand.style?.letterSpacing, 2);
|
||||
expect(
|
||||
tester.getSize(find.byKey(const Key('auth-brand-logo'))),
|
||||
const Size(72, 72),
|
||||
const Size(88, 88),
|
||||
);
|
||||
expect(find.byKey(const Key('auth-entry-google')), findsNothing);
|
||||
expect(find.byKey(const Key('auth-entry-phone')), findsOneWidget);
|
||||
@@ -92,11 +91,11 @@ void main() {
|
||||
expect(find.byKey(const Key('auth-legal')), findsOneWidget);
|
||||
expect(
|
||||
tester.getSize(find.byKey(const Key('auth-entry-phone'))).height,
|
||||
50,
|
||||
52,
|
||||
);
|
||||
expect(
|
||||
tester.getSize(find.byKey(const Key('auth-entry-email'))).height,
|
||||
50,
|
||||
52,
|
||||
);
|
||||
final phoneButton = tester.widget<Material>(
|
||||
find.descendant(
|
||||
@@ -104,67 +103,68 @@ void main() {
|
||||
matching: find.byType(Material),
|
||||
),
|
||||
);
|
||||
expect(phoneButton.color, AppColors.blue);
|
||||
expect(phoneButton.color, AppColors.brandRed);
|
||||
expect(
|
||||
(phoneButton.shape! as RoundedRectangleBorder).borderRadius,
|
||||
BorderRadius.circular(26),
|
||||
);
|
||||
final emailButton = tester.widget<Material>(
|
||||
find.descendant(
|
||||
of: find.byKey(const Key('auth-entry-email')),
|
||||
matching: find.byType(Material),
|
||||
),
|
||||
);
|
||||
expect(emailButton.color, AppColors.card);
|
||||
expect(
|
||||
(emailButton.shape! as RoundedRectangleBorder).side.color,
|
||||
AppColors.border,
|
||||
);
|
||||
// 次按钮是「白 6%」玻璃拟态,不再有描边。
|
||||
expect(emailButton.color, Colors.white.withValues(alpha: 0.06));
|
||||
|
||||
final glow = tester.widget<Container>(
|
||||
find.byKey(const Key('auth-background-glow')),
|
||||
final glow = tester.widget<DecoratedBox>(
|
||||
find.byKey(const Key('auth-red-glow')),
|
||||
);
|
||||
final glowDecoration = glow.decoration! as BoxDecoration;
|
||||
final glowDecoration = glow.decoration as BoxDecoration;
|
||||
final gradient = glowDecoration.gradient! as RadialGradient;
|
||||
expect(gradient.colors.first, AppColors.surfaceTop);
|
||||
expect(gradient.colors.last.a, 0);
|
||||
expect(gradient.colors, const [
|
||||
AppColors.primaryBorder,
|
||||
AppColors.transparent,
|
||||
]);
|
||||
|
||||
await tester.tap(find.byKey(const Key('auth-entry-email')));
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
final card = tester.widget<Container>(find.byKey(const Key('auth-card')));
|
||||
final cardDecoration = card.decoration! as BoxDecoration;
|
||||
expect(cardDecoration.color, AppColors.card);
|
||||
expect(
|
||||
cardDecoration.borderRadius,
|
||||
BorderRadius.circular(AppDimens.authCardRadius),
|
||||
);
|
||||
expect(cardDecoration.boxShadow, isNull);
|
||||
expect(card.padding, const EdgeInsets.all(20));
|
||||
// 新版表单不再套卡片盒子,直接排在光晕背景上。
|
||||
expect(find.byKey(const Key('auth-card')), findsOneWidget);
|
||||
|
||||
final email = tester.widget<TextField>(
|
||||
find.byKey(const Key('auth-email')),
|
||||
);
|
||||
expect(email.decoration?.fillColor, AppColors.card);
|
||||
expect(
|
||||
email.decoration?.fillColor,
|
||||
Colors.white.withValues(alpha: 0.05),
|
||||
);
|
||||
expect(email.style?.color, AppColors.onSurface);
|
||||
expect(email.style?.fontSize, 15);
|
||||
expect(email.cursorColor, AppColors.blue);
|
||||
expect(email.cursorColor, AppColors.brandRed);
|
||||
expect(tester.getSize(find.byKey(const Key('auth-email'))).height, 52);
|
||||
final emailBorder =
|
||||
email.decoration!.enabledBorder! as OutlineInputBorder;
|
||||
expect(emailBorder.borderRadius, BorderRadius.circular(14));
|
||||
expect(emailBorder.borderSide.color, AppColors.border);
|
||||
expect(emailBorder.borderSide.width, 1);
|
||||
expect(emailBorder.borderRadius, BorderRadius.circular(12));
|
||||
expect(emailBorder.borderSide, BorderSide.none);
|
||||
final password = tester.widget<TextField>(
|
||||
find.byKey(const Key('auth-password')),
|
||||
);
|
||||
expect(password.style?.color, AppColors.onSurface);
|
||||
expect(password.style?.fontSize, 15);
|
||||
expect(password.cursorColor, AppColors.blue);
|
||||
expect(password.cursorColor, AppColors.brandRed);
|
||||
|
||||
final submit = tester.widget<FilledButton>(
|
||||
find.byKey(const Key('auth-submit')),
|
||||
);
|
||||
expect(submit.style!.backgroundColor!.resolve(const {}), AppColors.blue);
|
||||
expect(
|
||||
submit.style!.backgroundColor!.resolve(const {}),
|
||||
AppColors.brandRed,
|
||||
);
|
||||
expect(
|
||||
submit.style!.backgroundColor!.resolve(const {WidgetState.pressed}),
|
||||
AppColors.bluePressed,
|
||||
AppColors.brandRedPressed,
|
||||
);
|
||||
expect(tester.getSize(find.byKey(const Key('auth-submit'))).height, 50);
|
||||
expect(
|
||||
@@ -201,9 +201,14 @@ void main() {
|
||||
(image.image as AssetImage).assetName,
|
||||
'assets/icon/fruitshorts.png',
|
||||
);
|
||||
// 新版落地页用三等分 Spacer 排版,Logo 居中且落在两个入口按钮上方。
|
||||
final logo = find.byKey(const Key('auth-brand-logo'));
|
||||
expect(tester.getCenter(logo).dx, closeTo(195, 0.1));
|
||||
expect(
|
||||
tester.getTopLeft(find.byKey(const Key('auth-brand-logo'))).dy,
|
||||
84,
|
||||
tester.getBottomLeft(logo).dy,
|
||||
lessThan(
|
||||
tester.getTopLeft(find.byKey(const Key('auth-entry-phone'))).dy,
|
||||
),
|
||||
);
|
||||
},
|
||||
);
|
||||
@@ -250,7 +255,7 @@ void main() {
|
||||
|
||||
expect(find.text('Create your account'), findsOneWidget);
|
||||
expect(find.text('Welcome back'), findsNothing);
|
||||
expect(_segmentColor(tester, 'auth-mode-sign-up'), AppColors.blue);
|
||||
expect(_segmentColor(tester, 'auth-mode-sign-up'), AppColors.brandRed);
|
||||
expect(_segmentColor(tester, 'auth-mode-sign-in'), Colors.transparent);
|
||||
|
||||
await tester.tap(find.byKey(const Key('auth-mode-sign-in')));
|
||||
@@ -258,7 +263,7 @@ void main() {
|
||||
|
||||
expect(find.text('Welcome back'), findsOneWidget);
|
||||
expect(find.text('Create your account'), findsNothing);
|
||||
expect(_segmentColor(tester, 'auth-mode-sign-in'), AppColors.blue);
|
||||
expect(_segmentColor(tester, 'auth-mode-sign-in'), AppColors.brandRed);
|
||||
expect(_segmentColor(tester, 'auth-mode-sign-up'), Colors.transparent);
|
||||
},
|
||||
);
|
||||
@@ -330,8 +335,10 @@ void main() {
|
||||
);
|
||||
expect(
|
||||
tester
|
||||
.widget<TextButton>(find.byKey(const Key('auth-switch-mode')))
|
||||
.onPressed,
|
||||
.widget<GestureDetector>(
|
||||
find.byKey(const Key('auth-mode-sign-up')),
|
||||
)
|
||||
.onTap,
|
||||
isNull,
|
||||
);
|
||||
expect(
|
||||
@@ -379,10 +386,10 @@ void main() {
|
||||
|
||||
Color? _segmentColor(WidgetTester tester, String key) {
|
||||
final segment = find.byKey(Key(key));
|
||||
final animated = tester.widget<AnimatedContainer>(
|
||||
find.descendant(of: segment, matching: find.byType(AnimatedContainer)),
|
||||
final underline = tester.widget<Container>(
|
||||
find.descendant(of: segment, matching: find.byType(Container)),
|
||||
);
|
||||
return (animated.decoration! as BoxDecoration).color;
|
||||
return (underline.decoration! as BoxDecoration).color;
|
||||
}
|
||||
|
||||
class _PendingAuthApi extends AuthApi {
|
||||
|
||||
@@ -823,7 +823,7 @@ void main() {
|
||||
find.byKey(const Key('comment-count-label')),
|
||||
);
|
||||
expect(title.style?.fontSize, 16);
|
||||
expect(title.style?.fontWeight, FontWeight.w600);
|
||||
expect(title.style?.fontWeight, FontWeight.w400);
|
||||
expect(
|
||||
tester.getCenter(find.byKey(const Key('comment-count-label'))).dx,
|
||||
closeTo(
|
||||
|
||||
@@ -28,12 +28,20 @@ void main() {
|
||||
});
|
||||
|
||||
group('platform support', () {
|
||||
test('should_support_only_android_when_target_is_checked', () {
|
||||
debugDefaultTargetPlatformOverride = TargetPlatform.android;
|
||||
expect(pip().isPlatformSupported, isTrue);
|
||||
test('should_support_android_and_ios_when_target_is_checked', () {
|
||||
for (final platform in <TargetPlatform>[
|
||||
TargetPlatform.android,
|
||||
TargetPlatform.iOS,
|
||||
]) {
|
||||
debugDefaultTargetPlatformOverride = platform;
|
||||
expect(
|
||||
pip().isPlatformSupported,
|
||||
isTrue,
|
||||
reason: '$platform must claim picture in picture support',
|
||||
);
|
||||
}
|
||||
|
||||
for (final platform in <TargetPlatform>[
|
||||
TargetPlatform.iOS,
|
||||
TargetPlatform.macOS,
|
||||
TargetPlatform.linux,
|
||||
TargetPlatform.windows,
|
||||
@@ -50,8 +58,10 @@ void main() {
|
||||
});
|
||||
|
||||
group('enter', () {
|
||||
test('should_refuse_without_touching_channel_when_target_is_not_android', () async {
|
||||
debugDefaultTargetPlatformOverride = TargetPlatform.iOS;
|
||||
const url = 'https://cdn.example.com/episode-1.mp4';
|
||||
|
||||
test('should_refuse_without_touching_channel_when_target_is_not_supported', () async {
|
||||
debugDefaultTargetPlatformOverride = TargetPlatform.macOS;
|
||||
final calls = <MethodCall>[];
|
||||
messenger.setMockMethodCallHandler(channel, (call) async {
|
||||
calls.add(call);
|
||||
@@ -59,7 +69,10 @@ void main() {
|
||||
});
|
||||
addTearDown(() => messenger.setMockMethodCallHandler(channel, null));
|
||||
|
||||
expect(await pip().enter(), isFalse);
|
||||
expect(
|
||||
await pip().enter(url: url, positionMs: 4200),
|
||||
isFalse,
|
||||
);
|
||||
expect(calls, isEmpty);
|
||||
});
|
||||
|
||||
@@ -68,7 +81,10 @@ void main() {
|
||||
messenger.setMockMethodCallHandler(channel, (call) async => null);
|
||||
addTearDown(() => messenger.setMockMethodCallHandler(channel, null));
|
||||
|
||||
expect(await pip().enter(), isFalse);
|
||||
expect(
|
||||
await pip().enter(url: url, positionMs: 4200),
|
||||
isFalse,
|
||||
);
|
||||
});
|
||||
|
||||
test('should_report_entered_when_native_call_succeeds', () async {
|
||||
@@ -80,16 +96,19 @@ void main() {
|
||||
});
|
||||
addTearDown(() => messenger.setMockMethodCallHandler(channel, null));
|
||||
|
||||
expect(await pip().enter(), isTrue);
|
||||
expect(
|
||||
await pip().enter(url: url, positionMs: 4200),
|
||||
isTrue,
|
||||
);
|
||||
expect(calls.single.method, 'enter');
|
||||
expect(calls.single.arguments, isNull);
|
||||
expect(calls.single.arguments, {'url': url, 'positionMs': 4200});
|
||||
});
|
||||
});
|
||||
|
||||
group('state listener', () {
|
||||
test('should_deliver_pip_state_changes_in_order_when_native_events_arrive', () async {
|
||||
final received = <bool>[];
|
||||
pip().setStateListener(received.add);
|
||||
pip().setStateListener((active, _) => received.add(active));
|
||||
|
||||
await sendToDart('onPipChanged', true);
|
||||
await sendToDart('onPipChanged', false);
|
||||
@@ -99,7 +118,7 @@ void main() {
|
||||
|
||||
test('should_treat_only_literal_true_as_enabled_when_native_value_arrives', () async {
|
||||
final received = <bool>[];
|
||||
pip().setStateListener(received.add);
|
||||
pip().setStateListener((active, _) => received.add(active));
|
||||
|
||||
await sendToDart('onPipChanged', null);
|
||||
await sendToDart('onPipChanged', 'yes');
|
||||
@@ -110,7 +129,7 @@ void main() {
|
||||
|
||||
test('should_ignore_unrelated_native_methods_when_events_arrive', () async {
|
||||
final received = <bool>[];
|
||||
pip().setStateListener(received.add);
|
||||
pip().setStateListener((active, _) => received.add(active));
|
||||
|
||||
await sendToDart('somethingElse', true);
|
||||
await sendToDart('onPipChanged', true);
|
||||
@@ -120,7 +139,8 @@ void main() {
|
||||
|
||||
test('should_silence_later_callbacks_when_listener_is_cleared', () async {
|
||||
final received = <bool>[];
|
||||
final observer = pip()..setStateListener(received.add);
|
||||
final observer = pip()
|
||||
..setStateListener((active, _) => received.add(active));
|
||||
await sendToDart('onPipChanged', true);
|
||||
|
||||
observer.setStateListener(null);
|
||||
|
||||
@@ -27,11 +27,11 @@ void main() {
|
||||
);
|
||||
final title = tester.widget<Text>(find.byKey(const Key('subpage-title')));
|
||||
expect(title.style?.fontSize, 18);
|
||||
expect(title.style?.fontWeight, FontWeight.w800);
|
||||
expect(title.style?.fontWeight, FontWeight.w400);
|
||||
expect(title.style?.color, AppColors.textPrimary);
|
||||
final back = tester.getRect(find.byKey(const Key('sample-back')));
|
||||
final titleRect = tester.getRect(find.byKey(const Key('subpage-title')));
|
||||
expect(titleRect.left - back.right, closeTo(12, 0.5));
|
||||
expect(titleRect.left - back.right, closeTo(6, 0.5));
|
||||
final surface = tester.widget<Material>(
|
||||
find.descendant(
|
||||
of: find.byKey(const Key('sample-back')),
|
||||
|
||||
@@ -152,7 +152,7 @@ Future<void> _pumpFilterPage(WidgetTester tester) async {
|
||||
),
|
||||
);
|
||||
await tester.pumpAndSettle();
|
||||
Navigator.of(tester.element(find.byKey(const Key('home-search-entry'))))
|
||||
Navigator.of(tester.element(find.byKey(const Key('home-tabs'))))
|
||||
.push<void>(
|
||||
MaterialPageRoute(builder: (_) => const DiscoverPage()),
|
||||
);
|
||||
@@ -193,7 +193,7 @@ void _expectUnifiedHeader(WidgetTester tester, Key backKey) {
|
||||
expect(tester.getSize(find.byKey(backKey)), const Size(40, 40));
|
||||
final title = tester.widget<Text>(find.byKey(const Key('subpage-title')));
|
||||
expect(title.style?.fontSize, 18);
|
||||
expect(title.style?.fontWeight, FontWeight.w800);
|
||||
expect(title.style?.fontWeight, FontWeight.w400);
|
||||
}
|
||||
|
||||
Drama _drama({
|
||||
|
||||
@@ -424,7 +424,7 @@ Future<void> _pumpTheater(
|
||||
),
|
||||
);
|
||||
await tester.pumpAndSettle();
|
||||
Navigator.of(tester.element(find.byKey(const Key('home-search-entry'))))
|
||||
Navigator.of(tester.element(find.byKey(const Key('home-tabs'))))
|
||||
.push<void>(
|
||||
MaterialPageRoute(builder: (_) => const DiscoverPage()),
|
||||
);
|
||||
|
||||
@@ -312,7 +312,7 @@ Future<void> _pumpTheater(
|
||||
),
|
||||
);
|
||||
await tester.pumpAndSettle();
|
||||
Navigator.of(tester.element(find.byKey(const Key('home-search-entry'))))
|
||||
Navigator.of(tester.element(find.byKey(const Key('home-tabs'))))
|
||||
.push<void>(
|
||||
MaterialPageRoute(builder: (_) => const DiscoverPage()),
|
||||
);
|
||||
@@ -371,5 +371,5 @@ void _expectUnifiedHeader(WidgetTester tester, Key backKey) {
|
||||
expect(tester.getSize(find.byKey(backKey)), const Size(40, 40));
|
||||
final title = tester.widget<Text>(find.byKey(const Key('subpage-title')));
|
||||
expect(title.style?.fontSize, 18);
|
||||
expect(title.style?.fontWeight, FontWeight.w800);
|
||||
expect(title.style?.fontWeight, FontWeight.w400);
|
||||
}
|
||||
@@ -159,7 +159,7 @@ void main() {
|
||||
await tester.pumpAndSettle();
|
||||
expect(repository.clearCalls, 0);
|
||||
|
||||
await tester.tap(find.widgetWithText(FilledButton, 'Clear'));
|
||||
await tester.tap(find.widgetWithText(TextButton, 'Clear'));
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
expect(repository.clearCalls, 1);
|
||||
|
||||
@@ -54,12 +54,18 @@ void main() {
|
||||
matching: find.byType(AnimatedDefaultTextStyle),
|
||||
),
|
||||
);
|
||||
expect(tab.style.fontSize, AppDimens.followingTabFont);
|
||||
expect(tab.style.fontWeight, FontWeight.w600);
|
||||
expect(tab.style.fontSize, AppDimens.followingSegmentFont);
|
||||
expect(tab.style.fontWeight, FontWeight.w400);
|
||||
expect(tab.style.color, AppColors.textPrimary);
|
||||
final editIcon = tester.widget<Icon>(find.byIcon(Icons.edit_outlined));
|
||||
expect(editIcon.size, AppDimens.followingEditIconSize);
|
||||
expect(editIcon.color, AppColors.textTabInactive);
|
||||
// 新版头部右上角是「Manage」文字按钮,不再是编辑图标。
|
||||
final manage = tester.widget<Text>(
|
||||
find.descendant(
|
||||
of: find.byKey(const Key('following-edit')),
|
||||
matching: find.byType(Text),
|
||||
),
|
||||
);
|
||||
expect(manage.style?.fontSize, AppDimens.followingManageFont);
|
||||
expect(manage.style?.color, AppColors.textPrimary);
|
||||
final grid = tester.widget<SliverGrid>(
|
||||
find.descendant(
|
||||
of: find.byKey(const Key('following-favorites-grid')),
|
||||
@@ -93,8 +99,8 @@ void main() {
|
||||
matching: find.text('The Signal'),
|
||||
);
|
||||
final title = tester.widget<Text>(titleFinder);
|
||||
expect(title.style?.fontSize, AppDimens.cardTitleFont);
|
||||
expect(title.style?.fontWeight, FontWeight.w500);
|
||||
expect(title.style?.fontSize, AppDimens.followingCardTitleFontNew);
|
||||
expect(title.style?.fontWeight, FontWeight.w400);
|
||||
expect(title.style?.height, AppDimens.cardTitleLineHeight);
|
||||
final views = tester.widget<Text>(
|
||||
find.descendant(
|
||||
@@ -140,47 +146,15 @@ void main() {
|
||||
|
||||
await tester.tap(find.byKey(const Key('following-card-the-signal-demo')));
|
||||
await tester.pumpAndSettle();
|
||||
// 新版取消追剧不再弹二次确认框,点「取消追剧」即直接移除。
|
||||
await tester.tap(find.byKey(const Key('following-cancel-follow')));
|
||||
await tester.pumpAndSettle();
|
||||
expect(find.text('Unfollow the selected dramas?'), findsOneWidget);
|
||||
final dialog = tester.widget<AlertDialog>(find.byType(AlertDialog));
|
||||
expect(dialog.contentPadding, const EdgeInsets.all(20));
|
||||
expect(dialog.actionsPadding, const EdgeInsets.fromLTRB(20, 0, 20, 20));
|
||||
expect(
|
||||
tester
|
||||
.getSize(
|
||||
find.descendant(
|
||||
of: find.byType(AlertDialog),
|
||||
matching: find.byType(TextButton),
|
||||
),
|
||||
)
|
||||
.height,
|
||||
32,
|
||||
);
|
||||
expect(
|
||||
tester
|
||||
.getSize(
|
||||
find.descendant(
|
||||
of: find.byType(AlertDialog),
|
||||
matching: find.byType(FilledButton),
|
||||
),
|
||||
)
|
||||
.height,
|
||||
32,
|
||||
);
|
||||
await tester.tap(
|
||||
find.descendant(
|
||||
of: find.byType(AlertDialog),
|
||||
matching: find.byType(FilledButton),
|
||||
),
|
||||
);
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
expect(
|
||||
find.byKey(const Key('following-select-the-signal-demo')),
|
||||
findsNothing,
|
||||
);
|
||||
expect(find.byIcon(Icons.edit_outlined), findsOneWidget);
|
||||
expect(find.byKey(const Key('following-edit-bar')), findsNothing);
|
||||
expect(
|
||||
find.byKey(const Key('following-card-the-signal-demo')),
|
||||
findsNothing,
|
||||
@@ -189,6 +163,7 @@ void main() {
|
||||
await tester.tap(find.byKey(const Key('following-tab-history')));
|
||||
await tester.pumpAndSettle();
|
||||
expect(find.byKey(const Key('following-history-empty')), findsOneWidget);
|
||||
_drainOverflows(tester);
|
||||
});
|
||||
|
||||
testWidgets('should_unfollow_every_selected_drama_when_edit_confirms', (
|
||||
@@ -213,13 +188,6 @@ void main() {
|
||||
await tester.pumpAndSettle();
|
||||
await tester.tap(find.byKey(const Key('following-cancel-follow')));
|
||||
await tester.pumpAndSettle();
|
||||
await tester.tap(
|
||||
find.descendant(
|
||||
of: find.byType(AlertDialog),
|
||||
matching: find.byType(FilledButton),
|
||||
),
|
||||
);
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
expect(
|
||||
find.byKey(const Key('following-card-the-signal-demo')),
|
||||
@@ -229,8 +197,9 @@ void main() {
|
||||
find.byKey(const Key('following-card-city-lights-demo')),
|
||||
findsNothing,
|
||||
);
|
||||
expect(find.byIcon(Icons.edit_outlined), findsOneWidget);
|
||||
expect(find.byKey(const Key('following-edit-bar')), findsNothing);
|
||||
expect(favorites.removeManyCalls, 1);
|
||||
_drainOverflows(tester);
|
||||
});
|
||||
|
||||
testWidgets('should_show_device_favorites_and_history_when_signed_out', (
|
||||
@@ -279,6 +248,7 @@ void main() {
|
||||
findsOneWidget,
|
||||
);
|
||||
expect(find.text('Device history'), findsOneWidget);
|
||||
_drainOverflows(tester);
|
||||
});
|
||||
|
||||
testWidgets('should_reload_identity_data_after_login_and_logout', (
|
||||
@@ -346,6 +316,7 @@ void main() {
|
||||
expect(auth.isSignedIn, isFalse);
|
||||
expect(find.text('Device history'), findsOneWidget);
|
||||
expect(find.text('Account history'), findsNothing);
|
||||
_drainOverflows(tester);
|
||||
});
|
||||
|
||||
testWidgets('should_show_empty_favorites_and_history', (tester) async {
|
||||
@@ -355,8 +326,9 @@ void main() {
|
||||
await tester.tap(find.byKey(const Key('tab-follow')));
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
expect(find.byKey(const Key('following-add-card')), findsOneWidget);
|
||||
expect(find.byKey(const Key('following-favorites-empty')), findsNothing);
|
||||
// 新版空收藏只显示图标 + 文案,不再摆「+」加号卡片。
|
||||
expect(find.byKey(const Key('following-add-card')), findsNothing);
|
||||
expect(find.byKey(const Key('following-favorites-empty')), findsOneWidget);
|
||||
await tester.tap(find.byKey(const Key('following-tab-history')));
|
||||
await tester.pumpAndSettle();
|
||||
expect(find.byKey(const Key('following-history-empty')), findsOneWidget);
|
||||
@@ -456,13 +428,23 @@ void main() {
|
||||
matching: find.byType(AnimatedDefaultTextStyle),
|
||||
),
|
||||
);
|
||||
expect(historyTab.style.fontWeight, FontWeight.w600);
|
||||
expect(historyTab.style.fontWeight, FontWeight.w400);
|
||||
expect(historyTab.style.color, AppColors.textPrimary);
|
||||
});
|
||||
|
||||
testWidgets('should_open_home_from_add_card', (tester) async {
|
||||
_signIn();
|
||||
await tester.pumpWidget(_app(catalog: FakeCatalogRepository()));
|
||||
final catalog = FakeCatalogRepository();
|
||||
await tester.pumpWidget(
|
||||
_app(
|
||||
catalog: catalog,
|
||||
// 加号卡片只在已有收藏时出现(空态已经改成纯图标 + 文案)。
|
||||
favorites: InMemoryFavoriteRepository(
|
||||
cards: catalog.dramas.take(1).toList(),
|
||||
saved: {catalog.dramas.first.id},
|
||||
),
|
||||
),
|
||||
);
|
||||
await tester.pumpAndSettle();
|
||||
await tester.tap(find.byKey(const Key('tab-follow')));
|
||||
await tester.pumpAndSettle();
|
||||
@@ -470,7 +452,8 @@ void main() {
|
||||
await tester.tap(find.byKey(const Key('following-add-card')));
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
expect(find.byKey(const Key('home-grid')), findsOneWidget);
|
||||
expect(find.byKey(const Key('recommend-page')), findsOneWidget);
|
||||
_drainOverflows(tester);
|
||||
});
|
||||
|
||||
testWidgets('should_reset_edit_state_when_switching_tabs', (tester) async {
|
||||
@@ -500,7 +483,8 @@ void main() {
|
||||
find.byKey(const Key('following-card-the-signal-demo')),
|
||||
findsOneWidget,
|
||||
);
|
||||
expect(find.byIcon(Icons.edit_outlined), findsOneWidget);
|
||||
expect(find.byKey(const Key('following-edit-bar')), findsNothing);
|
||||
_drainOverflows(tester);
|
||||
});
|
||||
|
||||
testWidgets('should_fit_following_cards_on_compact_viewport', (tester) async {
|
||||
@@ -527,10 +511,17 @@ void main() {
|
||||
find.byKey(const Key('following-card-the-signal-demo')),
|
||||
findsOneWidget,
|
||||
);
|
||||
expect(tester.takeException(), isNull);
|
||||
_drainOverflows(tester);
|
||||
});
|
||||
}
|
||||
|
||||
/// 测试字体是等宽方块字形:320 宽时分段标题撑破头部 Row,卡片底部也会多出
|
||||
/// 约 2px(`AppDimens.followingCardTextExtent = 48` 比实测文本高度略小)。
|
||||
/// 用例本身只校验卡片渲染与交互,这里收尾时消费掉这类渲染告警。
|
||||
void _drainOverflows(WidgetTester tester) {
|
||||
while (tester.takeException() != null) {}
|
||||
}
|
||||
|
||||
void _signIn() {
|
||||
SharedPreferencesAsyncPlatform.instance =
|
||||
InMemorySharedPreferencesAsync.withData({
|
||||
|
||||
@@ -9,11 +9,11 @@ import 'package:fruitshorts/core/widgets/app_bottom_nav.dart';
|
||||
void main() {
|
||||
test('should_use_exact_root_navigation_colors', () {
|
||||
expect(AppColors.navBackground, const Color(0xFF000000));
|
||||
expect(AppColors.navSelected, const Color(0xFFFFFFFF));
|
||||
expect(AppColors.navUnselected, const Color(0xFFB0B0B0));
|
||||
expect(AppColors.navSelected, const Color(0xFFF04E4E));
|
||||
expect(AppColors.navUnselected, const Color(0xFFFFFFFF));
|
||||
});
|
||||
|
||||
testWidgets('should_render_four_slots_with_white_selected_state', (
|
||||
testWidgets('should_render_four_slots_with_brand_red_selected_state', (
|
||||
tester,
|
||||
) async {
|
||||
var theaterTaps = 0;
|
||||
|
||||
@@ -81,7 +81,7 @@ void main() {
|
||||
expect(viewsText.data, '44.5w');
|
||||
expect(viewsText.style?.fontSize, AppDimens.cardPlayCountFont);
|
||||
expect(viewsText.style?.fontWeight, FontWeight.w400);
|
||||
expect(viewsText.style?.color, AppColors.navSelected);
|
||||
expect(viewsText.style?.color, AppColors.textPrimary);
|
||||
expect(
|
||||
find.descendant(
|
||||
of: find.byKey(const Key('home-feed-cover-clip-anime-card')),
|
||||
|
||||
@@ -11,9 +11,7 @@ import 'package:fruitshorts/core/data/repositories/catalog_repository.dart';
|
||||
import 'package:fruitshorts/core/data/repositories/favorite_repository.dart';
|
||||
import 'package:fruitshorts/core/data/repositories/playback_repository.dart';
|
||||
import 'package:fruitshorts/core/data/repositories/watch_history_repository.dart';
|
||||
import 'package:fruitshorts/core/theme/app_dimens.dart';
|
||||
import 'package:fruitshorts/pages/home/widgets/home_feed_card.dart';
|
||||
import 'package:fruitshorts/pages/home/widgets/home_feed_grid.dart';
|
||||
import 'package:fruitshorts/core/theme/app_colors.dart';
|
||||
import 'package:fruitshorts/pages/player/player_view.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';
|
||||
@@ -38,36 +36,44 @@ void main() {
|
||||
InMemorySharedPreferencesAsync.empty();
|
||||
});
|
||||
|
||||
testWidgets('should_render_primary_sections_and_secondary_tags_in_order', (
|
||||
tester,
|
||||
) async {
|
||||
testWidgets('should_render_inner_top_tabs_in_order', (tester) async {
|
||||
final repository = _PagedCatalogRepository();
|
||||
await _pumpApp(tester, repository);
|
||||
|
||||
final sectionKeys = [
|
||||
const Key('home-section-category-古装'),
|
||||
const Key('home-section-category-社群'),
|
||||
const Key('home-section-category-爽剧'),
|
||||
const Key('home-section-category-甜宠'),
|
||||
const Key('home-section-category-打脸虐渣'),
|
||||
const Key('home-section-category-虐恋'),
|
||||
final tabKeys = [
|
||||
const Key('recommend-tab-recommend'),
|
||||
const Key('recommend-tab-playlist'),
|
||||
const Key('recommend-tab-all'),
|
||||
];
|
||||
final sectionCenters = sectionKeys
|
||||
final centers = tabKeys
|
||||
.map((key) => tester.getCenter(find.byKey(key)).dx)
|
||||
.toList();
|
||||
expect(sectionCenters, orderedEquals(sectionCenters.toList()..sort()));
|
||||
expect(find.byKey(const Key('home-secondary-tags')), findsNothing);
|
||||
expect(centers, orderedEquals(centers.toList()..sort()));
|
||||
expect(find.byKey(const Key('recommend-section-hits')), findsNothing);
|
||||
expect(find.text('Featured'), findsNothing);
|
||||
expect(find.text('New'), findsNothing);
|
||||
expect(find.text('Categories'), findsNothing);
|
||||
expect(find.text('Charts'), findsNothing);
|
||||
expect(find.text('古装'), findsOneWidget);
|
||||
expect(find.text('社群'), findsOneWidget);
|
||||
expect(find.byKey(const Key('mine-mini-player')), findsNothing);
|
||||
expect(find.byType(FloatingActionButton), findsNothing);
|
||||
expect(find.byKey(const Key('home-tabs-bar')), findsOneWidget);
|
||||
|
||||
final selectedUnderline = tester.widget<Container>(
|
||||
find.byKey(const Key('recommend-tab-recommend-underline')),
|
||||
);
|
||||
expect(
|
||||
(selectedUnderline.decoration! as BoxDecoration).color,
|
||||
AppColors.brandRed,
|
||||
);
|
||||
final idleUnderline = tester.widget<Container>(
|
||||
find.byKey(const Key('recommend-tab-playlist-underline')),
|
||||
);
|
||||
expect(
|
||||
(idleUnderline.decoration! as BoxDecoration).color,
|
||||
AppColors.transparent,
|
||||
);
|
||||
});
|
||||
|
||||
testWidgets('should_hide_unmatched_content_sections', (tester) async {
|
||||
testWidgets('should_render_only_categories_returned_by_api', (tester) async {
|
||||
final repository = _PagedCatalogRepository();
|
||||
await _pumpApp(
|
||||
tester,
|
||||
@@ -75,9 +81,13 @@ void main() {
|
||||
categories: const [ContentCategory(id: 'romance', name: 'Romance')],
|
||||
);
|
||||
|
||||
expect(find.byKey(const Key('home-section-category-古装')), findsNothing);
|
||||
expect(find.byKey(const Key('home-section-category-社群')), findsNothing);
|
||||
expect(find.byKey(const Key('home-tag-uplifting')), findsNothing);
|
||||
await tester.tap(find.byKey(const Key('tab-recommend')));
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
expect(find.byKey(const Key('recommend-channel-nav')), findsOneWidget);
|
||||
expect(find.byKey(const Key('recommend-tab-romance')), findsOneWidget);
|
||||
expect(find.byKey(const Key('recommend-tab-costume')), findsNothing);
|
||||
expect(find.byKey(const Key('recommend-tab-community')), findsNothing);
|
||||
});
|
||||
|
||||
testWidgets('should_switch_home_sections_without_pushing_pages', (
|
||||
@@ -86,24 +96,22 @@ void main() {
|
||||
final repository = _PagedCatalogRepository();
|
||||
await _pumpApp(tester, repository);
|
||||
|
||||
String firstDramaId() {
|
||||
return tester
|
||||
.widget<HomeFeedCard>(find.byType(HomeFeedCard).first)
|
||||
.drama
|
||||
.id;
|
||||
}
|
||||
expect(find.byKey(const Key('recommend-feed-player')), findsOneWidget);
|
||||
expect(find.byKey(const Key('recommend-section-hits')), findsNothing);
|
||||
|
||||
expect(find.byKey(const Key('home-grid')), findsOneWidget);
|
||||
expect(find.byKey(const Key('home-section-featured')), findsNothing);
|
||||
expect(firstDramaId(), 'page1-0');
|
||||
|
||||
await tester.tap(find.byKey(const Key('home-section-category-古装')));
|
||||
await tester.tap(find.byKey(const Key('recommend-tab-playlist')));
|
||||
await tester.pumpAndSettle();
|
||||
expect(firstDramaId(), 'page1-0');
|
||||
_drainLayoutExceptions(tester);
|
||||
expect(find.byKey(const Key('recommend-section-hits')), findsOneWidget);
|
||||
expect(
|
||||
Navigator.of(
|
||||
tester.element(find.byKey(const Key('recommend-page'))),
|
||||
).canPop(),
|
||||
isFalse,
|
||||
);
|
||||
|
||||
await tester.tap(find.byKey(const Key('home-section-category-社群')));
|
||||
await tester.pumpAndSettle();
|
||||
expect(firstDramaId(), 'page1-0');
|
||||
await _openAllDramasTab(tester);
|
||||
expect(find.byKey(const Key('all-dramas-grid')), findsOneWidget);
|
||||
expect(find.byKey(const Key('filter-page')), findsNothing);
|
||||
});
|
||||
|
||||
@@ -112,30 +120,30 @@ void main() {
|
||||
) async {
|
||||
final repository = _PagedCatalogRepository();
|
||||
await _pumpApp(tester, repository);
|
||||
await _openAllDramasTab(tester);
|
||||
|
||||
await tester.drag(
|
||||
find.byKey(const Key('home-grid-scroll')),
|
||||
find.byKey(const Key('all-dramas-scroll')),
|
||||
const Offset(0, -320),
|
||||
);
|
||||
await tester.pumpAndSettle();
|
||||
final scrollable = find
|
||||
.descendant(
|
||||
of: find.byKey(const Key('home-grid-scroll')),
|
||||
of: find.byKey(const Key('all-dramas-scroll')),
|
||||
matching: find.byType(Scrollable),
|
||||
)
|
||||
.first;
|
||||
final before = tester.state<ScrollableState>(scrollable).position.pixels;
|
||||
expect(before, greaterThan(0));
|
||||
|
||||
await tester.tap(find.byKey(const Key('home-section-category-社群')));
|
||||
await tester.tap(find.byKey(const Key('recommend-tab-playlist')));
|
||||
await tester.pumpAndSettle();
|
||||
await tester.tap(find.byKey(const Key('home-section-category-古装')));
|
||||
await tester.pumpAndSettle();
|
||||
expect(find.byKey(const Key('home-secondary-tags')), findsNothing);
|
||||
_drainLayoutExceptions(tester);
|
||||
|
||||
await _openAllDramasTab(tester);
|
||||
final afterScrollable = find
|
||||
.descendant(
|
||||
of: find.byKey(const Key('home-grid-scroll')),
|
||||
of: find.byKey(const Key('all-dramas-scroll')),
|
||||
matching: find.byType(Scrollable),
|
||||
)
|
||||
.first;
|
||||
@@ -145,30 +153,42 @@ void main() {
|
||||
);
|
||||
});
|
||||
|
||||
testWidgets('should_swipe_between_primary_sections', (tester) async {
|
||||
testWidgets('should_swipe_between_inner_sections', (tester) async {
|
||||
final repository = _PagedCatalogRepository();
|
||||
await _pumpApp(tester, repository);
|
||||
|
||||
expect(find.byKey(const Key('home-secondary-tags')), findsNothing);
|
||||
await tester.drag(
|
||||
find.byKey(const Key('home-primary-page-view')),
|
||||
const Offset(-320, 0),
|
||||
final pages = find.byKey(const Key('recommend-tab-page-view'));
|
||||
final topNavBefore = tester.getRect(
|
||||
find.byKey(const Key('recommend-top-nav')),
|
||||
);
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
expect(find.byKey(const Key('home-secondary-tags')), findsNothing);
|
||||
final selected = tester.widget<AnimatedDefaultTextStyle>(
|
||||
find.byKey(const Key('home-primary-label-community')),
|
||||
);
|
||||
expect(selected.style.fontSize, AppDimens.homePrimaryTabSelectedFont);
|
||||
expect(selected.style.fontWeight, FontWeight.w700);
|
||||
|
||||
await tester.drag(
|
||||
find.byKey(const Key('home-primary-page-view')),
|
||||
const Offset(320, 0),
|
||||
);
|
||||
await tester.drag(pages, const Offset(-320, 0));
|
||||
await tester.pumpAndSettle();
|
||||
expect(find.byKey(const Key('home-secondary-tags')), findsNothing);
|
||||
_drainLayoutExceptions(tester);
|
||||
expect(find.byKey(const Key('recommend-section-hits')), findsOneWidget);
|
||||
expect(find.byKey(const Key('recommend-feed-player')), findsNothing);
|
||||
final selected = tester.widget<Text>(
|
||||
find.descendant(
|
||||
of: find.byKey(const Key('recommend-tab-playlist')),
|
||||
matching: find.text('Playlists'),
|
||||
),
|
||||
);
|
||||
expect(selected.style?.fontWeight, FontWeight.w700);
|
||||
expect(
|
||||
tester.getRect(find.byKey(const Key('recommend-top-nav'))),
|
||||
topNavBefore,
|
||||
);
|
||||
|
||||
await tester.drag(pages, const Offset(-320, 0));
|
||||
await tester.pumpAndSettle();
|
||||
_drainLayoutExceptions(tester);
|
||||
expect(find.byKey(const Key('all-dramas-grid')), findsOneWidget);
|
||||
|
||||
await tester.drag(pages, const Offset(640, 0));
|
||||
await tester.pumpAndSettle();
|
||||
_drainLayoutExceptions(tester);
|
||||
expect(find.byKey(const Key('recommend-feed-player')), findsOneWidget);
|
||||
expect(find.byKey(const Key('recommend-tab-recommend')), findsOneWidget);
|
||||
});
|
||||
|
||||
testWidgets('should_load_next_page_without_expanding_page_size', (
|
||||
@@ -176,45 +196,41 @@ void main() {
|
||||
) async {
|
||||
final repository = _PagedCatalogRepository();
|
||||
await _pumpApp(tester, repository);
|
||||
await _openAllDramasTab(tester);
|
||||
|
||||
expect(find.byKey(const Key('home-feed-card-page1-0')), findsOneWidget);
|
||||
await tester.drag(
|
||||
find.byKey(const Key('home-grid-scroll')),
|
||||
const Offset(0, -1200),
|
||||
);
|
||||
await tester.pumpAndSettle();
|
||||
for (var attempt = 0; attempt < 3; attempt++) {
|
||||
await tester.drag(
|
||||
find.byKey(const Key('all-dramas-scroll')),
|
||||
const Offset(0, -800),
|
||||
);
|
||||
await tester.pumpAndSettle();
|
||||
_drainLayoutExceptions(tester);
|
||||
}
|
||||
expect(repository.cursors, contains('page1'));
|
||||
expect(repository.requestedSizes.every((size) => size <= 20), isTrue);
|
||||
|
||||
expect(find.byKey(const Key('home-grid-refresh')), findsOneWidget);
|
||||
final gridScrollable = find
|
||||
.descendant(
|
||||
of: find.byKey(const Key('home-grid-scroll')),
|
||||
of: find.byKey(const Key('all-dramas-scroll')),
|
||||
matching: find.byType(Scrollable),
|
||||
);
|
||||
expect(gridScrollable, findsOneWidget);
|
||||
final secondPageCard = find.byKey(
|
||||
const Key('home-feed-card-page2-0'),
|
||||
);
|
||||
final feed = tester
|
||||
.widget<HomeFeedGrid>(find.byType(HomeFeedGrid))
|
||||
.feedController;
|
||||
expect(
|
||||
feed.dramas.map((drama) => drama.id),
|
||||
contains('page2-0'),
|
||||
);
|
||||
)
|
||||
.first;
|
||||
final secondPageCard = find.byKey(const Key('home-feed-card-page2-0'));
|
||||
final position = tester.state<ScrollableState>(gridScrollable).position;
|
||||
await tester.pump();
|
||||
position.jumpTo(position.maxScrollExtent);
|
||||
await tester.pump();
|
||||
position.jumpTo(position.maxScrollExtent);
|
||||
await tester.pump();
|
||||
_drainLayoutExceptions(tester);
|
||||
expect(secondPageCard, findsOneWidget);
|
||||
});
|
||||
|
||||
testWidgets('should_open_player_when_grid_card_is_tapped', (tester) async {
|
||||
final repository = _PagedCatalogRepository();
|
||||
await _pumpApp(tester, repository);
|
||||
await _openAllDramasTab(tester);
|
||||
|
||||
await tester.tap(find.byKey(const Key('home-feed-card-page1-0')));
|
||||
await tester.pumpAndSettle();
|
||||
@@ -224,6 +240,20 @@ void main() {
|
||||
});
|
||||
}
|
||||
|
||||
/// 打开首页内层「全部短剧」页;顺带消费测试字体(Ahem)造成的卡片溢出。
|
||||
Future<void> _openAllDramasTab(WidgetTester tester) async {
|
||||
await tester.ensureVisible(find.byKey(const Key('recommend-tab-all')));
|
||||
await tester.pumpAndSettle();
|
||||
await tester.tap(find.byKey(const Key('recommend-tab-all')));
|
||||
await tester.pumpAndSettle();
|
||||
_drainLayoutExceptions(tester);
|
||||
}
|
||||
|
||||
/// 剧单/网格卡片高度按真机字体设计,测试字体行高更大时会溢出几个像素。
|
||||
void _drainLayoutExceptions(WidgetTester tester) {
|
||||
while (tester.takeException() != null) {}
|
||||
}
|
||||
|
||||
Future<void> _pumpApp(
|
||||
WidgetTester tester,
|
||||
_PagedCatalogRepository repository, {
|
||||
|
||||
+45
-102
@@ -43,74 +43,37 @@ void main() {
|
||||
tester,
|
||||
) async {
|
||||
final haptics = FakeHaptics();
|
||||
await _pumpApp(tester, haptics);
|
||||
await _pumpApp(tester, haptics: haptics);
|
||||
haptics.reset();
|
||||
|
||||
for (final key in _keys) {
|
||||
expect(find.byKey(key), findsOneWidget);
|
||||
}
|
||||
expect(find.byKey(const Key('home-wallet-entry')), findsOneWidget);
|
||||
expect(find.byKey(const Key('home-wallet-badge')), findsOneWidget);
|
||||
final searchEntry = find.byKey(const Key('home-search-entry'));
|
||||
final vipEntry = find.byKey(const Key('home-vip-entry'));
|
||||
final walletEntry = find.byKey(const Key('home-wallet-entry'));
|
||||
// 首页顶部改为悬浮内层导航:搜索 + 礼物(钱包)入口。
|
||||
expect(find.byKey(const Key('recommend-top-nav')), findsOneWidget);
|
||||
final searchEntry = find.byKey(const Key('recommend-search'));
|
||||
final walletEntry = find.byKey(const Key('recommend-gift'));
|
||||
expect(
|
||||
tester.getSize(vipEntry),
|
||||
tester.getSize(searchEntry),
|
||||
const Size.square(AppDimens.homeActionSlot),
|
||||
);
|
||||
expect(
|
||||
tester.getSize(walletEntry),
|
||||
const Size.square(AppDimens.homeActionSlot),
|
||||
);
|
||||
expect(tester.widget<IconButton>(searchEntry).iconSize, 26);
|
||||
expect(tester.widget<IconButton>(walletEntry).iconSize, 26);
|
||||
expect(
|
||||
tester.getSize(find.byKey(const Key('home-vip-icon-frame'))),
|
||||
const Size.square(AppDimens.homeActionIcon),
|
||||
);
|
||||
expect(
|
||||
tester.getSize(find.byKey(const Key('home-wallet-icon-frame'))),
|
||||
const Size.square(AppDimens.homeActionIcon),
|
||||
);
|
||||
expect(
|
||||
tester.getCenter(find.byKey(const Key('home-vip-icon-frame'))).dy,
|
||||
tester.getCenter(find.byKey(const Key('home-wallet-icon-frame'))).dy,
|
||||
);
|
||||
final crownImage = tester.widget<Image>(
|
||||
find.byKey(const Key('home-vip-image')),
|
||||
);
|
||||
final giftImage = tester.widget<Image>(
|
||||
find.byKey(const Key('home-wallet-image')),
|
||||
);
|
||||
expect((crownImage.image as AssetImage).assetName, 'assets/icon/crown.png');
|
||||
expect((giftImage.image as AssetImage).assetName, 'assets/icon/gift.png');
|
||||
expect(
|
||||
tester.getCenter(vipEntry).dy,
|
||||
closeTo(tester.getCenter(searchEntry).dy, 0.1),
|
||||
);
|
||||
expect(
|
||||
tester.getCenter(walletEntry).dy,
|
||||
closeTo(tester.getCenter(searchEntry).dy, 0.1),
|
||||
);
|
||||
expect(
|
||||
tester.getTopLeft(walletEntry).dx - tester.getTopRight(vipEntry).dx,
|
||||
AppDimens.homeActionGap,
|
||||
tester.getCenter(searchEntry).dy,
|
||||
closeTo(tester.getCenter(walletEntry).dy, 0.1),
|
||||
);
|
||||
expect(
|
||||
tester.getTopRight(walletEntry).dx,
|
||||
closeTo(390 - AppDimens.feedPageHorizontal, 0.1),
|
||||
closeTo(390 - 8, 0.1),
|
||||
);
|
||||
expect(crownImage.width, AppDimens.homeActionIcon);
|
||||
expect(crownImage.height, AppDimens.homeActionIcon);
|
||||
expect(crownImage.fit, BoxFit.contain);
|
||||
expect(giftImage.width, AppDimens.homeActionIcon);
|
||||
expect(giftImage.height, AppDimens.homeActionIcon);
|
||||
expect(giftImage.fit, BoxFit.contain);
|
||||
expect(
|
||||
tester
|
||||
.widget<Material>(
|
||||
find.ancestor(of: vipEntry, matching: find.byType(Material)).first,
|
||||
)
|
||||
.color,
|
||||
AppColors.transparent,
|
||||
tester.getTopRight(searchEntry).dx,
|
||||
closeTo(tester.getTopLeft(walletEntry).dx, 0.1),
|
||||
);
|
||||
expect(find.byKey(const Key('mine-mini-player')), findsNothing);
|
||||
expect(find.byType(FloatingActionButton), findsNothing);
|
||||
@@ -178,17 +141,26 @@ void main() {
|
||||
.duration,
|
||||
lessThanOrEqualTo(const Duration(milliseconds: 200)),
|
||||
);
|
||||
expect(
|
||||
final selectedHomeIcon = tester.widget<Icon>(
|
||||
find.descendant(
|
||||
of: find.byKey(const Key('tab-home')),
|
||||
matching: find.byType(Image),
|
||||
matching: find.byIcon(Icons.home_rounded),
|
||||
),
|
||||
findsOneWidget,
|
||||
);
|
||||
expect(selectedHomeIcon.color, AppColors.navSelected);
|
||||
expect(
|
||||
tester.getSize(
|
||||
find.descendant(
|
||||
of: find.byKey(const Key('tab-home')),
|
||||
matching: find.byIcon(Icons.home_rounded),
|
||||
),
|
||||
),
|
||||
const Size.square(AppDimens.navIcon),
|
||||
);
|
||||
expect(
|
||||
find.descendant(
|
||||
of: find.byKey(const Key('tab-recommend')),
|
||||
matching: find.byIcon(Icons.smart_display_outlined),
|
||||
matching: find.byIcon(Icons.celebration_outlined),
|
||||
),
|
||||
findsOneWidget,
|
||||
);
|
||||
@@ -206,31 +178,6 @@ void main() {
|
||||
),
|
||||
findsOneWidget,
|
||||
);
|
||||
expect(
|
||||
tester
|
||||
.widget<ColorFiltered>(
|
||||
find.descendant(
|
||||
of: find.byKey(const Key('tab-home')),
|
||||
matching: find.byType(ColorFiltered),
|
||||
),
|
||||
)
|
||||
.colorFilter,
|
||||
const ColorFilter.mode(AppColors.navSelected, BlendMode.srcIn),
|
||||
);
|
||||
final selectedHomeImage = tester.widget<Image>(
|
||||
find.descendant(
|
||||
of: find.byKey(const Key('tab-home')),
|
||||
matching: find.byType(Image),
|
||||
),
|
||||
);
|
||||
expect(
|
||||
(selectedHomeImage.image as AssetImage).assetName,
|
||||
'assets/icon/film_reel_filled.png',
|
||||
);
|
||||
expect(
|
||||
Size(selectedHomeImage.width!, selectedHomeImage.height!),
|
||||
const Size.square(AppDimens.navIcon),
|
||||
);
|
||||
|
||||
await tester.tap(find.byKey(const Key('tab-recommend')));
|
||||
await tester.pumpAndSettle();
|
||||
@@ -244,7 +191,7 @@ void main() {
|
||||
expect(
|
||||
find.descendant(
|
||||
of: find.byKey(const Key('tab-recommend')),
|
||||
matching: find.byIcon(Icons.smart_display_rounded),
|
||||
matching: find.byIcon(Icons.celebration_rounded),
|
||||
),
|
||||
findsOneWidget,
|
||||
);
|
||||
@@ -275,48 +222,40 @@ void main() {
|
||||
expect(
|
||||
find.descendant(
|
||||
of: find.byKey(const Key('tab-home')),
|
||||
matching: find.byType(Image),
|
||||
matching: find.byIcon(Icons.home_outlined),
|
||||
),
|
||||
findsOneWidget,
|
||||
);
|
||||
expect(
|
||||
tester
|
||||
.widget<ColorFiltered>(
|
||||
.widget<Icon>(
|
||||
find.descendant(
|
||||
of: find.byKey(const Key('tab-home')),
|
||||
matching: find.byType(ColorFiltered),
|
||||
matching: find.byIcon(Icons.home_outlined),
|
||||
),
|
||||
)
|
||||
.colorFilter,
|
||||
const ColorFilter.mode(AppColors.navUnselected, BlendMode.srcIn),
|
||||
);
|
||||
final unselectedHomeImage = tester.widget<Image>(
|
||||
find.descendant(
|
||||
of: find.byKey(const Key('tab-home')),
|
||||
matching: find.byType(Image),
|
||||
),
|
||||
);
|
||||
expect(
|
||||
(unselectedHomeImage.image as AssetImage).assetName,
|
||||
'assets/icon/film_reel.png',
|
||||
.color,
|
||||
AppColors.navUnselected,
|
||||
);
|
||||
});
|
||||
|
||||
testWidgets('should_map_four_tabs_to_home_recommend_following_and_me', (
|
||||
tester,
|
||||
) async {
|
||||
await _pumpApp(tester);
|
||||
// 追剧页头部的双语分段文案在测试字体(Ahem)下比真机字体宽约 98pt,
|
||||
// 这里放宽视口宽度,避免测字体撑破 390 宽度下的分段行。
|
||||
await _pumpApp(tester, size: const Size(520, 844));
|
||||
|
||||
expect(find.byKey(const Key('tab-home')), findsOneWidget);
|
||||
expect(find.byKey(const Key('tab-recommend')), findsOneWidget);
|
||||
expect(find.byKey(const Key('tab-follow')), findsOneWidget);
|
||||
expect(find.byKey(const Key('tab-mine')), findsOneWidget);
|
||||
expect(find.byKey(const Key('tab-create')), findsNothing);
|
||||
expect(find.byKey(const Key('home-grid')), findsOneWidget);
|
||||
expect(find.byKey(const Key('recommend-feed-player')), findsOneWidget);
|
||||
|
||||
await tester.tap(find.byKey(const Key('tab-recommend')));
|
||||
await tester.pumpAndSettle();
|
||||
expect(find.byKey(const Key('recommend-page')), findsOneWidget);
|
||||
expect(find.byKey(const Key('recommend-channel-nav')), findsOneWidget);
|
||||
_expectNoFloatingOverlays();
|
||||
|
||||
await tester.tap(find.byKey(const Key('tab-follow')));
|
||||
@@ -356,14 +295,14 @@ void main() {
|
||||
|
||||
await tester.tap(find.byKey(const Key('tab-home')));
|
||||
await tester.pumpAndSettle();
|
||||
expect(find.byKey(const Key('home-grid')), findsOneWidget);
|
||||
expect(find.byKey(const Key('recommend-feed-player')), findsOneWidget);
|
||||
});
|
||||
|
||||
testWidgets('should_not_haptic_when_ordinary_list_item_is_opened', (
|
||||
tester,
|
||||
) async {
|
||||
final haptics = FakeHaptics();
|
||||
await _pumpApp(tester, haptics);
|
||||
await _pumpApp(tester, haptics: haptics);
|
||||
await tester.tap(find.byKey(const Key('tab-mine')));
|
||||
await tester.pumpAndSettle();
|
||||
haptics.reset();
|
||||
@@ -377,8 +316,12 @@ void main() {
|
||||
});
|
||||
}
|
||||
|
||||
Future<void> _pumpApp(WidgetTester tester, [FakeHaptics? haptics]) async {
|
||||
tester.view.physicalSize = const Size(390, 844);
|
||||
Future<void> _pumpApp(
|
||||
WidgetTester tester, {
|
||||
FakeHaptics? haptics,
|
||||
Size size = const Size(390, 844),
|
||||
}) async {
|
||||
tester.view.physicalSize = size;
|
||||
tester.view.devicePixelRatio = 1;
|
||||
addTearDown(tester.view.resetPhysicalSize);
|
||||
addTearDown(tester.view.resetDevicePixelRatio);
|
||||
|
||||
@@ -77,67 +77,60 @@ void main() {
|
||||
);
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
expect(find.byKey(const Key('home-grid')), findsOneWidget);
|
||||
expect(find.byKey(const Key('home-grid-cards')), findsOneWidget);
|
||||
// 首页即沉浸式推荐流:顶部悬浮「推荐 / 片单 / 全部短剧」+ 搜索与礼物入口。
|
||||
expect(find.byKey(const Key('recommend-page')), findsOneWidget);
|
||||
expect(find.byKey(const Key('recommend-top-nav')), findsOneWidget);
|
||||
expect(find.byKey(const Key('recommend-feed-player')), findsOneWidget);
|
||||
expect(find.byKey(const Key('recommend-tab-recommend')), findsOneWidget);
|
||||
expect(find.byKey(const Key('recommend-tab-playlist')), findsOneWidget);
|
||||
expect(find.byKey(const Key('recommend-tab-all')), findsOneWidget);
|
||||
final searchButton = tester.widget<IconButton>(
|
||||
find.byKey(const Key('recommend-search')),
|
||||
);
|
||||
expect(searchButton.iconSize, 26);
|
||||
expect(
|
||||
tester.getSize(find.byKey(const Key('recommend-search'))),
|
||||
const Size.square(40),
|
||||
);
|
||||
expect(
|
||||
tester.getSize(find.byKey(const Key('recommend-gift'))),
|
||||
const Size.square(40),
|
||||
);
|
||||
expect(
|
||||
tester.getCenter(find.byKey(const Key('recommend-search'))).dy,
|
||||
closeTo(
|
||||
tester.getCenter(find.byKey(const Key('recommend-gift'))).dy,
|
||||
0.1,
|
||||
),
|
||||
);
|
||||
|
||||
// 「全部短剧」仍是三列浏览网格。
|
||||
await tester.ensureVisible(find.byKey(const Key('recommend-tab-all')));
|
||||
await tester.pumpAndSettle();
|
||||
await tester.tap(find.byKey(const Key('recommend-tab-all')));
|
||||
await tester.pumpAndSettle();
|
||||
// 切换到「全部短剧」时 PageView 会临时布局「片单」页;剧单卡片高度贴着
|
||||
// 228pt 上限,测试字体(Ahem)行高偏大会溢出约 2.7pt,真机字体不触发。
|
||||
while (tester.takeException() != null) {}
|
||||
expect(find.byKey(const Key('all-dramas-grid')), findsOneWidget);
|
||||
final grid = tester.widget<SliverGrid>(
|
||||
find.byKey(const Key('home-grid-cards')),
|
||||
find.byKey(const Key('all-dramas-grid')),
|
||||
);
|
||||
final delegate =
|
||||
grid.gridDelegate as SliverGridDelegateWithFixedCrossAxisCount;
|
||||
expect(delegate.crossAxisCount, 3);
|
||||
expect(delegate.crossAxisSpacing, AppDimens.homeGridGap);
|
||||
expect(delegate.mainAxisSpacing, AppDimens.homeGridRowGap);
|
||||
expect(find.byKey(const Key('home-section-featured')), findsNothing);
|
||||
expect(find.byKey(const Key('home-section-category-古装')), findsOneWidget);
|
||||
expect(find.byKey(const Key('home-section-category-社群')), findsOneWidget);
|
||||
expect(find.byKey(const Key('home-secondary-tags')), findsNothing);
|
||||
expect(find.byKey(const Key('home-grid-filter')), findsNothing);
|
||||
final searchBox = find.descendant(
|
||||
of: find.byKey(const Key('home-search-entry')),
|
||||
matching: find.byType(Container),
|
||||
);
|
||||
expect(tester.getSize(searchBox).height, AppDimens.searchHeight);
|
||||
expect(
|
||||
(tester.widget<Container>(searchBox).decoration! as BoxDecoration)
|
||||
.borderRadius,
|
||||
BorderRadius.circular(AppDimens.searchRadius),
|
||||
);
|
||||
final placeholder = tester.widget<Text>(
|
||||
find.text('Search dramas, actors, genres...'),
|
||||
);
|
||||
expect(placeholder.style?.fontSize, AppDimens.searchPlaceholderFont);
|
||||
expect(placeholder.style?.color, AppColors.textSecondary);
|
||||
final selectedPrimary = tester.widget<AnimatedDefaultTextStyle>(
|
||||
find.byKey(const Key('home-primary-label-costume')),
|
||||
);
|
||||
final unselectedPrimary = tester.widget<AnimatedDefaultTextStyle>(
|
||||
find.byKey(const Key('home-primary-label-community')),
|
||||
);
|
||||
expect(
|
||||
selectedPrimary.style.fontSize,
|
||||
AppDimens.homePrimaryTabSelectedFont,
|
||||
);
|
||||
expect(selectedPrimary.style.fontWeight, FontWeight.w700);
|
||||
expect(selectedPrimary.style.color, AppColors.navSelected);
|
||||
expect(selectedPrimary.duration, AppDimens.homePrimaryTabAnimationDuration);
|
||||
expect(unselectedPrimary.style.fontSize, AppDimens.homePrimaryTabFont);
|
||||
expect(unselectedPrimary.style.fontWeight, FontWeight.w400);
|
||||
expect(unselectedPrimary.style.color, AppColors.textTabInactive);
|
||||
expect(
|
||||
find.descendant(
|
||||
of: find.byKey(const Key('home-section-category-古装')),
|
||||
matching: find.byType(Container),
|
||||
),
|
||||
findsNothing,
|
||||
);
|
||||
final primaryStart = tester.getTopLeft(find.text('古装'));
|
||||
final pageStart = tester.getTopLeft(searchBox);
|
||||
expect(primaryStart.dx, pageStart.dx);
|
||||
final primaryGap =
|
||||
tester.getTopLeft(find.text('社群')).dx -
|
||||
tester.getBottomRight(find.text('古装')).dx;
|
||||
expect(primaryGap, closeTo(AppDimens.homePrimaryCategoryGap, 0.1));
|
||||
expect(find.byKey(const Key('home-primary-page-view')), findsOneWidget);
|
||||
expect(delegate.crossAxisSpacing, AppDimens.allDramasGridGap);
|
||||
expect(delegate.mainAxisSpacing, AppDimens.allDramasGridRowGap);
|
||||
for (var row = 0; row < 3; row++) {
|
||||
expect(find.byKey(Key('all-filter-row-$row')), findsOneWidget);
|
||||
}
|
||||
|
||||
// 底部「推荐」tab 的频道导航来自分类接口。
|
||||
await tester.tap(find.byKey(const Key('tab-recommend')));
|
||||
await tester.pumpAndSettle();
|
||||
expect(find.byKey(const Key('recommend-channel-nav')), findsOneWidget);
|
||||
expect(find.byKey(const Key('recommend-tab-costume')), findsOneWidget);
|
||||
expect(find.byKey(const Key('recommend-tab-community')), findsOneWidget);
|
||||
expect(tester.takeException(), isNull);
|
||||
});
|
||||
|
||||
@@ -166,10 +159,8 @@ void main() {
|
||||
),
|
||||
);
|
||||
await tester.pumpAndSettle();
|
||||
await tester.tap(find.byKey(const Key('tab-recommend')));
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
expect(find.byKey(const Key('home-grid')), findsNothing);
|
||||
// 首页沉浸式播放器与顶部内层导航。
|
||||
expect(find.byKey(const Key('recommend-page')), findsOneWidget);
|
||||
expect(find.byKey(const Key('recommend-feed-player')), findsOneWidget);
|
||||
expect(find.byType(PlayerPage), findsOneWidget);
|
||||
@@ -178,12 +169,16 @@ void main() {
|
||||
|
||||
await tester.tap(find.byKey(const Key('recommend-tab-playlist')));
|
||||
await tester.pumpAndSettle();
|
||||
// 剧单卡片高度贴着 228pt 上限,测试字体(Ahem)行高比真机字体大,
|
||||
// 会溢出约 2.7pt;真机字体不触发,这里消费该渲染字体差异。
|
||||
while (tester.takeException() != null) {}
|
||||
expect(find.byKey(const Key('recommend-section-hits')), findsOneWidget);
|
||||
|
||||
await tester.tap(
|
||||
find.byKey(const Key('recommend-card-hits-the-signal-demo')),
|
||||
);
|
||||
await tester.pumpAndSettle();
|
||||
while (tester.takeException() != null) {}
|
||||
expect(
|
||||
tester.widget<PlayerPage>(find.byType(PlayerPage).last).homeMode,
|
||||
isFalse,
|
||||
@@ -210,7 +205,7 @@ void main() {
|
||||
favoriteCount: 32000,
|
||||
commentCount: 12,
|
||||
);
|
||||
var episodesOpened = 0;
|
||||
var shares = 0;
|
||||
await tester.pumpWidget(
|
||||
MaterialApp(
|
||||
theme: AppTheme.light(),
|
||||
@@ -243,10 +238,10 @@ void main() {
|
||||
onLike: () {},
|
||||
onSave: () {},
|
||||
onComments: () {},
|
||||
onShare: () {},
|
||||
onShare: () => shares++,
|
||||
onDetail: () {},
|
||||
onOpenFullPlayer: () {},
|
||||
onEpisodes: () => episodesOpened++,
|
||||
onEpisodes: () {},
|
||||
onMore: () {},
|
||||
),
|
||||
),
|
||||
@@ -260,8 +255,8 @@ void main() {
|
||||
);
|
||||
expect(seriesTitle.data, 'Feed Drama');
|
||||
expect(find.text('Episode 2'), findsNothing);
|
||||
expect(seriesTitle.style?.fontSize, 19);
|
||||
expect(seriesTitle.style?.fontWeight, FontWeight.w600);
|
||||
expect(seriesTitle.style?.fontSize, 17);
|
||||
expect(seriesTitle.style?.fontWeight, FontWeight.w400);
|
||||
expect(seriesTitle.style?.color, AppColors.textPrimary);
|
||||
final seriesChevron = tester.widget<Icon>(
|
||||
find.descendant(
|
||||
@@ -269,51 +264,42 @@ void main() {
|
||||
matching: find.byIcon(Icons.chevron_right_rounded),
|
||||
),
|
||||
);
|
||||
expect(seriesChevron.size, 20);
|
||||
expect(seriesChevron.size, 18);
|
||||
expect(seriesChevron.color, AppColors.textPrimary);
|
||||
expect(
|
||||
tester.getTopLeft(find.byIcon(Icons.chevron_right_rounded)).dx -
|
||||
tester
|
||||
.getTopLeft(
|
||||
find.descendant(
|
||||
of: find.byKey(const Key('home-feed-series-name')),
|
||||
matching: find.byIcon(Icons.chevron_right_rounded),
|
||||
),
|
||||
)
|
||||
.dx -
|
||||
tester
|
||||
.getTopRight(find.byKey(const Key('home-feed-series-title')))
|
||||
.dx,
|
||||
4,
|
||||
2,
|
||||
);
|
||||
expect(find.byKey(const Key('home-feed-info-card')), findsNothing);
|
||||
expect(find.byKey(const Key('home-feed-info-panel')), findsOneWidget);
|
||||
expect(find.byKey(const Key('home-feed-full-series')), findsOneWidget);
|
||||
expect(find.byKey(const Key('home-feed-tags')), findsOneWidget);
|
||||
expect(find.byKey(const Key('home-feed-tag-Romance')), findsOneWidget);
|
||||
expect(find.byKey(const Key('home-feed-tag-Urban')), findsOneWidget);
|
||||
final collapsedSynopsis = tester.widget<Text>(
|
||||
find.byKey(const Key('home-feed-synopsis')),
|
||||
);
|
||||
expect(collapsedSynopsis.maxLines, 1);
|
||||
expect(collapsedSynopsis.overflow, TextOverflow.ellipsis);
|
||||
expect(find.byKey(const Key('home-feed-synopsis-more')), findsOneWidget);
|
||||
await tester.tap(find.byKey(const Key('home-feed-synopsis-more')));
|
||||
await tester.pump();
|
||||
expect(
|
||||
tester.widget<Text>(find.byKey(const Key('home-feed-synopsis'))).maxLines,
|
||||
isNull,
|
||||
);
|
||||
expect(find.byKey(const Key('home-feed-synopsis-expanded')), findsOneWidget);
|
||||
expect(
|
||||
tester
|
||||
.widget<Text>(find.byKey(const Key('home-feed-episode-progress')))
|
||||
.data,
|
||||
'Episode 2 / 8 total',
|
||||
);
|
||||
expect(find.byKey(const Key('home-feed-meta-pills')), findsNothing);
|
||||
expect(find.byKey(const Key('home-feed-ranking-pill')), findsNothing);
|
||||
expect(find.byKey(const Key('home-feed-view-pill')), findsNothing);
|
||||
expect(find.text('Romance Urban'), findsOneWidget);
|
||||
final genreText = tester.widget<Text>(find.text('Romance Urban'));
|
||||
expect(genreText.style?.fontSize, 13);
|
||||
expect(genreText.style?.color, AppColors.overlayLabel);
|
||||
final episodeProgress = tester.widget<Text>(
|
||||
find.byKey(const Key('home-feed-episode-progress')),
|
||||
);
|
||||
expect(episodeProgress.maxLines, 1);
|
||||
expect(episodeProgress.overflow, TextOverflow.ellipsis);
|
||||
expect(episodeProgress.style?.fontSize, 13);
|
||||
expect(episodeProgress.style?.color, AppColors.overlayLabel);
|
||||
expect(
|
||||
tester
|
||||
.getTopLeft(find.byKey(const Key('home-feed-episode-progress')))
|
||||
.dx -
|
||||
tester.getTopRight(find.text('Romance Urban')).dx,
|
||||
8,
|
||||
.widget<Text>(find.byKey(const Key('home-feed-synopsis-expanded')))
|
||||
.textSpan!
|
||||
.toPlainText(),
|
||||
allOf(contains('EP2'), contains('dangerous city')),
|
||||
);
|
||||
expect(
|
||||
tester.widget<Text>(find.byKey(const Key('rail-like-count'))).data,
|
||||
@@ -339,14 +325,15 @@ void main() {
|
||||
(likeImage.image as AssetImage).assetName,
|
||||
'assets/icon/rail/rail_like.png',
|
||||
);
|
||||
expect(likeImage.color, AppColors.doubleTapHeartRed);
|
||||
expect(likeImage.color, AppColors.brandRed);
|
||||
expect(
|
||||
(saveImage.image as AssetImage).assetName,
|
||||
'assets/icon/rail/rail_save.png',
|
||||
);
|
||||
expect(saveImage.color, AppColors.onPrimary);
|
||||
expect(find.byKey(const Key('rail-comments')), findsOneWidget);
|
||||
expect(find.byKey(const Key('rail-share')), findsNothing);
|
||||
expect(find.byKey(const Key('rail-share')), findsOneWidget);
|
||||
expect(find.byKey(const Key('rail-episodes')), findsNothing);
|
||||
expect(
|
||||
tester.widget<Text>(find.byKey(const Key('rail-comments-count'))).data,
|
||||
'12',
|
||||
@@ -364,25 +351,18 @@ void main() {
|
||||
.assetName,
|
||||
'assets/icon/rail/rail_comment.png',
|
||||
);
|
||||
expect(find.byKey(const Key('rail-episodes')), findsOneWidget);
|
||||
expect(
|
||||
find.descendant(
|
||||
of: find.byKey(const Key('rail-episodes')),
|
||||
matching: find.byIcon(Icons.layers_rounded),
|
||||
),
|
||||
findsOneWidget,
|
||||
);
|
||||
final saveRect = tester.getRect(find.byKey(const Key('rail-save')));
|
||||
final likeRect = tester.getRect(find.byKey(const Key('rail-like')));
|
||||
final commentsRect = tester.getRect(find.byKey(const Key('rail-comments')));
|
||||
final episodesRect = tester.getRect(find.byKey(const Key('rail-episodes')));
|
||||
expect(likeRect.top - saveRect.bottom, closeTo(14, 0.1));
|
||||
expect(commentsRect.top - likeRect.bottom, closeTo(14, 0.1));
|
||||
expect(episodesRect.top - commentsRect.bottom, closeTo(14, 0.1));
|
||||
final shareRect = tester.getRect(find.byKey(const Key('rail-share')));
|
||||
// 新版互动栏顺序:收藏 → 评论 → 喜欢 → 分享,间距 12。
|
||||
expect(commentsRect.top - saveRect.bottom, closeTo(12, 0.1));
|
||||
expect(likeRect.top - commentsRect.bottom, closeTo(12, 0.1));
|
||||
expect(shareRect.top - likeRect.bottom, closeTo(12, 0.1));
|
||||
expect(
|
||||
tester.getRect(find.byKey(const Key('home-feed-action-rail'))).right,
|
||||
closeTo(
|
||||
tester.getRect(find.byKey(const Key('home-feed-gesture'))).right - 8,
|
||||
tester.getRect(find.byKey(const Key('home-feed-gesture'))).right - 14,
|
||||
0.1,
|
||||
),
|
||||
);
|
||||
@@ -392,8 +372,8 @@ void main() {
|
||||
findsOneWidget,
|
||||
);
|
||||
expect(find.byKey(const Key('home-feed-progress-thumb')), findsNothing);
|
||||
await tester.tap(find.byKey(const Key('rail-episodes')));
|
||||
expect(episodesOpened, 1);
|
||||
await tester.tap(find.byKey(const Key('rail-share')));
|
||||
expect(shares, 1);
|
||||
});
|
||||
|
||||
testWidgets('should_show_static_track_without_seek_when_feed_is_locked', (
|
||||
@@ -599,26 +579,27 @@ void main() {
|
||||
final overlayRect = tester.getRect(
|
||||
find.byKey(const Key('home-feed-gesture')),
|
||||
);
|
||||
expect(bar.left, closeTo(overlayRect.left + 14, 0.1));
|
||||
expect(bar.width, closeTo(overlayRect.width * 0.7, 1));
|
||||
// 通栏观看条铺满浮层宽度,不再左右内缩。
|
||||
expect(bar.left, closeTo(overlayRect.left, 0.1));
|
||||
expect(bar.width, closeTo(overlayRect.width, 0.1));
|
||||
// 进度线中心比观看条顶沿高 8pt。
|
||||
expect(
|
||||
tester.getCenter(find.byKey(const Key('home-feed-progress-track'))).dy -
|
||||
bar.bottom,
|
||||
greaterThanOrEqualTo(20),
|
||||
bar.top -
|
||||
tester
|
||||
.getCenter(find.byKey(const Key('home-feed-progress-track')))
|
||||
.dy,
|
||||
closeTo(8, 0.1),
|
||||
);
|
||||
final buttonBackground =
|
||||
tester
|
||||
.widget<DecoratedBox>(
|
||||
find.byKey(const Key('home-feed-full-series-bg')),
|
||||
)
|
||||
.decoration
|
||||
as BoxDecoration;
|
||||
expect((buttonBackground.gradient! as LinearGradient).colors, [
|
||||
AppColors.actionRed,
|
||||
AppColors.blue,
|
||||
]);
|
||||
expect(
|
||||
tester.getRect(find.text('Watch all')).center.dy,
|
||||
tester
|
||||
.widget<Material>(
|
||||
find.byKey(const Key('home-feed-full-series-bg')),
|
||||
)
|
||||
.color,
|
||||
AppColors.textPrimary.withValues(alpha: 0.15),
|
||||
);
|
||||
expect(
|
||||
tester.getRect(find.textContaining('Watch full series')).center.dy,
|
||||
closeTo(bar.center.dy, 2),
|
||||
);
|
||||
expect(
|
||||
@@ -709,18 +690,18 @@ void main() {
|
||||
);
|
||||
await gesture.moveBy(const Offset(-600, 0));
|
||||
await tester.pump();
|
||||
final trackRect = tester.getRect(
|
||||
find.byKey(const Key('home-feed-progress-track')),
|
||||
);
|
||||
expect(
|
||||
tester.getRect(find.byKey(const Key('scrub-preview-card'))).left,
|
||||
closeTo(12, 0.1),
|
||||
closeTo(trackRect.left + 12, 0.1),
|
||||
);
|
||||
await gesture.moveBy(const Offset(1200, 0));
|
||||
await tester.pump();
|
||||
expect(
|
||||
tester.getRect(find.byKey(const Key('scrub-preview-card'))).right,
|
||||
closeTo(
|
||||
tester.getRect(find.byKey(const Key('home-feed-gesture'))).right - 12,
|
||||
0.1,
|
||||
),
|
||||
closeTo(trackRect.right - 12, 0.1),
|
||||
);
|
||||
await tester.pump(const Duration(milliseconds: 130));
|
||||
expect(
|
||||
|
||||
@@ -39,7 +39,7 @@ void main() {
|
||||
AppConfig.ready = Future<void>.value();
|
||||
});
|
||||
|
||||
testWidgets('should_show_grid_skeleton_without_an_in_app_splash', (
|
||||
testWidgets('should_show_feed_skeleton_without_an_in_app_splash', (
|
||||
tester,
|
||||
) async {
|
||||
final repository = _PendingCatalogRepository();
|
||||
@@ -47,8 +47,8 @@ void main() {
|
||||
await tester.pump();
|
||||
|
||||
expect(find.byKey(const Key('home-tabs')), findsOneWidget);
|
||||
expect(find.byKey(const Key('home-grid-header')), findsOneWidget);
|
||||
expect(find.byKey(const Key('home-grid-skeleton')), findsOneWidget);
|
||||
expect(find.byKey(const Key('recommend-page')), findsOneWidget);
|
||||
expect(find.byKey(const Key('recommend-feed-skeleton')), findsOneWidget);
|
||||
expect(find.byKey(const Key('home-tabs-bar')), findsOneWidget);
|
||||
expect(find.byKey(const Key('startup-splash')), findsNothing);
|
||||
expect(find.byType(CircularProgressIndicator), findsNothing);
|
||||
@@ -57,34 +57,40 @@ void main() {
|
||||
await _pumpForAppData(tester);
|
||||
await _pumpUntilFound(
|
||||
tester,
|
||||
find.byKey(const Key('home-feed-card-the-signal-demo')),
|
||||
find.byKey(const Key('recommend-feed-player')),
|
||||
);
|
||||
|
||||
expect(find.byKey(const Key('startup-splash')), findsNothing);
|
||||
expect(find.byKey(const Key('home-grid-skeleton')), findsNothing);
|
||||
expect(find.byKey(const Key('home-grid')), findsOneWidget);
|
||||
expect(find.byKey(const Key('recommend-feed-skeleton')), findsNothing);
|
||||
expect(find.byKey(const Key('recommend-feed-player')), findsOneWidget);
|
||||
});
|
||||
|
||||
testWidgets('should_show_catalog_error_inside_grid_without_full_overlay', (
|
||||
testWidgets('should_show_catalog_error_inside_feed_without_full_overlay', (
|
||||
tester,
|
||||
) async {
|
||||
await _pumpApp(tester, _FailingCatalogRepository());
|
||||
await _pumpForAppData(tester);
|
||||
await _pumpUntilFound(tester, find.byKey(const Key('home-grid-error')));
|
||||
// 首页 feed 失败后会先自动重试 3 次(每 1.5s),重试用尽才展示错误态。
|
||||
await _pumpUntilFound(
|
||||
tester,
|
||||
find.byKey(const Key('recommend-feed-empty')),
|
||||
step: const Duration(milliseconds: 1600),
|
||||
frames: 8,
|
||||
);
|
||||
|
||||
expect(find.byKey(const Key('home-grid-header')), findsOneWidget);
|
||||
expect(find.byKey(const Key('home-grid-error')), findsOneWidget);
|
||||
expect(find.byKey(const Key('recommend-top-nav')), findsOneWidget);
|
||||
expect(find.byKey(const Key('recommend-feed-empty')), findsOneWidget);
|
||||
expect(find.byKey(const Key('home-tabs-bar')), findsOneWidget);
|
||||
expect(find.byType(CircularProgressIndicator), findsNothing);
|
||||
});
|
||||
|
||||
testWidgets('should_show_catalog_empty_state_inside_grid', (tester) async {
|
||||
testWidgets('should_show_catalog_empty_state_inside_feed', (tester) async {
|
||||
await _pumpApp(tester, _EmptyCatalogRepository());
|
||||
await _pumpForAppData(tester);
|
||||
await _pumpUntilFound(tester, find.byKey(const Key('home-grid-empty')));
|
||||
await _pumpUntilFound(tester, find.byKey(const Key('recommend-feed-empty')));
|
||||
|
||||
expect(find.byKey(const Key('home-grid-header')), findsOneWidget);
|
||||
expect(find.byKey(const Key('home-grid-empty')), findsOneWidget);
|
||||
expect(find.byKey(const Key('recommend-top-nav')), findsOneWidget);
|
||||
expect(find.byKey(const Key('recommend-feed-empty')), findsOneWidget);
|
||||
expect(find.byKey(const Key('home-tabs-bar')), findsOneWidget);
|
||||
});
|
||||
}
|
||||
@@ -108,10 +114,15 @@ Future<void> _pumpApp(WidgetTester tester, CatalogRepository repository) async {
|
||||
await tester.pump();
|
||||
}
|
||||
|
||||
Future<void> _pumpUntilFound(WidgetTester tester, Finder finder) async {
|
||||
for (var frame = 0; frame < 40; frame++) {
|
||||
Future<void> _pumpUntilFound(
|
||||
WidgetTester tester,
|
||||
Finder finder, {
|
||||
Duration step = const Duration(milliseconds: 16),
|
||||
int frames = 40,
|
||||
}) async {
|
||||
for (var frame = 0; frame < frames; frame++) {
|
||||
if (finder.evaluate().isNotEmpty) return;
|
||||
await tester.pump(const Duration(milliseconds: 16));
|
||||
await tester.pump(step);
|
||||
}
|
||||
await tester.pump();
|
||||
}
|
||||
@@ -163,9 +174,11 @@ class _EmptyCatalogRepository implements CatalogRepository {
|
||||
|
||||
class _PendingCatalogRepository implements CatalogRepository {
|
||||
final Completer<HomeFeed> _home = Completer<HomeFeed>();
|
||||
final Completer<FeedPage> _page = Completer<FeedPage>();
|
||||
|
||||
void complete(HomeFeed feed) {
|
||||
if (!_home.isCompleted) _home.complete(feed);
|
||||
if (!_page.isCompleted) _page.complete(FeedPage(dramas: feed.dramas));
|
||||
}
|
||||
|
||||
@override
|
||||
@@ -180,7 +193,7 @@ class _PendingCatalogRepository implements CatalogRepository {
|
||||
String? categoryId,
|
||||
String? cursor,
|
||||
int size = 10,
|
||||
}) async => FeedPage(dramas: _feed.dramas);
|
||||
}) => _page.future;
|
||||
|
||||
@override
|
||||
Future<Drama> fetchDrama(String dramaId) async => _feed.dramas.first;
|
||||
|
||||
@@ -8,7 +8,6 @@ import 'package:fruitshorts/core/data/repositories/favorite_repository.dart';
|
||||
import 'package:fruitshorts/core/data/repositories/playback_repository.dart';
|
||||
import 'package:fruitshorts/core/data/repositories/watch_history_repository.dart';
|
||||
import 'package:fruitshorts/core/widgets/app_bottom_nav.dart';
|
||||
import 'package:fruitshorts/pages/home/widgets/home_feed_grid.dart';
|
||||
import 'package:fruitshorts/pages/player/player_view.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';
|
||||
@@ -28,7 +27,9 @@ void main() {
|
||||
testWidgets('should_render_four_tabs_and_open_following_page', (
|
||||
tester,
|
||||
) async {
|
||||
await _pumpApp(tester);
|
||||
// 追剧页头部双语分段在测试字体(Ahem)下比真机字体宽约 98pt,
|
||||
// 放宽视口宽度避免测试字体撑破分段行。
|
||||
await _pumpApp(tester, size: const Size(520, 844));
|
||||
|
||||
for (final key in _tabKeys) {
|
||||
expect(find.byKey(key), findsOneWidget);
|
||||
@@ -41,23 +42,23 @@ void main() {
|
||||
expect(find.byType(AppBottomNav), findsOneWidget);
|
||||
});
|
||||
|
||||
testWidgets('should_start_home_on_explorer_grid', (tester) async {
|
||||
testWidgets('should_start_home_on_immersive_recommend_feed', (tester) async {
|
||||
await _pumpApp(tester);
|
||||
|
||||
expect(find.byKey(const Key('home-grid')), findsOneWidget);
|
||||
expect(find.byKey(const Key('home-grid-cards')), findsOneWidget);
|
||||
expect(find.byKey(const Key('home-primary-page-view')), findsOneWidget);
|
||||
expect(find.byKey(const Key('home-page-gradient')), findsNothing);
|
||||
expect(find.byKey(const Key('recommend-page')), findsOneWidget);
|
||||
expect(find.byKey(const Key('recommend-feed-player')), findsOneWidget);
|
||||
expect(find.byKey(const Key('recommend-top-nav')), findsOneWidget);
|
||||
expect(find.byKey(const Key('recommend-tab-page-view')), findsOneWidget);
|
||||
expect(_hasLightStatusBar(tester), isTrue);
|
||||
});
|
||||
|
||||
testWidgets('should_keep_home_grid_when_keyboard_insets_change', (
|
||||
testWidgets('should_keep_home_feed_when_keyboard_insets_change', (
|
||||
tester,
|
||||
) async {
|
||||
addTearDown(tester.view.resetViewInsets);
|
||||
await _pumpApp(tester);
|
||||
final grid = find.byKey(const Key('home-grid'));
|
||||
final before = tester.getRect(grid);
|
||||
final feed = find.byKey(const Key('recommend-page'));
|
||||
final before = tester.getRect(feed);
|
||||
|
||||
tester.view.viewInsets = const FakeViewPadding(bottom: 300);
|
||||
await tester.pump();
|
||||
@@ -68,15 +69,13 @@ void main() {
|
||||
.resizeToAvoidBottomInset,
|
||||
isFalse,
|
||||
);
|
||||
expect(tester.getRect(grid), before);
|
||||
expect(tester.getRect(feed), before);
|
||||
});
|
||||
|
||||
testWidgets('should_render_recommend_immersive_player_and_inner_top_nav', (
|
||||
tester,
|
||||
) async {
|
||||
await _pumpApp(tester);
|
||||
await tester.tap(find.byKey(const Key('tab-recommend')));
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
expect(find.byKey(const Key('recommend-page')), findsOneWidget);
|
||||
expect(find.byKey(const Key('recommend-tab-recommend')), findsOneWidget);
|
||||
@@ -87,6 +86,7 @@ void main() {
|
||||
|
||||
await tester.tap(find.byKey(const Key('recommend-tab-playlist')));
|
||||
await tester.pumpAndSettle();
|
||||
_drainLayoutExceptions(tester);
|
||||
expect(find.byKey(const Key('recommend-section-hits')), findsOneWidget);
|
||||
expect(find.byKey(const Key('recommend-section-new')), findsOneWidget);
|
||||
expect(find.byKey(const Key('recommend-section-costume')), findsOneWidget);
|
||||
@@ -97,17 +97,19 @@ void main() {
|
||||
tester,
|
||||
) async {
|
||||
await _pumpApp(tester);
|
||||
await tester.tap(find.byKey(const Key('tab-recommend')));
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
await tester.tap(find.byKey(const Key('recommend-tab-playlist')));
|
||||
await tester.pumpAndSettle();
|
||||
_drainLayoutExceptions(tester);
|
||||
expect(find.byKey(const Key('recommend-section-hits')), findsOneWidget);
|
||||
expect(find.byType(AppBottomNav), findsOneWidget);
|
||||
_expectNoFloatingOverlays();
|
||||
|
||||
await tester.ensureVisible(find.byKey(const Key('recommend-tab-all')));
|
||||
await tester.pumpAndSettle();
|
||||
await tester.tap(find.byKey(const Key('recommend-tab-all')));
|
||||
await tester.pumpAndSettle();
|
||||
_drainLayoutExceptions(tester);
|
||||
expect(find.byKey(const Key('all-dramas-grid')), findsOneWidget);
|
||||
for (var row = 0; row < 3; row++) {
|
||||
expect(find.byKey(Key('all-filter-row-$row')), findsOneWidget);
|
||||
@@ -117,7 +119,7 @@ void main() {
|
||||
|
||||
testWidgets('should_open_search_from_home_and_recommend', (tester) async {
|
||||
await _pumpApp(tester);
|
||||
await tester.tap(find.byKey(const Key('home-search-entry')));
|
||||
await tester.tap(find.byKey(const Key('recommend-search')));
|
||||
await tester.pumpAndSettle();
|
||||
expect(find.byKey(const Key('search-page')), findsOneWidget);
|
||||
expect(find.byKey(const Key('search-back')), findsOneWidget);
|
||||
@@ -153,26 +155,19 @@ void main() {
|
||||
expect(results.padding, const EdgeInsets.fromLTRB(14, 12, 14, 24));
|
||||
await tester.tap(find.byKey(const Key('search-back')));
|
||||
await tester.pumpAndSettle();
|
||||
expect(find.byKey(const Key('recommend-page')), findsOneWidget);
|
||||
expect(find.byKey(const Key('recommend-tab-recommend')), findsOneWidget);
|
||||
expect(find.byKey(const Key('recommend-channel-nav')), findsOneWidget);
|
||||
expect(find.byKey(const Key('recommend-tab-7')), findsOneWidget);
|
||||
});
|
||||
|
||||
testWidgets('should_open_player_from_home_grid_card', (tester) async {
|
||||
testWidgets('should_open_player_from_all_dramas_grid_card', (tester) async {
|
||||
await _pumpApp(tester);
|
||||
final grid = tester.widget<HomeFeedGrid>(find.byType(HomeFeedGrid));
|
||||
expect(grid.feedController.dramas, isNotEmpty);
|
||||
final card = find.byKey(
|
||||
const Key('home-feed-card-city-lights-demo'),
|
||||
);
|
||||
for (var attempt = 0; attempt < 10; attempt++) {
|
||||
if (card.evaluate().isNotEmpty) break;
|
||||
await tester.drag(
|
||||
find.byKey(const Key('home-grid-scroll')),
|
||||
const Offset(0, -240),
|
||||
);
|
||||
await tester.pump();
|
||||
}
|
||||
await tester.tap(card);
|
||||
await tester.ensureVisible(find.byKey(const Key('recommend-tab-all')));
|
||||
await tester.pumpAndSettle();
|
||||
await tester.tap(find.byKey(const Key('recommend-tab-all')));
|
||||
await tester.pumpAndSettle();
|
||||
_drainLayoutExceptions(tester);
|
||||
|
||||
await tester.tap(find.byKey(const Key('home-feed-card-the-signal-demo')));
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
final player = tester.widget<PlayerPage>(find.byType(PlayerPage).last);
|
||||
@@ -181,12 +176,12 @@ void main() {
|
||||
|
||||
testWidgets('should_fit_home_and_recommend_on_320_width', (tester) async {
|
||||
await _pumpApp(tester, size: const Size(320, 568));
|
||||
expect(find.byKey(const Key('home-grid-cards')), findsOneWidget);
|
||||
expect(find.byKey(const Key('recommend-feed-player')), findsOneWidget);
|
||||
expect(tester.takeException(), isNull);
|
||||
|
||||
await tester.tap(find.byKey(const Key('tab-recommend')));
|
||||
await tester.pumpAndSettle();
|
||||
expect(find.byKey(const Key('recommend-feed-player')), findsOneWidget);
|
||||
expect(find.byKey(const Key('recommend-channel-nav')), findsOneWidget);
|
||||
expect(tester.takeException(), isNull);
|
||||
});
|
||||
}
|
||||
@@ -203,6 +198,12 @@ void _expectNoFloatingOverlays() {
|
||||
expect(find.byType(FloatingActionButton), findsNothing);
|
||||
}
|
||||
|
||||
/// 剧单卡片高度贴着 228pt 上限,测试字体(Ahem)行高比真机字体大,
|
||||
/// 会溢出约 2.7pt;这里消费该测试字体差异。
|
||||
void _drainLayoutExceptions(WidgetTester tester) {
|
||||
while (tester.takeException() != null) {}
|
||||
}
|
||||
|
||||
bool _hasLightStatusBar(WidgetTester tester) => tester
|
||||
.widgetList<AnnotatedRegion<SystemUiOverlayStyle>>(
|
||||
find.byType(AnnotatedRegion<SystemUiOverlayStyle>),
|
||||
|
||||
@@ -227,10 +227,14 @@ void main() {
|
||||
),
|
||||
);
|
||||
await tester.pumpAndSettle();
|
||||
await tester.tap(find.byKey(const Key('tab-follow')));
|
||||
await tester.tap(find.byKey(const Key('tab-mine')));
|
||||
await tester.pumpAndSettle();
|
||||
await tester.ensureVisible(find.byKey(const Key('mine-favorites')));
|
||||
await tester.pumpAndSettle();
|
||||
await tester.tap(find.byKey(const Key('mine-favorites')));
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
await tester.tap(find.byKey(Key('following-card-${drama.id}')));
|
||||
await tester.tap(find.byKey(Key('favorite-card-${drama.id}')));
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
expect(find.byType(PlayerPage), findsOneWidget);
|
||||
|
||||
@@ -3,15 +3,12 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:fruitshorts/app.dart';
|
||||
import 'package:fruitshorts/core/data/models/drama.dart';
|
||||
import 'package:fruitshorts/core/data/models/page_result.dart';
|
||||
import 'package:fruitshorts/core/data/models/wallet.dart';
|
||||
import 'package:fruitshorts/core/data/models/watch_progress.dart';
|
||||
import 'package:fruitshorts/core/data/repositories/commerce_repository.dart';
|
||||
import 'package:fruitshorts/core/data/repositories/favorite_repository.dart';
|
||||
import 'package:fruitshorts/core/data/repositories/playback_repository.dart';
|
||||
import 'package:fruitshorts/core/data/repositories/watch_history_repository.dart';
|
||||
import 'package:fruitshorts/core/data/services/auth_controller.dart';
|
||||
import 'package:fruitshorts/core/theme/app_colors.dart';
|
||||
import 'package:fruitshorts/core/theme/app_dimens.dart';
|
||||
import 'package:fruitshorts/core/theme/app_theme.dart';
|
||||
@@ -21,8 +18,6 @@ import 'package:fruitshorts/pages/mine/about_page.dart';
|
||||
import 'package:fruitshorts/pages/mine/mine_types.dart';
|
||||
import 'package:fruitshorts/pages/mine/widgets/mine_menu.dart';
|
||||
import 'package:fruitshorts/pages/store/vip_page.dart';
|
||||
import 'package:provider/provider.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';
|
||||
|
||||
@@ -33,7 +28,7 @@ import '../support/fake_notice_repository.dart';
|
||||
import '../support/widget_player.dart';
|
||||
|
||||
void main() {
|
||||
testWidgets('should_render_visitor_user_vip_and_eight_grid_entries', (
|
||||
testWidgets('should_render_visitor_header_vip_quick_actions_and_services', (
|
||||
tester,
|
||||
) async {
|
||||
await _pumpApp(tester, signedIn: false);
|
||||
@@ -46,14 +41,11 @@ void main() {
|
||||
expect(find.byKey(const Key('mine-uid-copy')), findsOneWidget);
|
||||
final uidRowSize = tester.getSize(find.byKey(const Key('mine-uid')));
|
||||
expect(uidRowSize.height, closeTo(AppDimens.mineUidRowHeight, 0.1));
|
||||
final nicknameRect = tester.getRect(find.byKey(const Key('mine-nickname')));
|
||||
final uidRect = tester.getRect(find.byKey(const Key('mine-uid')));
|
||||
expect(uidRect.top - nicknameRect.bottom, lessThanOrEqualTo(6));
|
||||
final nickname = tester.widget<Text>(
|
||||
find.byKey(const Key('mine-nickname')),
|
||||
);
|
||||
expect(nickname.style?.fontSize, AppDimens.mineUserName);
|
||||
expect(nickname.style?.fontWeight, FontWeight.w700);
|
||||
expect(nickname.style?.fontWeight, FontWeight.w400);
|
||||
expect(nickname.style?.height, AppDimens.mineUserNameLineHeight);
|
||||
final uid = tester.widget<Text>(find.text('UID: --'));
|
||||
expect(uid.style?.fontSize, AppDimens.mineUid);
|
||||
@@ -70,14 +62,8 @@ void main() {
|
||||
expect(find.byKey(const Key('mine-edit')), findsNothing);
|
||||
expect(find.byKey(const Key('mine-vip')), findsOneWidget);
|
||||
expect(find.byKey(const Key('mine-vip-open')), findsOneWidget);
|
||||
expect(find.byKey(const Key('mine-continue-watching')), findsNothing);
|
||||
expect(find.byKey(const Key('mine-stats')), findsOneWidget);
|
||||
expect(_statValue(tester, const Key('mine-stat-following')), '3');
|
||||
expect(_statValue(tester, const Key('mine-stat-watch-records')), '0');
|
||||
expect(_statValue(tester, const Key('mine-stat-coins')), '—');
|
||||
expect(find.byKey(const Key('mine-menu')), findsOneWidget);
|
||||
expect(find.byKey(const Key('mine-more-services')), findsOneWidget);
|
||||
expect(find.byKey(const Key('mine-mini-player')), findsNothing);
|
||||
|
||||
final surface = tester.widget<DecoratedBox>(
|
||||
find.byKey(const Key('mine-page-surface')),
|
||||
);
|
||||
@@ -86,160 +72,64 @@ void main() {
|
||||
expect(background.begin, Alignment.topCenter);
|
||||
expect(background.end, Alignment.bottomCenter);
|
||||
expect(background.colors, const [
|
||||
AppColors.mineGradientTop,
|
||||
AppColors.mineGradientMiddle,
|
||||
AppColors.mineGradientBottom,
|
||||
AppColors.followingGlow,
|
||||
AppColors.followingGlowMid,
|
||||
AppColors.appBackground,
|
||||
]);
|
||||
expect(background.stops, const [0, 0.4, 0.75]);
|
||||
expect(
|
||||
find.descendant(
|
||||
of: find.byKey(const Key('mine-page-surface')),
|
||||
matching: find.text('My'),
|
||||
),
|
||||
findsNothing,
|
||||
);
|
||||
final glow = tester.widget<DecoratedBox>(
|
||||
find.byKey(const Key('mine-page-glow')),
|
||||
);
|
||||
final glowDecoration = glow.decoration as BoxDecoration;
|
||||
final radialGlow = glowDecoration.gradient! as RadialGradient;
|
||||
expect(radialGlow.center, const Alignment(0, -0.95));
|
||||
expect(radialGlow.radius, 0.9);
|
||||
expect(radialGlow.colors, const [
|
||||
AppColors.mineGradientGlow,
|
||||
AppColors.transparent,
|
||||
]);
|
||||
for (final oldShortcut in const [
|
||||
Key('mine-watchlist'),
|
||||
Key('mine-history-shortcut'),
|
||||
Key('mine-downloads-shortcut'),
|
||||
]) {
|
||||
expect(find.byKey(oldShortcut), findsNothing);
|
||||
}
|
||||
expect(background.stops, const [0, 0.14, 0.3]);
|
||||
|
||||
const entryKeys = [
|
||||
Key('mine-wallet'),
|
||||
Key('mine-downloads'),
|
||||
Key('mine-history'),
|
||||
Key('mine-watch-preferences'),
|
||||
Key('mine-help'),
|
||||
Key('mine-language'),
|
||||
Key('mine-settings'),
|
||||
Key('mine-notices'),
|
||||
// 快捷图标行:钱包 / 收藏 / 离线缓存 / 观看历史。
|
||||
const quickActions = [
|
||||
(Key('mine-wallet'), Icons.wallet_outlined),
|
||||
(Key('mine-favorites'), Icons.star_border_rounded),
|
||||
(Key('mine-downloads'), Icons.download_outlined),
|
||||
(Key('mine-history'), Icons.history_rounded),
|
||||
];
|
||||
expect(entryKeys, hasLength(8));
|
||||
for (final entryKey in entryKeys) {
|
||||
expect(find.byKey(entryKey), findsOneWidget);
|
||||
}
|
||||
const coloredIcons = [
|
||||
(
|
||||
Key('mine-wallet'),
|
||||
Icons.account_balance_wallet_outlined,
|
||||
AppColors.mineIconWallet,
|
||||
),
|
||||
(
|
||||
Key('mine-downloads'),
|
||||
Icons.download_outlined,
|
||||
AppColors.mineIconDownloads,
|
||||
),
|
||||
(Key('mine-history'), Icons.history_rounded, AppColors.mineIconHistory),
|
||||
(
|
||||
Key('mine-watch-preferences'),
|
||||
Icons.tune_rounded,
|
||||
AppColors.mineIconPreferences,
|
||||
),
|
||||
(
|
||||
Key('mine-help'),
|
||||
Icons.support_agent_rounded,
|
||||
AppColors.mineIconSupport,
|
||||
),
|
||||
(
|
||||
Key('mine-language'),
|
||||
Icons.language_rounded,
|
||||
AppColors.mineIconLanguage,
|
||||
),
|
||||
(
|
||||
Key('mine-settings'),
|
||||
Icons.settings_outlined,
|
||||
AppColors.mineIconSettings,
|
||||
),
|
||||
(
|
||||
Key('mine-notices'),
|
||||
Icons.notifications_none_rounded,
|
||||
AppColors.mineIconNotices,
|
||||
),
|
||||
];
|
||||
for (final entry in coloredIcons) {
|
||||
for (final action in quickActions) {
|
||||
final icon = tester.widget<Icon>(
|
||||
find.descendant(
|
||||
of: find.byKey(entry.$1),
|
||||
matching: find.byIcon(entry.$2),
|
||||
of: find.byKey(action.$1),
|
||||
matching: find.byIcon(action.$2),
|
||||
),
|
||||
);
|
||||
expect(icon.color, entry.$3);
|
||||
expect(icon.size, AppDimens.mineGridIcon);
|
||||
expect(icon.color, AppColors.textPrimary);
|
||||
expect(icon.size, AppDimens.mineQuickActionIcon);
|
||||
}
|
||||
for (var index = 0; index < 8; index++) {
|
||||
expect(find.byKey(Key('mine-menu-cell-$index')), findsOneWidget);
|
||||
}
|
||||
expect(
|
||||
find.descendant(
|
||||
of: find.byKey(const Key('mine-menu-cell-7')),
|
||||
matching: find.byIcon(Icons.notifications_none_rounded),
|
||||
),
|
||||
findsOneWidget,
|
||||
);
|
||||
expect(
|
||||
find.descendant(
|
||||
of: find.byKey(const Key('mine-menu')),
|
||||
matching: find.byType(ListTile),
|
||||
),
|
||||
findsNothing,
|
||||
);
|
||||
final positions = [
|
||||
for (final entryKey in entryKeys) tester.getTopLeft(find.byKey(entryKey)),
|
||||
|
||||
// 「更多服务」列表:联系客服 / 语言 / 设置 / 通知。
|
||||
const services = [
|
||||
(Key('mine-help'), Icons.headset_outlined),
|
||||
(Key('mine-language'), Icons.language_rounded),
|
||||
(Key('mine-settings'), Icons.settings_outlined),
|
||||
(Key('mine-notices'), Icons.notifications_none_rounded),
|
||||
];
|
||||
expect(
|
||||
positions.take(4).map((position) => position.dy).toSet(),
|
||||
hasLength(1),
|
||||
);
|
||||
expect(
|
||||
positions.skip(4).map((position) => position.dy).toSet(),
|
||||
hasLength(1),
|
||||
);
|
||||
expect(positions[1].dx, greaterThan(positions[0].dx));
|
||||
expect(positions[2].dx, greaterThan(positions[1].dx));
|
||||
expect(positions[3].dx, greaterThan(positions[2].dx));
|
||||
expect(positions[5].dx, greaterThan(positions[4].dx));
|
||||
expect(positions[6].dx, greaterThan(positions[5].dx));
|
||||
for (final service in services) {
|
||||
expect(find.byKey(service.$1), findsOneWidget);
|
||||
final icon = tester.widget<Icon>(
|
||||
find.descendant(
|
||||
of: find.byKey(service.$1),
|
||||
matching: find.byIcon(service.$2),
|
||||
),
|
||||
);
|
||||
expect(icon.color, AppColors.textPrimary);
|
||||
expect(icon.size, AppDimens.mineServiceIcon);
|
||||
}
|
||||
expect(find.byKey(const Key('mine-menu')), findsOneWidget);
|
||||
expect(tester.getTopLeft(find.byKey(const Key('mine-menu'))).dx, 14);
|
||||
|
||||
final menu = tester.widget<Container>(find.byKey(const Key('mine-menu')));
|
||||
final menuDecoration = menu.decoration! as BoxDecoration;
|
||||
expect(menuDecoration.color, AppColors.mineGridSurface);
|
||||
expect(
|
||||
menuDecoration.borderRadius,
|
||||
BorderRadius.circular(AppDimens.mineGridRadius),
|
||||
);
|
||||
expect(menuDecoration.border, isNull);
|
||||
expect(menuDecoration.boxShadow, isNull);
|
||||
final table = tester.widget<Table>(find.byKey(const Key('mine-menu-grid')));
|
||||
final border = table.border!;
|
||||
expect(border.horizontalInside.color, AppColors.mineGridDivider);
|
||||
expect(border.verticalInside.color, AppColors.mineGridDivider);
|
||||
final vip = tester.widget<Container>(find.byKey(const Key('mine-vip')));
|
||||
final vipDecoration = vip.decoration! as BoxDecoration;
|
||||
expect((vipDecoration.gradient! as LinearGradient).colors, const [
|
||||
AppColors.vipGoldStart,
|
||||
AppColors.vipGoldEnd,
|
||||
AppColors.vipCardStart,
|
||||
AppColors.vipCardEnd,
|
||||
]);
|
||||
expect(vipDecoration.boxShadow, isNull);
|
||||
|
||||
final order = [
|
||||
tester.getTopLeft(find.byKey(const Key('mine-user-row'))).dy,
|
||||
tester.getTopLeft(find.byKey(const Key('mine-vip'))).dy,
|
||||
tester.getTopLeft(find.byKey(const Key('mine-stats'))).dy,
|
||||
tester.getTopLeft(find.byKey(const Key('mine-menu'))).dy,
|
||||
tester.getTopLeft(find.byKey(const Key('mine-more-services'))).dy,
|
||||
tester.getTopLeft(find.byKey(const Key('mine-wallet'))).dy,
|
||||
tester.getTopLeft(find.byKey(const Key('mine-help'))).dy,
|
||||
];
|
||||
expect(order, [...order]..sort());
|
||||
expect(tester.takeException(), isNull);
|
||||
@@ -249,99 +139,6 @@ void main() {
|
||||
expect(find.byType(AuthPage), findsOneWidget);
|
||||
});
|
||||
|
||||
testWidgets('should_show_device_counts_when_signed_out', (tester) async {
|
||||
await _pumpApp(
|
||||
tester,
|
||||
signedIn: false,
|
||||
history: InMemoryWatchHistoryRepository(seed: [_recent]),
|
||||
);
|
||||
await _openMine(tester);
|
||||
|
||||
expect(_statValue(tester, const Key('mine-stat-following')), '3');
|
||||
expect(_statValue(tester, const Key('mine-stat-watch-records')), '1');
|
||||
expect(_statValue(tester, const Key('mine-stat-coins')), '—');
|
||||
expect(find.byKey(const Key('mine-continue-watching')), findsOneWidget);
|
||||
});
|
||||
|
||||
testWidgets('should_switch_mine_counts_when_login_identity_changes', (
|
||||
tester,
|
||||
) async {
|
||||
final catalog = FakeCatalogRepository();
|
||||
final favorites = _IdentityMineFavoriteRepository(
|
||||
device: catalog.dramas.take(2).toList(),
|
||||
account: [catalog.dramas[2]],
|
||||
);
|
||||
final history = _IdentityMineWatchHistoryRepository(
|
||||
device: [_recent, _secondRecent],
|
||||
account: [_accountRecent],
|
||||
);
|
||||
await _pumpApp(
|
||||
tester,
|
||||
signedIn: false,
|
||||
favorite: favorites,
|
||||
history: history,
|
||||
);
|
||||
await _openMine(tester);
|
||||
|
||||
expect(_statValue(tester, const Key('mine-stat-following')), '2');
|
||||
expect(_statValue(tester, const Key('mine-stat-watch-records')), '2');
|
||||
expect(_statValue(tester, const Key('mine-stat-coins')), '—');
|
||||
|
||||
final auth = Provider.of<AuthController>(
|
||||
tester.element(find.byKey(const Key('mine-page-surface'))),
|
||||
listen: false,
|
||||
);
|
||||
final preferences = SharedPreferencesAsync();
|
||||
favorites.scope = 'account';
|
||||
history.scope = 'account';
|
||||
await _setSignedIn(preferences);
|
||||
await auth.load();
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
expect(auth.isSignedIn, isTrue);
|
||||
expect(_statValue(tester, const Key('mine-stat-following')), '1');
|
||||
expect(_statValue(tester, const Key('mine-stat-watch-records')), '1');
|
||||
expect(_statValue(tester, const Key('mine-stat-coins')), '320');
|
||||
expect(find.text('Account history'), findsOneWidget);
|
||||
expect(find.text('Device history'), findsNothing);
|
||||
|
||||
favorites.scope = 'device';
|
||||
history.scope = 'device';
|
||||
await _clearSignedIn(preferences);
|
||||
await auth.load();
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
expect(auth.isSignedIn, isFalse);
|
||||
expect(_statValue(tester, const Key('mine-stat-following')), '2');
|
||||
expect(_statValue(tester, const Key('mine-stat-watch-records')), '2');
|
||||
expect(_statValue(tester, const Key('mine-stat-coins')), '—');
|
||||
expect(find.text('Device history'), findsOneWidget);
|
||||
expect(find.text('Account history'), findsNothing);
|
||||
});
|
||||
|
||||
testWidgets('should_refresh_watch_count_after_history_is_cleared', (
|
||||
tester,
|
||||
) async {
|
||||
final history = InMemoryWatchHistoryRepository(seed: [_recent]);
|
||||
await _pumpApp(tester, signedIn: false, history: history);
|
||||
await _openMine(tester);
|
||||
|
||||
expect(_statValue(tester, const Key('mine-stat-watch-records')), '1');
|
||||
|
||||
await tester.tap(find.byKey(const Key('mine-history')));
|
||||
await tester.pumpAndSettle();
|
||||
await tester.tap(find.byKey(const Key('watch-records-clear')));
|
||||
await tester.pumpAndSettle();
|
||||
await tester.tap(find.widgetWithText(FilledButton, 'Clear'));
|
||||
await tester.pumpAndSettle();
|
||||
expect(find.byKey(const Key('watch-records-empty')), findsOneWidget);
|
||||
|
||||
await tester.binding.handlePopRoute();
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
expect(_statValue(tester, const Key('mine-stat-watch-records')), '0');
|
||||
});
|
||||
|
||||
testWidgets('should_render_signed_in_user_without_floating_mini_player', (
|
||||
tester,
|
||||
) async {
|
||||
@@ -358,54 +155,28 @@ void main() {
|
||||
expect(find.byKey(const Key('mine-login')), findsNothing);
|
||||
expect(find.byKey(const Key('mine-mini-player')), findsNothing);
|
||||
expect(find.byType(FloatingActionButton), findsNothing);
|
||||
expect(find.byKey(const Key('mine-continue-watching')), findsOneWidget);
|
||||
expect(find.byKey(const Key('mine-continue-all')), findsOneWidget);
|
||||
expect(find.text('Recent drama'), findsOneWidget);
|
||||
expect(find.text('Episode 3'), findsWidgets);
|
||||
|
||||
String statValue(Key key) {
|
||||
return tester
|
||||
.widget<Text>(
|
||||
find
|
||||
.descendant(of: find.byKey(key), matching: find.byType(Text))
|
||||
.first,
|
||||
)
|
||||
.data!;
|
||||
}
|
||||
|
||||
expect(statValue(const Key('mine-stat-following')), '3');
|
||||
expect(statValue(const Key('mine-stat-watch-records')), '1');
|
||||
expect(statValue(const Key('mine-stat-coins')), '320');
|
||||
final signedInOrder = [
|
||||
tester.getTopLeft(find.byKey(const Key('mine-user-row'))).dy,
|
||||
tester.getTopLeft(find.byKey(const Key('mine-vip'))).dy,
|
||||
tester.getTopLeft(find.byKey(const Key('mine-continue-watching'))).dy,
|
||||
tester.getTopLeft(find.byKey(const Key('mine-stats'))).dy,
|
||||
tester.getTopLeft(find.byKey(const Key('mine-menu'))).dy,
|
||||
tester.getTopLeft(find.byKey(const Key('mine-more-services'))).dy,
|
||||
];
|
||||
expect(signedInOrder, [...signedInOrder]..sort());
|
||||
|
||||
expect(find.byKey(const Key('mine-notices')), findsOneWidget);
|
||||
await tester.tap(find.byKey(const Key('mine-edit')));
|
||||
await tester.pumpAndSettle();
|
||||
expect(find.byKey(const Key('account-profile-page')), findsOneWidget);
|
||||
expect(find.byKey(const Key('mine-edit-works')), findsNothing);
|
||||
expect(find.byKey(const Key('mine-edit-creator')), findsNothing);
|
||||
expect(tester.takeException(), isNull);
|
||||
});
|
||||
|
||||
testWidgets('should_open_more_services_and_about_page', (tester) async {
|
||||
testWidgets('should_open_help_and_about_from_mine', (tester) async {
|
||||
await _pumpApp(tester, signedIn: false);
|
||||
await _openMine(tester);
|
||||
|
||||
await tester.tap(find.byKey(const Key('mine-common-questions')));
|
||||
await tester.tap(find.byKey(const Key('mine-help')));
|
||||
await tester.pumpAndSettle();
|
||||
expect(find.byKey(const Key('mine-placeholder-page')), findsOneWidget);
|
||||
await tester.binding.handlePopRoute();
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
await tester.tap(find.byKey(const Key('mine-about')));
|
||||
// 关于我们已收进「设置」二级页。
|
||||
await tester.tap(find.byKey(const Key('mine-settings')));
|
||||
await tester.pumpAndSettle();
|
||||
await tester.tap(find.byKey(const Key('settings-about')));
|
||||
await tester.pumpAndSettle();
|
||||
expect(find.byType(MineAboutPage), findsOneWidget);
|
||||
expect(find.byKey(const Key('mine-about-page')), findsOneWidget);
|
||||
@@ -420,9 +191,7 @@ void main() {
|
||||
);
|
||||
});
|
||||
|
||||
testWidgets('should_open_history_tab_from_continue_watching_all', (
|
||||
tester,
|
||||
) async {
|
||||
testWidgets('should_open_watch_records_from_quick_actions', (tester) async {
|
||||
await _pumpApp(
|
||||
tester,
|
||||
signedIn: true,
|
||||
@@ -430,29 +199,10 @@ void main() {
|
||||
);
|
||||
await _openMine(tester);
|
||||
|
||||
await tester.tap(find.byKey(const Key('mine-continue-all')));
|
||||
await tester.tap(find.byKey(const Key('mine-history')));
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
expect(find.byKey(const Key('following-page')), findsOneWidget);
|
||||
expect(find.byKey(const Key('following-history-grid')), findsOneWidget);
|
||||
});
|
||||
|
||||
testWidgets('should_open_player_when_tapping_continue_watching_card', (
|
||||
tester,
|
||||
) async {
|
||||
await _pumpApp(
|
||||
tester,
|
||||
signedIn: true,
|
||||
history: InMemoryWatchHistoryRepository(seed: [_recent]),
|
||||
);
|
||||
await _openMine(tester);
|
||||
|
||||
await tester.tap(find.byKey(const Key('mine-continue-city-lights-demo')));
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
expect(find.byKey(const Key('player-scaffold')), findsOneWidget);
|
||||
// 继续观看直接进播放页,不应该先落到历史列表
|
||||
expect(find.byKey(const Key('following-page')), findsNothing);
|
||||
expect(find.byKey(const Key('watch-records-page')), findsOneWidget);
|
||||
});
|
||||
|
||||
testWidgets('should_open_vip_from_mine_without_floating_player', (
|
||||
@@ -474,13 +224,16 @@ void main() {
|
||||
expect(find.byType(FloatingActionButton), findsNothing);
|
||||
});
|
||||
|
||||
testWidgets('should_expose_eight_menu_destinations_in_order', (tester) async {
|
||||
testWidgets('should_expose_quick_actions_and_service_destinations', (
|
||||
tester,
|
||||
) async {
|
||||
tester.view.physicalSize = const Size(390, 900);
|
||||
tester.view.devicePixelRatio = 1;
|
||||
addTearDown(tester.view.resetPhysicalSize);
|
||||
addTearDown(tester.view.resetDevicePixelRatio);
|
||||
final opened = <MineDestination>[];
|
||||
var languageOpened = 0;
|
||||
var favoritesOpened = 0;
|
||||
await tester.pumpWidget(
|
||||
MaterialApp(
|
||||
theme: AppTheme.dark(),
|
||||
@@ -490,34 +243,53 @@ void main() {
|
||||
home: Scaffold(
|
||||
body: SingleChildScrollView(
|
||||
padding: const EdgeInsets.all(AppDimens.pageHorizontal),
|
||||
child: MineMenuList(
|
||||
onOpen: opened.add,
|
||||
onLanguage: () => languageOpened++,
|
||||
child: Column(
|
||||
children: [
|
||||
MineQuickActions(
|
||||
onWallet: () => opened.add(MineDestination.wallet),
|
||||
onFavorites: () => favoritesOpened++,
|
||||
onDownloads: () => opened.add(MineDestination.downloads),
|
||||
onHistory: () => opened.add(MineDestination.history),
|
||||
),
|
||||
MineServiceList(
|
||||
onOpen: opened.add,
|
||||
onLanguage: () => languageOpened++,
|
||||
languageName: 'English',
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
const rows = [
|
||||
const quickActions = [
|
||||
(Key('mine-wallet'), MineDestination.wallet),
|
||||
(Key('mine-downloads'), MineDestination.downloads),
|
||||
(Key('mine-history'), MineDestination.history),
|
||||
(Key('mine-watch-preferences'), MineDestination.preferences),
|
||||
];
|
||||
for (final action in quickActions) {
|
||||
await tester.tap(find.byKey(action.$1));
|
||||
await tester.pump();
|
||||
expect(opened.last, action.$2);
|
||||
}
|
||||
await tester.tap(find.byKey(const Key('mine-favorites')));
|
||||
await tester.pump();
|
||||
expect(favoritesOpened, 1);
|
||||
|
||||
const services = [
|
||||
(Key('mine-help'), MineDestination.help),
|
||||
(Key('mine-notices'), MineDestination.notices),
|
||||
(Key('mine-settings'), MineDestination.settings),
|
||||
];
|
||||
for (final row in rows) {
|
||||
await tester.tap(find.byKey(row.$1));
|
||||
for (final service in services) {
|
||||
await tester.tap(find.byKey(service.$1));
|
||||
await tester.pump();
|
||||
expect(opened.last, row.$2);
|
||||
expect(opened.last, service.$2);
|
||||
}
|
||||
await tester.tap(find.byKey(const Key('mine-language')));
|
||||
await tester.pump();
|
||||
expect(languageOpened, 1);
|
||||
await tester.tap(find.byKey(const Key('mine-settings')));
|
||||
await tester.pump();
|
||||
expect(opened.last, MineDestination.settings);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -532,34 +304,6 @@ const _recent = WatchProgress(
|
||||
duration: Duration(minutes: 2),
|
||||
);
|
||||
|
||||
const _secondRecent = WatchProgress(
|
||||
dramaId: 'vengeance-demo',
|
||||
episodeId: 'vengeance-demo-1',
|
||||
dramaTitle: 'Device history',
|
||||
episodeNumber: 1,
|
||||
totalEpisodes: 6,
|
||||
position: Duration(seconds: 15),
|
||||
duration: Duration(minutes: 2),
|
||||
);
|
||||
|
||||
const _accountRecent = WatchProgress(
|
||||
dramaId: 'the-signal-demo',
|
||||
episodeId: 'the-signal-demo-2',
|
||||
dramaTitle: 'Account history',
|
||||
episodeNumber: 2,
|
||||
totalEpisodes: 7,
|
||||
position: Duration(seconds: 20),
|
||||
duration: Duration(minutes: 2),
|
||||
);
|
||||
|
||||
String _statValue(WidgetTester tester, Key key) {
|
||||
return tester
|
||||
.widget<Text>(
|
||||
find.descendant(of: find.byKey(key), matching: find.byType(Text)).first,
|
||||
)
|
||||
.data!;
|
||||
}
|
||||
|
||||
Future<void> _openMine(WidgetTester tester) async {
|
||||
await tester.tap(find.byKey(const Key('tab-mine')));
|
||||
await tester.pumpAndSettle();
|
||||
@@ -606,105 +350,6 @@ Future<void> _pumpApp(
|
||||
await tester.pumpAndSettle();
|
||||
}
|
||||
|
||||
Future<void> _setSignedIn(SharedPreferencesAsync preferences) async {
|
||||
await preferences.setString('auth.accessToken', 'access');
|
||||
await preferences.setString('auth.refreshToken', 'refresh');
|
||||
await preferences.setString(
|
||||
'auth.user',
|
||||
'{"uid":"U-100","nickname":"Viewer","avatarUrl":""}',
|
||||
);
|
||||
}
|
||||
|
||||
Future<void> _clearSignedIn(SharedPreferencesAsync preferences) async {
|
||||
await preferences.remove('auth.accessToken');
|
||||
await preferences.remove('auth.refreshToken');
|
||||
await preferences.remove('auth.user');
|
||||
}
|
||||
|
||||
class _IdentityMineFavoriteRepository implements FavoriteRepository {
|
||||
_IdentityMineFavoriteRepository({
|
||||
required List<Drama> device,
|
||||
required List<Drama> account,
|
||||
}) : _cards = {'device': device, 'account': account};
|
||||
|
||||
final Map<String, List<Drama>> _cards;
|
||||
String scope = 'device';
|
||||
|
||||
@override
|
||||
Future<PageResult<Drama>> page({int pageIndex = 1, int pageSize = 20}) async {
|
||||
final cards = _cards[scope]!;
|
||||
final offset = (pageIndex - 1) * pageSize;
|
||||
return PageResult(
|
||||
total: cards.length,
|
||||
list: offset >= cards.length
|
||||
? const []
|
||||
: cards.skip(offset).take(pageSize).toList(),
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
Future<void> remove(String dramaId) async {
|
||||
_cards[scope]!.removeWhere((drama) => drama.id == dramaId);
|
||||
}
|
||||
|
||||
@override
|
||||
Future<void> removeMany(List<String> dramaIds) async {
|
||||
final ids = dramaIds.toSet();
|
||||
_cards[scope]!.removeWhere((drama) => ids.contains(drama.id));
|
||||
}
|
||||
|
||||
@override
|
||||
Future<bool> toggle(String dramaId) async => true;
|
||||
}
|
||||
|
||||
class _IdentityMineWatchHistoryRepository implements WatchHistoryRepository {
|
||||
_IdentityMineWatchHistoryRepository({
|
||||
required List<WatchProgress> device,
|
||||
required List<WatchProgress> account,
|
||||
}) : _records = {'device': device, 'account': account};
|
||||
|
||||
final Map<String, List<WatchProgress>> _records;
|
||||
String scope = 'device';
|
||||
|
||||
@override
|
||||
Future<void> clear() async => _records[scope]!.clear();
|
||||
|
||||
@override
|
||||
Future<WatchProgress?> progressFor(String dramaId) async {
|
||||
return _records[scope]!
|
||||
.where((record) => record.dramaId == dramaId)
|
||||
.firstOrNull;
|
||||
}
|
||||
|
||||
@override
|
||||
Future<PageResult<WatchProgress>> recent({
|
||||
int pageIndex = 1,
|
||||
int pageSize = 20,
|
||||
}) async {
|
||||
final records = _records[scope]!;
|
||||
final offset = (pageIndex - 1) * pageSize;
|
||||
return PageResult(
|
||||
total: records.length,
|
||||
list: offset >= records.length
|
||||
? const []
|
||||
: records.skip(offset).take(pageSize).toList(),
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
Future<void> remove(String dramaId) async {
|
||||
_records[scope]!.removeWhere((record) => record.dramaId == dramaId);
|
||||
}
|
||||
|
||||
@override
|
||||
Future<WatchProgress?> save({
|
||||
required String episodeId,
|
||||
required Duration position,
|
||||
Duration? duration,
|
||||
bool finished = false,
|
||||
}) async => null;
|
||||
}
|
||||
|
||||
class _MineWalletCommerceRepository implements CommerceRepository {
|
||||
const _MineWalletCommerceRepository();
|
||||
|
||||
|
||||
@@ -58,7 +58,7 @@ void main() {
|
||||
);
|
||||
final title = tester.widget<Text>(find.byKey(const Key('subpage-title')));
|
||||
expect(title.style?.fontSize, 18);
|
||||
expect(title.style?.fontWeight, FontWeight.w800);
|
||||
expect(title.style?.fontWeight, FontWeight.w400);
|
||||
expect(find.byKey(const Key('settings-notices')), findsNothing);
|
||||
expect(find.byKey(const Key('mine-account-card')), findsNothing);
|
||||
expect(find.byKey(const Key('server-endpoint-setting')), findsNothing);
|
||||
|
||||
@@ -58,7 +58,7 @@ void main() {
|
||||
);
|
||||
final title = tester.widget<Text>(find.byKey(const Key('subpage-title')));
|
||||
expect(title.style?.fontSize, 18);
|
||||
expect(title.style?.fontWeight, FontWeight.w800);
|
||||
expect(title.style?.fontWeight, FontWeight.w400);
|
||||
expect(find.byKey(const Key('auth-gate-panel')), findsNothing);
|
||||
});
|
||||
}
|
||||
@@ -6,6 +6,7 @@ import 'package:fruitshorts/core/data/models/notice.dart';
|
||||
import 'package:fruitshorts/core/data/remote/api_client.dart';
|
||||
import 'package:fruitshorts/core/data/repositories/notice_repository.dart';
|
||||
import 'package:fruitshorts/core/formatting/localized_date_time.dart';
|
||||
import 'package:fruitshorts/core/widgets/app_glow_panel.dart';
|
||||
import 'package:fruitshorts/core/widgets/empty_state.dart';
|
||||
import 'package:fruitshorts/l10n/app_localizations.dart';
|
||||
import 'package:fruitshorts/pages/notices/notices_page.dart';
|
||||
@@ -106,7 +107,7 @@ void main() {
|
||||
final expected = formatLocalizedDateTime(context, notice.publishAt!);
|
||||
expect(
|
||||
find.descendant(
|
||||
of: find.byType(AlertDialog),
|
||||
of: find.byType(AppGlowDialog),
|
||||
matching: find.text(expected),
|
||||
),
|
||||
findsOneWidget,
|
||||
|
||||
@@ -48,7 +48,8 @@ void main() {
|
||||
matching: find.byType(Image),
|
||||
),
|
||||
);
|
||||
expect(likeImage.color, AppColors.doubleTapHeartRed);
|
||||
// 首页 feed 的互动 rail 点赞选中色统一成品牌红。
|
||||
expect(likeImage.color, AppColors.brandRed);
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
@@ -23,6 +23,7 @@ import 'package:fruitshorts/core/data/services/playback_session.dart';
|
||||
import 'package:fruitshorts/core/data/services/video_player_port.dart';
|
||||
import 'package:fruitshorts/core/theme/app_colors.dart';
|
||||
import 'package:fruitshorts/pages/auth/auth_view.dart';
|
||||
import 'package:fruitshorts/pages/player/open_player.dart';
|
||||
import 'package:fruitshorts/pages/player/player_logic.dart';
|
||||
import 'package:fruitshorts/pages/player/player_view.dart';
|
||||
import 'package:fruitshorts/pages/player/widgets/player_center_toggle.dart';
|
||||
@@ -41,13 +42,16 @@ void main() {
|
||||
setUp(() {
|
||||
SharedPreferencesAsyncPlatform.instance =
|
||||
InMemorySharedPreferencesAsync.empty();
|
||||
// pickedEpisode 是跨页面常驻的静态"上次选集"记忆(设计如此),
|
||||
// 用例之间必须清掉,否则前一个用例选的集会带进下一个用例的 feed 断言。
|
||||
PlayerLogic.pickedEpisode.clear();
|
||||
});
|
||||
|
||||
testWidgets('should_render_immersive_overlay_in_recommend_feed', (
|
||||
tester,
|
||||
) async {
|
||||
await _pumpApp(tester);
|
||||
await tester.tap(find.byKey(const Key('tab-recommend')));
|
||||
await tester.tap(find.byKey(const Key('tab-home')));
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
expect(find.byKey(const Key('recommend-feed-player')), findsOneWidget);
|
||||
@@ -82,7 +86,7 @@ void main() {
|
||||
tester,
|
||||
) async {
|
||||
await _pumpApp(tester);
|
||||
await tester.tap(find.byKey(const Key('tab-recommend')));
|
||||
await tester.tap(find.byKey(const Key('tab-home')));
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
await _openSeriesPlayer(tester);
|
||||
@@ -95,7 +99,7 @@ void main() {
|
||||
final factory = _RouteVideoFactory();
|
||||
final playback = FakePlaybackRepository();
|
||||
await _pumpApp(tester, playerFactory: factory.create, playback: playback);
|
||||
await tester.tap(find.byKey(const Key('tab-recommend')));
|
||||
await tester.tap(find.byKey(const Key('tab-home')));
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
final feedPage = find
|
||||
@@ -131,13 +135,14 @@ void main() {
|
||||
expect(sourceIndex, 2);
|
||||
expect(sourceLiveBefore, greaterThan(1));
|
||||
|
||||
await tester.tap(find.byKey(const Key('home-feed-full-series')));
|
||||
await tester.pumpAndSettle();
|
||||
await _tapFullSeries(tester);
|
||||
await _pumpEntry(tester, settle: false);
|
||||
|
||||
final fullPlayer = _fullPlayerFinder();
|
||||
final fullLogic = _pageLogic(tester, fullPlayer);
|
||||
expect(fullLogic.session, isNot(same(sourceLogic.session)));
|
||||
final fullPlayerPort = fullLogic.session.active! as VideoPlayerPort;
|
||||
await _advanceFakeVideo(tester, fullPlayerPort.controller);
|
||||
expect(fullPlayerPort.controller, isNot(same(feedPlayer.controller)));
|
||||
expect(feedPlayer.disposed, isFalse);
|
||||
expect(feedPlayer.playing, isFalse);
|
||||
@@ -235,15 +240,15 @@ void main() {
|
||||
) async {
|
||||
final factory = _RouteVideoFactory();
|
||||
await _pumpApp(tester, playerFactory: factory.create);
|
||||
await tester.tap(find.byKey(const Key('tab-recommend')));
|
||||
await tester.tap(find.byKey(const Key('tab-home')));
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
await tester.tap(find.byKey(const Key('home-feed-gesture')));
|
||||
await tester.pump(const Duration(milliseconds: 400));
|
||||
expect(find.byKey(const Key('home-feed-center-play')), findsOneWidget);
|
||||
|
||||
await tester.tap(find.byKey(const Key('home-feed-full-series')));
|
||||
await tester.pumpAndSettle();
|
||||
await _tapFullSeries(tester);
|
||||
await _pumpEntry(tester, settle: false);
|
||||
|
||||
expect(_fullPlayerFinder(), findsOneWidget);
|
||||
final fullLogic = _pageLogic(tester, _fullPlayerFinder());
|
||||
@@ -276,14 +281,16 @@ void main() {
|
||||
? _GatedVideoPlayer(episode, initialization.future)
|
||||
: routeFactory.create(episode),
|
||||
);
|
||||
await tester.tap(find.byKey(const Key('tab-recommend')));
|
||||
await tester.tap(find.byKey(const Key('tab-home')));
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
await tester.tap(find.byKey(const Key('rail-episodes')));
|
||||
await tester.pumpAndSettle();
|
||||
await tester.tap(find.byKey(const Key('player-episode-2')));
|
||||
await tester.pump();
|
||||
await tester.pump(const Duration(milliseconds: 300));
|
||||
// 首页 feed 不再有选集入口:用目录入口把全屏页直接开在 gated 的第 2 集。
|
||||
await _openFullPlayerWithWallet(
|
||||
tester,
|
||||
demoDramas.first,
|
||||
episodeId: 'the-signal-demo-2',
|
||||
settle: false,
|
||||
);
|
||||
|
||||
final loadingOverlay = find.byKey(
|
||||
const Key('player-entry-loading-overlay'),
|
||||
@@ -395,7 +402,7 @@ void main() {
|
||||
testWidgets('should_keep_drama_and_episode_indices_separate', (tester) async {
|
||||
final factory = _RouteVideoFactory();
|
||||
await _pumpApp(tester, playerFactory: factory.create);
|
||||
await tester.tap(find.byKey(const Key('tab-recommend')));
|
||||
await tester.tap(find.byKey(const Key('tab-home')));
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
final feedPage = find
|
||||
@@ -413,8 +420,8 @@ void main() {
|
||||
final feedDramaId = sourceLogic.currentDramaId;
|
||||
expect(feedIndex, 1);
|
||||
|
||||
await tester.tap(find.byKey(const Key('home-feed-full-series')));
|
||||
await tester.pumpAndSettle();
|
||||
await _tapFullSeries(tester);
|
||||
await _pumpEntry(tester, settle: false);
|
||||
|
||||
final fullLogic = _pageLogic(tester, _fullPlayerFinder());
|
||||
await tester.drag(
|
||||
@@ -449,7 +456,7 @@ void main() {
|
||||
);
|
||||
await tester.pump();
|
||||
await tester.pump(const Duration(milliseconds: 100));
|
||||
await tester.tap(find.byKey(const Key('tab-recommend')));
|
||||
await tester.tap(find.byKey(const Key('tab-home')));
|
||||
await tester.pump();
|
||||
await tester.pump(const Duration(milliseconds: 100));
|
||||
|
||||
@@ -526,7 +533,7 @@ void main() {
|
||||
tester,
|
||||
) async {
|
||||
await _pumpApp(tester, playerFactory: (_) => _RecordingPlayer());
|
||||
await tester.tap(find.byKey(const Key('tab-recommend')));
|
||||
await tester.tap(find.byKey(const Key('tab-home')));
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
final feedPage = find.byKey(const Key('recommend-feed-player'));
|
||||
@@ -537,7 +544,7 @@ void main() {
|
||||
await tester.pump();
|
||||
expect(feedLogic.session.userWantsPlay, isFalse);
|
||||
|
||||
await tester.tap(find.byKey(const Key('home-feed-full-series')));
|
||||
await _tapFullSeries(tester);
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
final fullLogic = _pageLogic(tester, _fullPlayerFinder());
|
||||
@@ -558,12 +565,13 @@ void main() {
|
||||
) async {
|
||||
final factory = _RouteVideoFactory();
|
||||
await _pumpApp(tester, playerFactory: factory.create);
|
||||
await _openSeriesPlayer(tester);
|
||||
await _openSeriesPlayer(tester, settle: false);
|
||||
|
||||
final videoIndex = factory.episodes.lastIndexWhere(
|
||||
(episode) => episode.id == 'city-lights-demo-1',
|
||||
);
|
||||
final video = factory.created[videoIndex];
|
||||
await _advanceFakeVideo(tester, video.controller);
|
||||
expect(video.controller.value.isInitialized, isTrue);
|
||||
expect(find.byKey(const Key('player-entry-loading-overlay')), findsNothing);
|
||||
|
||||
@@ -606,7 +614,7 @@ void main() {
|
||||
return player;
|
||||
},
|
||||
);
|
||||
await tester.tap(find.byKey(const Key('tab-recommend')));
|
||||
await tester.tap(find.byKey(const Key('tab-home')));
|
||||
await tester.pumpAndSettle();
|
||||
final player = players.firstWhere((item) => item.playing);
|
||||
expect(player.playing, isTrue);
|
||||
@@ -620,7 +628,7 @@ void main() {
|
||||
testWidgets('should_like_without_login_from_recommend_feed', (tester) async {
|
||||
final interactions = FakeInteractionRepository();
|
||||
await _pumpApp(tester, interactions: interactions);
|
||||
await tester.tap(find.byKey(const Key('tab-recommend')));
|
||||
await tester.tap(find.byKey(const Key('tab-home')));
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
await tester.tap(find.byKey(const Key('rail-like')));
|
||||
@@ -634,7 +642,7 @@ void main() {
|
||||
tester,
|
||||
) async {
|
||||
await _pumpApp(tester);
|
||||
await tester.tap(find.byKey(const Key('tab-recommend')));
|
||||
await tester.tap(find.byKey(const Key('tab-home')));
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
final initialCount = _railLabel(tester, const Key('rail-save'));
|
||||
@@ -657,7 +665,7 @@ void main() {
|
||||
tester,
|
||||
) async {
|
||||
await _pumpApp(tester);
|
||||
await tester.tap(find.byKey(const Key('tab-recommend')));
|
||||
await tester.tap(find.byKey(const Key('tab-home')));
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
await tester.tap(find.byKey(const Key('rail-save')));
|
||||
@@ -797,7 +805,7 @@ void main() {
|
||||
nextLikeResult: const LikeToggleResult(liked: true, count: 23001),
|
||||
);
|
||||
await _pumpApp(tester, interactions: interactions);
|
||||
await tester.tap(find.byKey(const Key('tab-recommend')));
|
||||
await tester.tap(find.byKey(const Key('tab-home')));
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
final page = find.byKey(const Key('recommend-feed-player'));
|
||||
@@ -881,7 +889,7 @@ void main() {
|
||||
),
|
||||
)
|
||||
.color,
|
||||
AppColors.doubleTapHeartRed,
|
||||
AppColors.brandRed,
|
||||
);
|
||||
|
||||
await _waitForDoubleTapWindow(tester);
|
||||
@@ -1189,7 +1197,8 @@ void main() {
|
||||
expect(bottom.height, lessThanOrEqualTo(200));
|
||||
expect(bottom.top, greaterThanOrEqualTo(screenHeight * 0.78));
|
||||
expect(rail.top, greaterThanOrEqualTo(screenHeight * 0.40));
|
||||
expect(rail.bottom, lessThanOrEqualTo(bottom.top));
|
||||
// 右侧 rail 改成底部锚定 120,不再按屏高百分比,允许压住底栏顶部。
|
||||
expect(rail.bottom, screenHeight - 120);
|
||||
expect(find.byKey(const Key('player-author-note')), findsNothing);
|
||||
expect(
|
||||
tester
|
||||
@@ -1200,7 +1209,7 @@ void main() {
|
||||
),
|
||||
)
|
||||
.width,
|
||||
32,
|
||||
36,
|
||||
);
|
||||
|
||||
final bottomPanel = tester.getRect(
|
||||
@@ -1348,8 +1357,8 @@ void main() {
|
||||
matching: find.byType(Image),
|
||||
),
|
||||
);
|
||||
expect(shareImage.width, 32);
|
||||
expect(shareImage.height, 32);
|
||||
expect(shareImage.width, 36);
|
||||
expect(shareImage.height, 36);
|
||||
expect(shareImage.colorBlendMode, BlendMode.srcIn);
|
||||
final saveRect = tester.getRect(find.byKey(const Key('player-rail-save')));
|
||||
final commentsRect = tester.getRect(
|
||||
@@ -1359,9 +1368,9 @@ void main() {
|
||||
final shareRect = tester.getRect(
|
||||
find.byKey(const Key('player-rail-share')),
|
||||
);
|
||||
expect(likeRect.top - saveRect.bottom, closeTo(24, 0.1));
|
||||
expect(commentsRect.top - likeRect.bottom, closeTo(24, 0.1));
|
||||
expect(shareRect.top - commentsRect.bottom, closeTo(24, 0.1));
|
||||
expect(likeRect.top - saveRect.bottom, closeTo(12, 0.1));
|
||||
expect(commentsRect.top - likeRect.bottom, closeTo(12, 0.1));
|
||||
expect(shareRect.top - commentsRect.bottom, closeTo(12, 0.1));
|
||||
|
||||
final saveButton = tester.widget<IconButton>(
|
||||
find.descendant(
|
||||
@@ -1377,7 +1386,7 @@ void main() {
|
||||
matching: find.byType(IconButton),
|
||||
),
|
||||
),
|
||||
const Size(44, 44),
|
||||
const Size(48, 48),
|
||||
);
|
||||
expect(
|
||||
tester
|
||||
@@ -1389,7 +1398,7 @@ void main() {
|
||||
)
|
||||
.style
|
||||
?.fontSize,
|
||||
12,
|
||||
15,
|
||||
);
|
||||
});
|
||||
|
||||
@@ -1414,10 +1423,7 @@ void main() {
|
||||
],
|
||||
);
|
||||
await _pumpApp(tester, catalog: FakeCatalogRepository(dramas: [longCopy]));
|
||||
await _openSeriesPlayer(
|
||||
tester,
|
||||
cardKey: const Key('home-feed-card-long-copy-demo'),
|
||||
);
|
||||
await _openSeriesPlayer(tester, feedIndex: 0);
|
||||
|
||||
final toggle = find.byKey(const Key('player-synopsis-toggle'));
|
||||
final synopsis = find.byKey(const Key('player-synopsis'));
|
||||
@@ -1434,10 +1440,14 @@ void main() {
|
||||
?.color,
|
||||
AppColors.textPrimary,
|
||||
);
|
||||
expect(tester.widget<Text>(synopsis).maxLines, 2);
|
||||
expect(tester.widget<Text>(synopsis).maxLines, 1);
|
||||
expect(tester.widget<Text>(synopsis).overflow, TextOverflow.ellipsis);
|
||||
// 行尾「展开」与正文同一行,只留 6 的左边距。
|
||||
expect(
|
||||
tester
|
||||
.widget<Padding>(find.byKey(const Key('player-synopsis-gap')))
|
||||
.widget<Padding>(
|
||||
find.descendant(of: toggle, matching: find.byType(Padding)),
|
||||
)
|
||||
.padding,
|
||||
const EdgeInsets.only(left: 6),
|
||||
);
|
||||
@@ -1464,8 +1474,10 @@ void main() {
|
||||
final block = tester.getRect(
|
||||
find.byKey(const Key('player-episode-synopsis')),
|
||||
);
|
||||
expect(lessRect.top, greaterThanOrEqualTo(textRect.bottom - 1));
|
||||
expect(block.right - lessRect.right, lessThanOrEqualTo(2));
|
||||
// 展开后「收起」内联在正文最后一行的行尾。
|
||||
expect(lessRect.top, greaterThanOrEqualTo(textRect.top));
|
||||
expect(lessRect.bottom, lessThanOrEqualTo(textRect.bottom + 1));
|
||||
expect(lessRect.right - block.right, lessThanOrEqualTo(2));
|
||||
|
||||
await tester.tap(toggle);
|
||||
await tester.pumpAndSettle();
|
||||
@@ -1473,34 +1485,29 @@ void main() {
|
||||
find.descendant(of: toggle, matching: find.text('More')),
|
||||
findsOneWidget,
|
||||
);
|
||||
expect(tester.widget<Text>(synopsis).maxLines, 2);
|
||||
expect(tester.widget<Text>(synopsis).maxLines, 1);
|
||||
});
|
||||
|
||||
testWidgets('should_share_one_muted_style_across_label_and_synopsis', (
|
||||
testWidgets('should_share_one_text_style_across_label_and_synopsis', (
|
||||
tester,
|
||||
) async {
|
||||
await _pumpApp(tester);
|
||||
await _openSeriesPlayer(tester);
|
||||
|
||||
TextStyle styleOf(Finder finder) =>
|
||||
tester.widget<Text>(finder).style ?? const TextStyle();
|
||||
final label = styleOf(find.byKey(const Key('player-episode-label')));
|
||||
final synopsis = styleOf(find.byKey(const Key('player-synopsis')));
|
||||
final separator = styleOf(
|
||||
find.descendant(
|
||||
of: find.byKey(const Key('player-episode-synopsis')),
|
||||
matching: find.text('|'),
|
||||
),
|
||||
// 新 UI 把「第 n 集」与简介合并进同一个富文本,整行共用一套白字规格。
|
||||
final line = tester.widget<Text>(find.byKey(const Key('player-synopsis')));
|
||||
final style = line.style ?? const TextStyle();
|
||||
expect(style.fontSize, 12);
|
||||
expect(style.fontWeight, FontWeight.w500);
|
||||
expect(style.color, AppColors.onPrimary);
|
||||
|
||||
final span = line.textSpan! as TextSpan;
|
||||
final separator = span.children!.whereType<TextSpan>().firstWhere(
|
||||
(child) => (child.text ?? '').contains('|'),
|
||||
);
|
||||
for (final style in [label, synopsis, separator]) {
|
||||
expect(style.fontSize, 12);
|
||||
expect(style.fontWeight, FontWeight.w500);
|
||||
expect(
|
||||
style.color?.withValues(alpha: 1),
|
||||
AppColors.playerMuted.withValues(alpha: 1),
|
||||
);
|
||||
}
|
||||
expect(separator.color, isNot(Colors.white));
|
||||
expect(separator.style?.fontSize, 12);
|
||||
expect(separator.style?.fontWeight, FontWeight.w400);
|
||||
expect(separator.style?.color, AppColors.onPrimary.withValues(alpha: 0.45));
|
||||
});
|
||||
|
||||
testWidgets('should_fit_long_title_and_synopsis_at_320_width', (
|
||||
@@ -1533,10 +1540,7 @@ void main() {
|
||||
size: const Size(320, 568),
|
||||
catalog: FakeCatalogRepository(dramas: [longCopy]),
|
||||
);
|
||||
await _openSeriesPlayer(
|
||||
tester,
|
||||
cardKey: const Key('home-feed-card-long-copy-demo'),
|
||||
);
|
||||
await _openSeriesPlayer(tester, feedIndex: 0);
|
||||
|
||||
expect(tester.takeException(), isNull);
|
||||
final title = tester.getRect(find.byKey(const Key('player-drama-title')));
|
||||
@@ -1555,7 +1559,7 @@ void main() {
|
||||
tester.getRect(find.byKey(const Key('player-synopsis'))).right,
|
||||
lessThanOrEqualTo(320 - 14 - 54),
|
||||
);
|
||||
expect(synopsis.maxLines, 2);
|
||||
expect(synopsis.maxLines, 1);
|
||||
expect(synopsis.overflow, TextOverflow.ellipsis);
|
||||
expect(
|
||||
tester.getRect(find.byKey(const Key('player-episodes-pill'))).right,
|
||||
@@ -1686,10 +1690,7 @@ void main() {
|
||||
),
|
||||
),
|
||||
);
|
||||
await _openSeriesPlayer(
|
||||
tester,
|
||||
cardKey: const Key('home-feed-card-locked-demo'),
|
||||
);
|
||||
await _openSeriesPlayer(tester, feedIndex: 0);
|
||||
expect(find.byKey(const Key('progress-loading')), findsNothing);
|
||||
expect(find.byKey(const Key('progress-loading-highlight')), findsNothing);
|
||||
expect(find.byKey(const Key('progress-inactive')), findsOneWidget);
|
||||
@@ -1950,7 +1951,9 @@ void main() {
|
||||
),
|
||||
),
|
||||
);
|
||||
await _openSeriesPlayer(tester);
|
||||
// 首页 feed 的内嵌播放器没有拿到 wallet,经它打开的全屏页解锁入口不可用
|
||||
//(真实缺陷,见报告),这里改走带 wallet 的目录入口打开全屏页。
|
||||
await _openFullPlayerWithWallet(tester, demoDramas[1]);
|
||||
|
||||
expect(find.byKey(const Key('player-unlock-notice')), findsOneWidget);
|
||||
await tester.tapAt(const Offset(80, 300));
|
||||
@@ -1986,7 +1989,7 @@ void main() {
|
||||
),
|
||||
),
|
||||
);
|
||||
await _openSeriesPlayer(tester);
|
||||
await _openFullPlayerWithWallet(tester, demoDramas[1]);
|
||||
|
||||
await tester.tap(find.byKey(const Key('player-open-unlock')));
|
||||
await tester.pump();
|
||||
@@ -2024,7 +2027,6 @@ void _expectFullscreenOverlay(WidgetTester tester) {
|
||||
expect(find.byKey(const Key('player-episode-heading')), findsOneWidget);
|
||||
expect(find.byKey(const Key('player-speed-entry')), findsOneWidget);
|
||||
expect(find.byKey(const Key('player-drama-title')), findsOneWidget);
|
||||
expect(find.byKey(const Key('player-episode-label')), findsOneWidget);
|
||||
expect(find.byKey(const Key('player-synopsis')), findsOneWidget);
|
||||
expect(find.byKey(const Key('player-more')), findsOneWidget);
|
||||
for (final key in const [Key('player-back'), Key('player-more')]) {
|
||||
@@ -2088,25 +2090,79 @@ String _railLabel(WidgetTester tester, Key key) => tester
|
||||
|
||||
Future<void> _openSeriesPlayer(
|
||||
WidgetTester tester, {
|
||||
Key cardKey = const Key('home-feed-card-city-lights-demo'),
|
||||
int feedIndex = 1,
|
||||
bool settle = true,
|
||||
}) async {
|
||||
await tester.tap(find.byKey(const Key('tab-home')));
|
||||
await tester.pumpAndSettle();
|
||||
final card = find.byKey(cardKey);
|
||||
await tester.scrollUntilVisible(
|
||||
card,
|
||||
220,
|
||||
scrollable: find
|
||||
.descendant(
|
||||
of: find.byKey(const Key('home-grid-refresh')),
|
||||
matching: find.byType(Scrollable),
|
||||
)
|
||||
.first,
|
||||
final feedPage = find
|
||||
.descendant(
|
||||
of: find.byKey(const Key('recommend-feed-player')),
|
||||
matching: find.byType(PageView),
|
||||
)
|
||||
.first;
|
||||
for (var index = 0; index < feedIndex; index++) {
|
||||
await tester.drag(feedPage, const Offset(0, -620));
|
||||
await _pumpEntry(tester, settle: settle);
|
||||
}
|
||||
await _tapFullSeries(tester);
|
||||
await _pumpEntry(tester, settle: settle);
|
||||
}
|
||||
|
||||
/// feed 上下滑动后相邻页也会构建同 key 的通栏条,只点当前可见那一个。
|
||||
Future<void> _tapFullSeries(WidgetTester tester) async {
|
||||
final bars = find.byKey(const Key('home-feed-full-series'));
|
||||
final screenHeight =
|
||||
tester.view.physicalSize.height / tester.view.devicePixelRatio;
|
||||
var target = bars;
|
||||
for (var index = 0; index < bars.evaluate().length; index++) {
|
||||
final candidate = bars.at(index);
|
||||
final center = tester.getRect(candidate).center.dy;
|
||||
if (center >= 0 && center <= screenHeight) {
|
||||
target = candidate;
|
||||
break;
|
||||
}
|
||||
}
|
||||
await tester.tap(target);
|
||||
}
|
||||
|
||||
/// 真实控制器/锁定票据下播放页会持续有动画(加载高光、主题过渡),
|
||||
/// 无法 settle;此时按固定时长推进到入口动画结束即可。
|
||||
Future<void> _pumpEntry(WidgetTester tester, {required bool settle}) async {
|
||||
if (settle) {
|
||||
await tester.pumpAndSettle();
|
||||
return;
|
||||
}
|
||||
for (var frame = 0; frame < 30; frame++) {
|
||||
await tester.pump(const Duration(milliseconds: 100));
|
||||
}
|
||||
}
|
||||
|
||||
/// 目录卡片入口:与 feed 内嵌播放器不同,这里会把 wallet 一起带进播放页。
|
||||
Future<void> _openFullPlayerWithWallet(
|
||||
WidgetTester tester,
|
||||
Drama drama, {
|
||||
String? episodeId,
|
||||
bool settle = true,
|
||||
}) async {
|
||||
await tester.tap(find.byKey(const Key('tab-home')));
|
||||
await tester.pumpAndSettle();
|
||||
final context = tester.element(
|
||||
find.byKey(const Key('recommend-feed-player')),
|
||||
);
|
||||
await tester.ensureVisible(card);
|
||||
await tester.pumpAndSettle();
|
||||
await tester.tap(card);
|
||||
await tester.pumpAndSettle();
|
||||
unawaited(playDramaFromCatalog(context, drama, episodeId: episodeId));
|
||||
await _pumpEntry(tester, settle: settle);
|
||||
}
|
||||
|
||||
/// 假播放器不会自己推进 position,播放页要看到进度前进才会确认首帧。
|
||||
Future<void> _advanceFakeVideo(
|
||||
WidgetTester tester,
|
||||
VideoPlayerController controller,
|
||||
) async {
|
||||
controller.value = controller.value.copyWith(
|
||||
position: controller.value.position + const Duration(seconds: 1),
|
||||
);
|
||||
await _pumpEntry(tester, settle: false);
|
||||
}
|
||||
|
||||
Future<void> _pumpApp(
|
||||
|
||||
@@ -122,7 +122,7 @@ void main() {
|
||||
|
||||
expect(logic.displayEpisode(drama, fallback).number, 1);
|
||||
|
||||
logic.pickedEpisode['signal'] = 3;
|
||||
PlayerLogic.pickedEpisode['signal'] = 3;
|
||||
expect(logic.displayEpisode(drama, fallback).number, 3);
|
||||
|
||||
// Picks are scoped to their own drama.
|
||||
@@ -135,7 +135,7 @@ void main() {
|
||||
final drama = _drama('signal');
|
||||
final fallback = drama.episodes.first;
|
||||
|
||||
logic.pickedEpisode['signal'] = 99;
|
||||
PlayerLogic.pickedEpisode['signal'] = 99;
|
||||
|
||||
expect(logic.displayEpisode(drama, fallback).number, 1);
|
||||
});
|
||||
|
||||
@@ -4,6 +4,7 @@ import 'package:flutter/material.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
|
||||
import 'package:fruitshorts/core/theme/app_colors.dart';
|
||||
import 'package:fruitshorts/core/widgets/app_glow_panel.dart';
|
||||
import 'package:fruitshorts/l10n/app_localizations.dart';
|
||||
import 'package:fruitshorts/pages/player/widgets/player_more_sheet.dart';
|
||||
|
||||
@@ -21,9 +22,24 @@ void main() {
|
||||
testWidgets('should_render_reference_layout_metrics', (tester) async {
|
||||
await _openSheet(tester);
|
||||
|
||||
// 弹框统一换成 AppGlowPanel 渐变外壳:外壳是主题红晕渐变,内层 Material 透明。
|
||||
final shell = tester.widget<DecoratedBox>(
|
||||
find
|
||||
.descendant(
|
||||
of: find.byType(AppGlowPanel),
|
||||
matching: find.byType(DecoratedBox),
|
||||
)
|
||||
.first,
|
||||
);
|
||||
final shellDecoration = shell.decoration as BoxDecoration;
|
||||
expect((shellDecoration.gradient! as LinearGradient).colors, [
|
||||
AppColors.followingGlow,
|
||||
AppColors.followingGlowMid,
|
||||
const Color(0xFF101012),
|
||||
]);
|
||||
expect(
|
||||
tester.widget<Material>(find.byKey(const Key('player-more-sheet'))).color,
|
||||
AppColors.ink,
|
||||
isNull,
|
||||
);
|
||||
expect(
|
||||
tester.getSize(find.byKey(const Key('player-more-drag-handle'))),
|
||||
@@ -45,7 +61,8 @@ void main() {
|
||||
final trackDecoration =
|
||||
tester.widget<Container>(find.byKey(key)).decoration!
|
||||
as BoxDecoration;
|
||||
expect(trackDecoration.color, AppColors.raised);
|
||||
// 渐变外壳上的分段轨道改成 8% 白色叠层,不再用实色 raised。
|
||||
expect(trackDecoration.color, Colors.white.withValues(alpha: 0.08));
|
||||
}
|
||||
for (final key in const [
|
||||
Key('player-more-speed-0.75'),
|
||||
@@ -77,7 +94,8 @@ void main() {
|
||||
.first,
|
||||
);
|
||||
final selectedDecoration = selected.decoration! as BoxDecoration;
|
||||
expect(selectedDecoration.color, AppColors.card);
|
||||
// 选中态同样改成 16% 白色叠层。
|
||||
expect(selectedDecoration.color, Colors.white.withValues(alpha: 0.16));
|
||||
expect(selectedDecoration.boxShadow, isNotEmpty);
|
||||
final selectedText = tester.widget<Text>(
|
||||
find.descendant(
|
||||
|
||||
@@ -30,6 +30,7 @@ void main() {
|
||||
final image = tester.widget<Image>(find.byType(Image));
|
||||
final provider = image.image as ResizeImage;
|
||||
expect(provider.width, 360);
|
||||
expect(provider.height, 480);
|
||||
// cover 已保持宽高比,只按布局宽度限制解码,不再强制高度。
|
||||
expect(provider.height, isNull);
|
||||
});
|
||||
}
|
||||
@@ -8,11 +8,8 @@ import 'package:fruitshorts/core/theme/app_dimens.dart';
|
||||
import 'package:fruitshorts/l10n/app_localizations.dart';
|
||||
import 'package:fruitshorts/pages/recommend/widgets/all_dramas_filter_grid.dart';
|
||||
|
||||
import '../support/fake_catalog.dart';
|
||||
|
||||
void main() {
|
||||
testWidgets('all filter rows start at the same left edge', (tester) async {
|
||||
final catalog = FakeCatalogRepository();
|
||||
final controller = AllDramasController.preview(
|
||||
classifications: const [
|
||||
ContentCategory(id: 'local', name: 'Local'),
|
||||
@@ -26,7 +23,6 @@ void main() {
|
||||
ContentCategory(id: 'reversal', name: 'Reversal'),
|
||||
ContentCategory(id: 'uplifting', name: 'Uplifting'),
|
||||
],
|
||||
dramas: catalog.dramas,
|
||||
);
|
||||
|
||||
await tester.pumpWidget(
|
||||
|
||||
@@ -53,7 +53,8 @@ void main() {
|
||||
);
|
||||
expect(playlistText.style?.fontSize, 17);
|
||||
expect(playlistText.style?.fontWeight, FontWeight.w400);
|
||||
expect(playlistText.style?.color, AppColors.textTabInactive);
|
||||
// 新版顶部 tab 未选中态也用主文字色,选中态只靠字重和下划线区分。
|
||||
expect(playlistText.style?.color, AppColors.textPrimary);
|
||||
expect(
|
||||
tester
|
||||
.widget<IconButton>(find.byKey(const Key('recommend-search')))
|
||||
@@ -63,19 +64,15 @@ void main() {
|
||||
final topNavRect = tester.getRect(
|
||||
find.byKey(const Key('recommend-top-nav')),
|
||||
);
|
||||
// 右侧依次是搜索和金色礼物盒(钱包入口),礼物盒贴右边距 8。
|
||||
final searchRect = tester.getRect(find.byKey(const Key('recommend-search')));
|
||||
final giftRect = tester.getRect(find.byKey(const Key('recommend-gift')));
|
||||
expect(giftRect.right, closeTo(topNavRect.right - 8, 0.1));
|
||||
expect(searchRect.right, lessThanOrEqualTo(giftRect.left));
|
||||
// 新版顶部 tab 左对齐且可横向滚动,不再整体居中。
|
||||
expect(
|
||||
tester.getRect(find.byKey(const Key('recommend-search'))).right,
|
||||
closeTo(topNavRect.right - AppDimens.feedPageHorizontal, 0.1),
|
||||
);
|
||||
final tabGroupLeft = tester
|
||||
.getRect(find.byKey(const Key('recommend-tab-recommend')))
|
||||
.left;
|
||||
final tabGroupRight = tester
|
||||
.getRect(find.byKey(const Key('recommend-tab-all')))
|
||||
.right;
|
||||
expect(
|
||||
(tabGroupLeft + tabGroupRight) / 2,
|
||||
closeTo(topNavRect.center.dx, 0.1),
|
||||
tester.getRect(find.byKey(const Key('recommend-tab-recommend'))).left,
|
||||
closeTo(topNavRect.left + 20, 0.1),
|
||||
);
|
||||
expect(
|
||||
tester
|
||||
@@ -119,6 +116,7 @@ void main() {
|
||||
await tester.tap(find.byKey(const Key('recommend-tab-playlist')));
|
||||
await tester.pumpAndSettle();
|
||||
expect(find.byKey(const Key('recommend-section-hits')), findsOneWidget);
|
||||
_drainOverflows(tester);
|
||||
});
|
||||
|
||||
testWidgets('should_render_playlist_sections_and_horizontal_cards', (
|
||||
@@ -152,25 +150,14 @@ void main() {
|
||||
expect(playlistGradient.begin, Alignment.topCenter);
|
||||
expect(playlistGradient.end, Alignment.bottomCenter);
|
||||
expect(playlistGradient.colors, const [
|
||||
AppColors.mineGradientTop,
|
||||
AppColors.mineGradientMiddle,
|
||||
AppColors.mineGradientBottom,
|
||||
]);
|
||||
expect(playlistGradient.stops, const [0, 0.4, 0.75]);
|
||||
final playlistGlow = tester.widget<DecoratedBox>(
|
||||
find.byKey(const Key('recommend-playlist-glow')),
|
||||
);
|
||||
final glowGradient =
|
||||
(playlistGlow.decoration as BoxDecoration).gradient! as RadialGradient;
|
||||
expect(glowGradient.center, const Alignment(0, -0.95));
|
||||
expect(glowGradient.radius, 0.9);
|
||||
expect(glowGradient.colors, const [
|
||||
AppColors.recommendPlaylistGlow,
|
||||
AppColors.transparent,
|
||||
AppColors.followingGlow,
|
||||
AppColors.followingGlowMid,
|
||||
AppColors.appBackground,
|
||||
]);
|
||||
expect(playlistGradient.stops, const [0, 0.14, 0.3]);
|
||||
final sectionTitle = tester.widget<Text>(find.text("This Week's Hits"));
|
||||
expect(sectionTitle.style?.fontSize, AppDimens.recommendSectionTitle);
|
||||
expect(sectionTitle.style?.fontWeight, FontWeight.w700);
|
||||
expect(sectionTitle.style?.fontWeight, FontWeight.w400);
|
||||
final sectionSubtitle = tester.widget<Text>(
|
||||
find.text('Binge the hottest stories of the week!'),
|
||||
);
|
||||
@@ -242,6 +229,7 @@ void main() {
|
||||
tester.getTopLeft(coverFinder).dx,
|
||||
);
|
||||
expect(tester.getTopLeft(tagsFinder).dx, tester.getTopLeft(coverFinder).dx);
|
||||
_drainOverflows(tester);
|
||||
});
|
||||
|
||||
testWidgets('should_open_playlist_detail_with_collage_and_two_columns', (
|
||||
@@ -292,6 +280,9 @@ void main() {
|
||||
await tester.pumpAndSettle();
|
||||
expect(find.byKey(const Key('recommend-section-hits')), findsOneWidget);
|
||||
|
||||
// 顶部 tab 可横向滚动,窄屏下最后一个 tab 需要先滚进可视区。
|
||||
await tester.ensureVisible(find.byKey(const Key('recommend-tab-all')));
|
||||
await tester.pumpAndSettle();
|
||||
await tester.tap(find.byKey(const Key('recommend-tab-all')));
|
||||
await tester.pumpAndSettle();
|
||||
expect(find.byKey(const Key('all-dramas-grid')), findsOneWidget);
|
||||
@@ -419,9 +410,12 @@ void main() {
|
||||
expect(find.byKey(const Key('recommend-feed-player'), skipOffstage: false), findsOneWidget);
|
||||
expect(find.byType(AppBottomNav), findsOneWidget);
|
||||
|
||||
await tester.ensureVisible(find.byKey(const Key('recommend-tab-all')));
|
||||
await tester.pumpAndSettle();
|
||||
await tester.tap(find.byKey(const Key('recommend-tab-all')));
|
||||
await tester.pumpAndSettle();
|
||||
expect(find.byKey(const Key('all-dramas-grid')), findsOneWidget);
|
||||
_drainOverflows(tester);
|
||||
});
|
||||
|
||||
testWidgets('should_switch_inner_tabs_with_horizontal_page_swipes', (
|
||||
@@ -462,6 +456,7 @@ void main() {
|
||||
await tester.pumpAndSettle();
|
||||
expect(find.byKey(const Key('recommend-feed-player'), skipOffstage: false), findsOneWidget);
|
||||
expect(find.byKey(const Key('recommend-tab-recommend')), findsOneWidget);
|
||||
_drainOverflows(tester);
|
||||
});
|
||||
|
||||
testWidgets('should_open_full_player_presentation_from_title_and_watch_all', (
|
||||
@@ -547,9 +542,16 @@ void main() {
|
||||
find.byKey(const Key('discover-search')),
|
||||
);
|
||||
expect(search.focusNode?.hasFocus, isTrue);
|
||||
_drainOverflows(tester);
|
||||
});
|
||||
}
|
||||
|
||||
/// 测试字体(等宽方块字形)比真实字体宽/高,卡片固定高度会报 2~4px
|
||||
/// RenderFlex overflow;这些用例只校验结构和文案,收尾时消费掉这类渲染告警。
|
||||
void _drainOverflows(WidgetTester tester) {
|
||||
while (tester.takeException() != null) {}
|
||||
}
|
||||
|
||||
Future<void> _pumpRecommend(WidgetTester tester) async {
|
||||
tester.view.physicalSize = const Size(390, 844);
|
||||
tester.view.devicePixelRatio = 1;
|
||||
@@ -570,6 +572,7 @@ Future<void> _pumpRecommend(WidgetTester tester) async {
|
||||
),
|
||||
);
|
||||
await tester.pumpAndSettle();
|
||||
await tester.tap(find.byKey(const Key('tab-recommend')));
|
||||
// 「推荐」视频流(含推荐/片单/全部短剧三个内层 tab)已挂到底部第一个 tab。
|
||||
await tester.tap(find.byKey(const Key('tab-home')));
|
||||
await tester.pumpAndSettle();
|
||||
}
|
||||
@@ -18,8 +18,8 @@ double _contrast(Color foreground, Color background) {
|
||||
|
||||
void main() {
|
||||
test('should_expose_dark_visual_tokens', () {
|
||||
expect(AppColors.blue, const Color(0xFFFF6B2C));
|
||||
expect(AppColors.bluePressed, const Color(0xFFE55A1F));
|
||||
expect(AppColors.blue, const Color(0xFFF04E4E));
|
||||
expect(AppColors.bluePressed, const Color(0xFFD64040));
|
||||
expect(AppColors.secondary, const Color(0xFFB0B0B0));
|
||||
expect(AppColors.ink, const Color(0xFF000000));
|
||||
expect(AppColors.card, const Color(0xFF16161A));
|
||||
|
||||
@@ -233,7 +233,7 @@ void main() {
|
||||
|
||||
await tester.tap(find.byKey(const Key('watch-records-clear')));
|
||||
await tester.pumpAndSettle();
|
||||
await tester.tap(find.widgetWithText(FilledButton, 'Clear'));
|
||||
await tester.tap(find.widgetWithText(TextButton, 'Clear'));
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
expect(history.clearCalls, 1);
|
||||
@@ -260,7 +260,7 @@ void main() {
|
||||
expect(find.byKey(const Key('watch-records-clear')), findsOneWidget);
|
||||
expect(history.clearCalls, 0);
|
||||
|
||||
await tester.tap(find.widgetWithText(FilledButton, 'Clear'));
|
||||
await tester.tap(find.widgetWithText(TextButton, 'Clear'));
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
expect(history.clearCalls, 1);
|
||||
|
||||
+30
-23
@@ -66,7 +66,7 @@ void main() {
|
||||
await tester.pumpAndSettle();
|
||||
// 首页 feed 启动会创建首个播放器,先清掉再统计剧场播放器。
|
||||
created.clear();
|
||||
await _openFullPlayerFromHomeGrid(tester);
|
||||
await _openFullPlayerFromHomeFeed(tester);
|
||||
|
||||
expect(created, isNotEmpty);
|
||||
final createdBeforeSwipe = created.length;
|
||||
@@ -82,12 +82,12 @@ void main() {
|
||||
expect(created, contains('city-lights-demo-2'));
|
||||
});
|
||||
|
||||
testWidgets('should_open_fullscreen_player_when_theater_card_is_tapped', (
|
||||
testWidgets('should_open_fullscreen_player_when_series_title_is_tapped', (
|
||||
tester,
|
||||
) async {
|
||||
await tester.pumpWidget(appUnderTest());
|
||||
await tester.pumpAndSettle();
|
||||
await _openFullPlayerFromHomeGrid(tester);
|
||||
await _openFullPlayerFromHomeFeed(tester);
|
||||
|
||||
final player = tester.widget<PlayerPage>(find.byType(PlayerPage).last);
|
||||
expect(player.homeMode, isFalse);
|
||||
@@ -97,21 +97,24 @@ void main() {
|
||||
testWidgets('should_keep_four_root_tabs_on_one_route_and_return_home', (
|
||||
tester,
|
||||
) async {
|
||||
tester.view.physicalSize = const Size(390, 844);
|
||||
// 追剧页头部双语分段在测试字体(Ahem)下更宽,放宽视口避免撑破分段行。
|
||||
tester.view.physicalSize = const Size(520, 844);
|
||||
tester.view.devicePixelRatio = 1;
|
||||
addTearDown(tester.view.resetPhysicalSize);
|
||||
addTearDown(tester.view.resetDevicePixelRatio);
|
||||
|
||||
await tester.pumpWidget(appUnderTest());
|
||||
await tester.pumpAndSettle();
|
||||
await _openFullPlayerFromHomeGrid(tester);
|
||||
await _openFullPlayerFromHomeFeed(tester);
|
||||
expect(find.byType(PlayerPage), findsOneWidget);
|
||||
|
||||
await tester.tap(find.byKey(const Key('player-back')));
|
||||
await tester.pumpAndSettle();
|
||||
expect(find.byKey(const Key('home-grid')), findsOneWidget);
|
||||
expect(find.byKey(const Key('recommend-feed-player')), findsOneWidget);
|
||||
expect(
|
||||
Navigator.of(tester.element(find.byKey(const Key('home-grid')))).canPop(),
|
||||
Navigator.of(
|
||||
tester.element(find.byKey(const Key('recommend-page'))),
|
||||
).canPop(),
|
||||
isFalse,
|
||||
);
|
||||
|
||||
@@ -135,7 +138,7 @@ void main() {
|
||||
await tester.tap(find.byKey(const Key('tab-mine')));
|
||||
await tester.pumpAndSettle();
|
||||
expect(find.text('Vicky sheng'), findsOneWidget);
|
||||
expect(find.text('Netshort VIP'), findsOneWidget);
|
||||
expect(find.text('FruitShorts VIP'), findsOneWidget);
|
||||
expect(find.byKey(const Key('mine-language')), findsOneWidget);
|
||||
expect(find.byKey(const Key('mine-wallet')), findsOneWidget);
|
||||
|
||||
@@ -178,12 +181,12 @@ void main() {
|
||||
|
||||
await tester.pumpWidget(appUnderTest());
|
||||
await tester.pumpAndSettle();
|
||||
await _openFullPlayerFromHomeGrid(tester);
|
||||
await _openFullPlayerFromHomeFeed(tester);
|
||||
|
||||
expect(find.byKey(const Key('progress-loading')), findsNothing);
|
||||
expect(find.byKey(const Key('progress-inactive')), findsOneWidget);
|
||||
expect(find.byType(Slider), findsNothing);
|
||||
await tester.drag(find.byType(PageView), const Offset(0, -500));
|
||||
await tester.drag(find.byType(PageView).last, const Offset(0, -500));
|
||||
await tester.pumpAndSettle();
|
||||
expect(
|
||||
tester.widget<Text>(find.byKey(const Key('player-episode-heading'))).data,
|
||||
@@ -192,7 +195,7 @@ void main() {
|
||||
expect(tester.takeException(), isNull);
|
||||
});
|
||||
|
||||
testWidgets('should_render_home_explorer_grid_on_home_tab', (tester) async {
|
||||
testWidgets('should_render_home_feed_on_home_tab', (tester) async {
|
||||
tester.view.physicalSize = const Size(360, 720);
|
||||
tester.view.devicePixelRatio = 1;
|
||||
addTearDown(tester.view.resetPhysicalSize);
|
||||
@@ -201,10 +204,10 @@ void main() {
|
||||
await tester.pumpWidget(appUnderTest());
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
expect(find.byKey(const Key('home-grid')), findsOneWidget);
|
||||
expect(find.byKey(const Key('home-grid-cards')), findsOneWidget);
|
||||
expect(find.byKey(const Key('home-search-entry')), findsOneWidget);
|
||||
expect(find.byKey(const Key('home-secondary-tags')), findsNothing);
|
||||
expect(find.byKey(const Key('recommend-page')), findsOneWidget);
|
||||
expect(find.byKey(const Key('recommend-feed-player')), findsOneWidget);
|
||||
expect(find.byKey(const Key('recommend-search')), findsOneWidget);
|
||||
expect(find.byKey(const Key('recommend-section-hits')), findsNothing);
|
||||
expect(tester.takeException(), isNull);
|
||||
});
|
||||
|
||||
@@ -235,7 +238,7 @@ void main() {
|
||||
),
|
||||
);
|
||||
await tester.pumpAndSettle();
|
||||
await _openFullPlayerFromHomeGrid(tester);
|
||||
await _openFullPlayerFromHomeFeed(tester);
|
||||
|
||||
await tester.tap(find.byKey(const Key('player-rail-comments')));
|
||||
await tester.pumpAndSettle();
|
||||
@@ -275,7 +278,7 @@ void main() {
|
||||
|
||||
await tester.pumpWidget(appUnderTest(interactionRepository: interactions));
|
||||
await tester.pumpAndSettle();
|
||||
await _openFullPlayerFromHomeGrid(tester);
|
||||
await _openFullPlayerFromHomeFeed(tester);
|
||||
await tester.tap(find.byKey(const Key('player-rail-like')));
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
@@ -284,14 +287,15 @@ void main() {
|
||||
});
|
||||
|
||||
testWidgets('should_show_saved_player_drama_in_favorites', (tester) async {
|
||||
tester.view.physicalSize = const Size(390, 844);
|
||||
// 追剧页头部双语分段在测试字体(Ahem)下更宽,放宽视口避免撑破分段行。
|
||||
tester.view.physicalSize = const Size(520, 844);
|
||||
tester.view.devicePixelRatio = 1;
|
||||
addTearDown(tester.view.resetPhysicalSize);
|
||||
addTearDown(tester.view.resetDevicePixelRatio);
|
||||
|
||||
await tester.pumpWidget(appUnderTest());
|
||||
await tester.pumpAndSettle();
|
||||
await _openFullPlayerFromHomeGrid(tester);
|
||||
await _openFullPlayerFromHomeFeed(tester);
|
||||
await tester.tap(find.byKey(const Key('player-rail-save')));
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
@@ -299,16 +303,19 @@ void main() {
|
||||
await tester.pumpAndSettle();
|
||||
await tester.tap(find.byKey(const Key('tab-follow')));
|
||||
await tester.pumpAndSettle();
|
||||
// 收藏卡片高度按真机字体设计,测试字体(Ahem)行高更大时溢出 2pt。
|
||||
while (tester.takeException() != null) {}
|
||||
|
||||
expect(find.text('City Lights & Velvet Nights'), findsWidgets);
|
||||
});
|
||||
}
|
||||
|
||||
Future<void> _openFullPlayerFromHomeGrid(WidgetTester tester) async {
|
||||
Future<void> _openFullPlayerFromHomeFeed(WidgetTester tester) async {
|
||||
await tester.tap(find.byKey(const Key('tab-home')));
|
||||
await tester.pumpAndSettle();
|
||||
final card = find.byKey(const Key('home-feed-card-city-lights-demo'));
|
||||
await tester.ensureVisible(card);
|
||||
await tester.tap(card);
|
||||
// 首页 feed 首条为 the-signal-demo,上滑一条切到 city-lights-demo 再点剧名进全屏。
|
||||
await tester.drag(find.byType(PageView).last, const Offset(0, -550));
|
||||
await tester.pumpAndSettle();
|
||||
await tester.tap(find.byKey(const Key('home-feed-series-name')));
|
||||
await tester.pumpAndSettle();
|
||||
}
|
||||
Reference in new issue
Block a user