179 lines
6.6 KiB
Dart
179 lines
6.6 KiB
Dart
// Author: fruit.com.cn
|
|
|
|
import 'package:flutter/material.dart';
|
|
import 'package:flutter_test/flutter_test.dart';
|
|
import 'package:fruitshorts/app.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: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', (
|
|
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();
|
|
|
|
expect(find.byKey(const Key('mine-user-row')), findsOneWidget);
|
|
expect(find.byKey(const Key('mine-continue-watching')), findsNothing);
|
|
for (final key in const [
|
|
Key('mine-watchlist'),
|
|
Key('mine-history'),
|
|
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-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);
|
|
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,
|
|
);
|
|
final dividers = tester.widgetList<Divider>(
|
|
find.descendant(
|
|
of: find.byKey(const Key('mine-menu')),
|
|
matching: find.byType(Divider),
|
|
),
|
|
);
|
|
expect(dividers, hasLength(5));
|
|
expect(
|
|
dividers.every((divider) => divider.color == AppColors.contentSurface),
|
|
isTrue,
|
|
);
|
|
expect(tester.takeException(), isNull);
|
|
|
|
await tester.tap(find.byKey(const Key('mine-watchlist')));
|
|
await tester.pumpAndSettle();
|
|
expect(find.byKey(const Key('favorites-page')), findsOneWidget);
|
|
});
|
|
}
|