feat(mine): 重排我的页并新增迷你播放器
This commit is contained in:
1 parent
5aa8170951
commit
cbc6d80cd4
21 files changed
+860
-531
No files matched your search
@@ -3,160 +3,73 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:fruitshorts/app.dart';
|
||||
import 'package:fruitshorts/core/data/models/watch_progress.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_colors.dart';
|
||||
import 'package:fruitshorts/core/theme/app_dimens.dart';
|
||||
import 'package:fruitshorts/core/theme/app_theme.dart';
|
||||
import 'package:fruitshorts/l10n/app_localizations.dart';
|
||||
import 'package:fruitshorts/pages/auth/auth_view.dart';
|
||||
import 'package:fruitshorts/pages/mine/mine_types.dart';
|
||||
import 'package:fruitshorts/pages/mine/widgets/mine_menu.dart';
|
||||
import 'package:fruitshorts/pages/player/player_view.dart';
|
||||
import 'package:fruitshorts/pages/store/vip_page.dart';
|
||||
import 'package:shared_preferences_platform_interface/in_memory_shared_preferences_async.dart';
|
||||
import 'package:shared_preferences_platform_interface/shared_preferences_async_platform_interface.dart';
|
||||
|
||||
import '../support/fake_catalog.dart';
|
||||
import '../support/fake_category.dart';
|
||||
import '../support/fake_haptics.dart';
|
||||
import '../support/fake_interaction_repositories.dart';
|
||||
import '../support/fake_notice_repository.dart';
|
||||
import '../support/widget_player.dart';
|
||||
|
||||
void main() {
|
||||
testWidgets('should_render_minimal_profile_shortcuts_wallet_vip_and_menu', (
|
||||
testWidgets('should_render_visitor_user_vip_and_seven_menu_rows', (
|
||||
tester,
|
||||
) async {
|
||||
SharedPreferencesAsyncPlatform.instance =
|
||||
InMemorySharedPreferencesAsync.empty();
|
||||
tester.view.physicalSize = const Size(390, 844);
|
||||
tester.view.devicePixelRatio = 1;
|
||||
addTearDown(tester.view.resetPhysicalSize);
|
||||
addTearDown(tester.view.resetDevicePixelRatio);
|
||||
|
||||
final catalog = FakeCatalogRepository();
|
||||
await tester.pumpWidget(
|
||||
LumaDramaApp(
|
||||
playerFactory: createWidgetPlayer,
|
||||
catalogRepository: catalog,
|
||||
categoryRepository: FakeCategoryRepository(catalog: catalog),
|
||||
watchHistoryRepository: InMemoryWatchHistoryRepository(),
|
||||
favoriteRepository: InMemoryFavoriteRepository(cards: catalog.dramas),
|
||||
playbackRepository: FakePlaybackRepository(),
|
||||
commentRepository: FakeCommentRepository(),
|
||||
interactionRepository: FakeInteractionRepository(),
|
||||
noticeRepository: FakeNoticeRepository(),
|
||||
haptics: FakeHaptics(),
|
||||
),
|
||||
);
|
||||
await tester.pumpAndSettle();
|
||||
await tester.tap(find.byKey(const Key('tab-mine')));
|
||||
await tester.pumpAndSettle();
|
||||
await _pumpApp(tester, signedIn: false);
|
||||
await _openMine(tester);
|
||||
|
||||
expect(find.byKey(const Key('mine-user-row')), findsOneWidget);
|
||||
expect(find.byKey(const Key('mine-continue-watching')), findsNothing);
|
||||
for (final key in const [
|
||||
expect(find.byKey(const Key('mine-avatar')), findsOneWidget);
|
||||
expect(find.text('Visitor'), findsOneWidget);
|
||||
expect(find.text('UID: --'), findsOneWidget);
|
||||
expect(find.byKey(const Key('mine-uid-copy')), findsOneWidget);
|
||||
expect(find.byKey(const Key('mine-login')), findsOneWidget);
|
||||
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-menu')), findsOneWidget);
|
||||
expect(find.byKey(const Key('mine-mini-player')), findsNothing);
|
||||
for (final oldShortcut in const [
|
||||
Key('mine-watchlist'),
|
||||
Key('mine-history'),
|
||||
Key('mine-history-shortcut'),
|
||||
Key('mine-downloads-shortcut'),
|
||||
]) {
|
||||
expect(find.byKey(oldShortcut), findsNothing);
|
||||
}
|
||||
|
||||
final menuRows = tester.widgetList<ListTile>(
|
||||
find.descendant(
|
||||
of: find.byKey(const Key('mine-menu')),
|
||||
matching: find.byType(ListTile),
|
||||
),
|
||||
);
|
||||
expect(menuRows.map((row) => row.key), const [
|
||||
Key('mine-wallet'),
|
||||
Key('mine-downloads'),
|
||||
Key('mine-wallet'),
|
||||
Key('mine-wallet-recharge'),
|
||||
Key('mine-vip'),
|
||||
Key('mine-menu'),
|
||||
Key('mine-works'),
|
||||
Key('mine-creator-center'),
|
||||
Key('mine-notices'),
|
||||
Key('mine-settings'),
|
||||
Key('mine-language'),
|
||||
Key('mine-history'),
|
||||
Key('mine-watch-preferences'),
|
||||
Key('mine-help'),
|
||||
]) {
|
||||
expect(find.byKey(key), findsOneWidget);
|
||||
}
|
||||
expect(find.byKey(const Key('mine-language')), findsOneWidget);
|
||||
expect(find.byKey(const Key('mine-library-tab-0')), findsNothing);
|
||||
expect(find.byKey(const Key('mine-library-tab-1')), findsNothing);
|
||||
expect(find.byKey(const Key('mine-library-tab-2')), findsNothing);
|
||||
final surface = tester.widget<ColoredBox>(
|
||||
find.byKey(const Key('mine-page-surface')),
|
||||
);
|
||||
expect(surface.color, AppColors.appBackground);
|
||||
final title = tester.widget<Text>(
|
||||
find.descendant(
|
||||
of: find.byKey(const Key('mine-page-surface')),
|
||||
matching: find.text('My'),
|
||||
),
|
||||
);
|
||||
expect(title.style?.color, AppColors.textPrimary);
|
||||
expect(title.style?.fontSize, AppDimens.minePageTitle);
|
||||
expect(title.style?.fontWeight, FontWeight.w700);
|
||||
|
||||
for (final key in const [
|
||||
Key('mine-user-row'),
|
||||
Key('mine-wallet'),
|
||||
Key('mine-vip'),
|
||||
Key('mine-menu'),
|
||||
]) {
|
||||
final container = tester.widget<Container>(find.byKey(key));
|
||||
final decoration = container.decoration! as BoxDecoration;
|
||||
expect(decoration.color, AppColors.contentCard);
|
||||
expect(
|
||||
decoration.borderRadius,
|
||||
BorderRadius.circular(AppDimens.mineCardRadius),
|
||||
);
|
||||
expect(decoration.gradient, isNull);
|
||||
expect(decoration.boxShadow, isNull);
|
||||
expect((decoration.border! as Border).top.color, AppColors.contentBorder);
|
||||
}
|
||||
|
||||
final shortcutIcon = tester.widget<Icon>(
|
||||
find.descendant(
|
||||
of: find.byKey(const Key('mine-watchlist')),
|
||||
matching: find.byType(Icon),
|
||||
),
|
||||
);
|
||||
expect(shortcutIcon.size, 24);
|
||||
expect(shortcutIcon.color, AppColors.textPrimary);
|
||||
final shortcutKeys = [
|
||||
const Key('mine-watchlist'),
|
||||
const Key('mine-history'),
|
||||
const Key('mine-downloads'),
|
||||
];
|
||||
final shortcutWidths = shortcutKeys
|
||||
.map((key) => tester.getSize(find.byKey(key)).width)
|
||||
.toList();
|
||||
expect(shortcutWidths.toSet(), hasLength(1));
|
||||
final shortcutCard = tester.widget<Container>(
|
||||
find
|
||||
.descendant(
|
||||
of: find.byKey(const Key('mine-watchlist')),
|
||||
matching: find.byType(Container),
|
||||
)
|
||||
.first,
|
||||
);
|
||||
final shortcutDecoration = shortcutCard.decoration! as BoxDecoration;
|
||||
expect(shortcutDecoration.color, AppColors.contentCard);
|
||||
Key('mine-language'),
|
||||
Key('mine-settings'),
|
||||
]);
|
||||
expect(menuRows, hasLength(7));
|
||||
expect(
|
||||
shortcutDecoration.borderRadius,
|
||||
BorderRadius.circular(AppDimens.mineCardRadius),
|
||||
);
|
||||
expect(shortcutDecoration.boxShadow, isNull);
|
||||
final menuRows = find.descendant(
|
||||
of: find.byKey(const Key('mine-menu')),
|
||||
matching: find.byType(ListTile),
|
||||
);
|
||||
expect(menuRows, findsNWidgets(6));
|
||||
for (final row in tester.widgetList<ListTile>(menuRows)) {
|
||||
expect(row.minTileHeight, AppDimens.mineRowHeight);
|
||||
}
|
||||
final settingsRow = tester.widget<ListTile>(
|
||||
find.byKey(const Key('mine-settings')),
|
||||
);
|
||||
final settingsTitle = settingsRow.title! as Text;
|
||||
expect(settingsTitle.style?.color, AppColors.textPrimary);
|
||||
expect(settingsTitle.style?.fontSize, AppDimens.listTitle);
|
||||
expect((settingsRow.trailing! as Icon).color, AppColors.textSecondary);
|
||||
final recharge = tester.widget<TextButton>(
|
||||
find.byKey(const Key('mine-wallet-recharge')),
|
||||
);
|
||||
expect(recharge.style?.backgroundColor?.resolve(const {}), AppColors.blue);
|
||||
expect(
|
||||
tester.widget<Text>(find.text('Join VIP')).style?.color,
|
||||
AppColors.blue,
|
||||
menuRows.every((row) => row.minTileHeight == AppDimens.mineRowHeight),
|
||||
isTrue,
|
||||
);
|
||||
final dividers = tester.widgetList<Divider>(
|
||||
find.descendant(
|
||||
@@ -164,15 +77,186 @@ void main() {
|
||||
matching: find.byType(Divider),
|
||||
),
|
||||
);
|
||||
expect(dividers, hasLength(5));
|
||||
expect(dividers, hasLength(6));
|
||||
expect(
|
||||
dividers.every((divider) => divider.color == AppColors.contentSurface),
|
||||
isTrue,
|
||||
);
|
||||
|
||||
final menu = tester.widget<Container>(find.byKey(const Key('mine-menu')));
|
||||
final menuDecoration = menu.decoration! as BoxDecoration;
|
||||
expect(menuDecoration.color, AppColors.mineCard);
|
||||
expect(
|
||||
menuDecoration.borderRadius,
|
||||
BorderRadius.circular(AppDimens.mineCardRadius),
|
||||
);
|
||||
expect(menuDecoration.boxShadow, isNull);
|
||||
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,
|
||||
]);
|
||||
expect(vipDecoration.boxShadow, isNull);
|
||||
expect(tester.takeException(), isNull);
|
||||
|
||||
await tester.tap(find.byKey(const Key('mine-watchlist')));
|
||||
await tester.tap(find.byKey(const Key('mine-login')));
|
||||
await tester.pumpAndSettle();
|
||||
expect(find.byKey(const Key('favorites-page')), findsOneWidget);
|
||||
expect(find.byType(AuthPage), findsOneWidget);
|
||||
});
|
||||
|
||||
testWidgets('should_render_signed_in_user_and_dismiss_mini_player', (
|
||||
tester,
|
||||
) async {
|
||||
await _pumpApp(
|
||||
tester,
|
||||
signedIn: true,
|
||||
history: InMemoryWatchHistoryRepository(seed: [_recent]),
|
||||
);
|
||||
await _openMine(tester);
|
||||
|
||||
expect(find.text('Viewer'), findsOneWidget);
|
||||
expect(find.text('UID: U-100'), findsOneWidget);
|
||||
expect(find.byKey(const Key('mine-edit')), findsOneWidget);
|
||||
expect(find.byKey(const Key('mine-login')), findsNothing);
|
||||
expect(find.byKey(const Key('mine-mini-player')), findsOneWidget);
|
||||
expect(find.text('Recent drama'), findsOneWidget);
|
||||
expect(find.text('Episode 3'), findsOneWidget);
|
||||
expect(
|
||||
tester.getSize(find.byKey(const Key('mine-mini-player'))),
|
||||
const Size(AppDimens.mineMiniWidth, AppDimens.mineMiniHeight),
|
||||
);
|
||||
|
||||
await tester.tap(find.byKey(const Key('mine-mini-close')));
|
||||
await tester.pump();
|
||||
expect(find.byKey(const Key('mine-mini-player')), findsNothing);
|
||||
|
||||
await tester.tap(find.byKey(const Key('mine-edit')));
|
||||
await tester.pumpAndSettle();
|
||||
expect(find.byKey(const Key('mine-edit-profile')), findsOneWidget);
|
||||
expect(find.byKey(const Key('mine-edit-works')), findsOneWidget);
|
||||
expect(find.byKey(const Key('mine-edit-creator')), findsOneWidget);
|
||||
expect(find.byKey(const Key('mine-edit-notices')), findsOneWidget);
|
||||
await tester.tap(find.byKey(const Key('mine-edit-works')));
|
||||
await tester.pumpAndSettle();
|
||||
expect(find.byKey(const Key('mine-placeholder-page')), findsOneWidget);
|
||||
expect(tester.takeException(), isNull);
|
||||
});
|
||||
|
||||
testWidgets('should_open_vip_and_recent_player_from_mine_entries', (
|
||||
tester,
|
||||
) async {
|
||||
await _pumpApp(
|
||||
tester,
|
||||
signedIn: true,
|
||||
history: InMemoryWatchHistoryRepository(seed: [_recent]),
|
||||
);
|
||||
await _openMine(tester);
|
||||
|
||||
await tester.tap(find.byKey(const Key('mine-vip-open')));
|
||||
await tester.pumpAndSettle();
|
||||
expect(find.byType(VipPage), findsOneWidget);
|
||||
await tester.binding.handlePopRoute();
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
await tester.tap(find.byKey(const Key('mine-mini-player')));
|
||||
await tester.pumpAndSettle();
|
||||
final player = tester.widget<PlayerPage>(find.byType(PlayerPage).last);
|
||||
expect(player.embedded, isFalse);
|
||||
});
|
||||
|
||||
testWidgets('should_expose_seven_menu_destinations_in_order', (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;
|
||||
await tester.pumpWidget(
|
||||
MaterialApp(
|
||||
theme: AppTheme.dark(),
|
||||
locale: const Locale('en'),
|
||||
supportedLocales: AppLocalizations.supportedLocales,
|
||||
localizationsDelegates: AppLocalizations.localizationsDelegates,
|
||||
home: Scaffold(
|
||||
body: SingleChildScrollView(
|
||||
padding: const EdgeInsets.all(AppDimens.pageHorizontal),
|
||||
child: MineMenuList(
|
||||
onOpen: opened.add,
|
||||
onLanguage: () => languageOpened++,
|
||||
languageLabel: 'English',
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
const rows = [
|
||||
(Key('mine-wallet'), MineDestination.wallet),
|
||||
(Key('mine-downloads'), MineDestination.downloads),
|
||||
(Key('mine-history'), MineDestination.history),
|
||||
(Key('mine-watch-preferences'), MineDestination.preferences),
|
||||
(Key('mine-help'), MineDestination.help),
|
||||
];
|
||||
for (final row in rows) {
|
||||
await tester.tap(find.byKey(row.$1));
|
||||
await tester.pump();
|
||||
expect(opened.last, row.$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);
|
||||
});
|
||||
}
|
||||
|
||||
const _recent = WatchProgress(
|
||||
dramaId: 'city-lights-demo',
|
||||
episodeId: 'city-lights-demo-3',
|
||||
dramaTitle: 'Recent drama',
|
||||
dramaCover: '/files/recent.jpg',
|
||||
episodeNumber: 3,
|
||||
totalEpisodes: 8,
|
||||
position: Duration(seconds: 30),
|
||||
duration: Duration(minutes: 2),
|
||||
);
|
||||
|
||||
Future<void> _openMine(WidgetTester tester) async {
|
||||
await tester.tap(find.byKey(const Key('tab-mine')));
|
||||
await tester.pumpAndSettle();
|
||||
}
|
||||
|
||||
Future<void> _pumpApp(
|
||||
WidgetTester tester, {
|
||||
required bool signedIn,
|
||||
WatchHistoryRepository? history,
|
||||
}) async {
|
||||
tester.view.physicalSize = const Size(390, 1000);
|
||||
tester.view.devicePixelRatio = 1;
|
||||
addTearDown(tester.view.resetPhysicalSize);
|
||||
addTearDown(tester.view.resetDevicePixelRatio);
|
||||
SharedPreferencesAsyncPlatform.instance = signedIn
|
||||
? InMemorySharedPreferencesAsync.withData({
|
||||
'auth.accessToken': 'access',
|
||||
'auth.refreshToken': 'refresh',
|
||||
'auth.user': '{"uid":"U-100","nickname":"Viewer","avatarUrl":""}',
|
||||
})
|
||||
: InMemorySharedPreferencesAsync.empty();
|
||||
final catalog = FakeCatalogRepository();
|
||||
await tester.pumpWidget(
|
||||
LumaDramaApp(
|
||||
playerFactory: createWidgetPlayer,
|
||||
catalogRepository: catalog,
|
||||
categoryRepository: FakeCategoryRepository(catalog: catalog),
|
||||
watchHistoryRepository: history ?? InMemoryWatchHistoryRepository(),
|
||||
favoriteRepository: InMemoryFavoriteRepository(cards: catalog.dramas),
|
||||
playbackRepository: FakePlaybackRepository(),
|
||||
commentRepository: FakeCommentRepository(),
|
||||
interactionRepository: FakeInteractionRepository(),
|
||||
noticeRepository: FakeNoticeRepository(),
|
||||
),
|
||||
);
|
||||
await tester.pumpAndSettle();
|
||||
}
|
||||
Reference in new issue
Block a user