186 lines
6.3 KiB
Dart
186 lines
6.3 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/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';
|
|
|
|
import '../support/fake_catalog.dart';
|
|
import '../support/fake_category.dart';
|
|
import '../support/fake_haptics.dart';
|
|
import '../support/fake_interaction_repositories.dart';
|
|
import '../support/widget_player.dart';
|
|
|
|
void main() {
|
|
setUp(() {
|
|
SharedPreferencesAsyncPlatform.instance =
|
|
InMemorySharedPreferencesAsync.empty();
|
|
});
|
|
|
|
testWidgets('should_render_four_tabs_and_open_create_placeholder', (
|
|
tester,
|
|
) async {
|
|
await _pumpApp(tester);
|
|
|
|
for (final key in _tabKeys) {
|
|
expect(find.byKey(key), findsOneWidget);
|
|
}
|
|
|
|
await tester.tap(find.byKey(const Key('tab-create')));
|
|
await tester.pumpAndSettle();
|
|
|
|
expect(find.byKey(const Key('create-page')), findsOneWidget);
|
|
expect(find.text('Create'), findsWidgets);
|
|
expect(find.text('Stories become short dramas'), findsOneWidget);
|
|
expect(find.byKey(const Key('create-ai')), findsOneWidget);
|
|
expect(find.byKey(const Key('create-upload')), findsOneWidget);
|
|
|
|
await tester.tap(find.byKey(const Key('create-ai')));
|
|
await tester.pumpAndSettle();
|
|
expect(find.byKey(const Key('create-placeholder-page')), findsOneWidget);
|
|
expect(find.text('Coming soon'), findsOneWidget);
|
|
});
|
|
|
|
testWidgets('should_start_home_on_immersive_feed', (tester) async {
|
|
await _pumpApp(tester);
|
|
|
|
expect(find.byKey(const Key('home-feed-title')), findsOneWidget);
|
|
expect(find.byKey(const Key('home-feed-info-card')), findsOneWidget);
|
|
expect(find.byType(PageView), findsOneWidget);
|
|
expect(find.byKey(const Key('home-browse-page')), findsNothing);
|
|
expect(tester.widget<PlayerPage>(find.byType(PlayerPage)).homeMode, isTrue);
|
|
});
|
|
|
|
testWidgets('should_switch_feed_drama_when_swiped_up', (tester) async {
|
|
await _pumpApp(tester);
|
|
final before = tester
|
|
.widget<Text>(find.byKey(const Key('home-feed-title')))
|
|
.data;
|
|
|
|
await tester.drag(find.byType(PageView).first, const Offset(0, -600));
|
|
await tester.pumpAndSettle();
|
|
|
|
final after = tester
|
|
.widget<Text>(find.byKey(const Key('home-feed-title')))
|
|
.data;
|
|
expect(after, isNot(before));
|
|
});
|
|
|
|
testWidgets('should_hide_feed_when_switching_to_theater', (tester) async {
|
|
await _pumpApp(tester);
|
|
expect(find.byKey(const Key('home-feed-title')), findsOneWidget);
|
|
|
|
await tester.tap(find.byKey(const Key('tab-theater')));
|
|
await tester.pumpAndSettle();
|
|
|
|
expect(find.byKey(const Key('home-feed-title')), findsNothing);
|
|
expect(find.byKey(const Key('discover-search')), findsOneWidget);
|
|
});
|
|
|
|
testWidgets('should_open_theater_search_when_feed_search_is_tapped', (
|
|
tester,
|
|
) async {
|
|
await _pumpApp(tester);
|
|
|
|
await tester.tap(find.byKey(const Key('home-feed-search')));
|
|
await tester.pumpAndSettle();
|
|
|
|
final field = tester.widget<TextField>(
|
|
find.byKey(const Key('discover-search')),
|
|
);
|
|
expect(field.focusNode?.hasFocus, isTrue);
|
|
});
|
|
|
|
testWidgets('should_not_render_theater_language_filters', (tester) async {
|
|
await _pumpApp(tester);
|
|
await tester.tap(find.byKey(const Key('tab-theater')));
|
|
await tester.pumpAndSettle();
|
|
|
|
expect(find.byKey(const Key('theater-language-chips')), findsNothing);
|
|
expect(find.byKey(const Key('theater-category-chips')), findsOneWidget);
|
|
expect(find.byKey(const Key('discover-search')), findsOneWidget);
|
|
expect(find.byKey(const Key('discover-refresh')), findsOneWidget);
|
|
expect(
|
|
find.byKey(const Key('home-drama-card-the-signal-demo')),
|
|
findsOneWidget,
|
|
);
|
|
});
|
|
|
|
testWidgets('should_open_fullscreen_player_when_theater_card_is_tapped', (
|
|
tester,
|
|
) async {
|
|
await _pumpApp(tester);
|
|
await tester.tap(find.byKey(const Key('tab-theater')));
|
|
await tester.pumpAndSettle();
|
|
|
|
final card = find.byKey(const Key('home-drama-card-the-signal-demo'));
|
|
await tester.scrollUntilVisible(
|
|
card,
|
|
220,
|
|
scrollable: find
|
|
.descendant(
|
|
of: find.byKey(const Key('discover-refresh')),
|
|
matching: find.byType(Scrollable),
|
|
)
|
|
.first,
|
|
);
|
|
await tester.ensureVisible(card);
|
|
await tester.pumpAndSettle();
|
|
await tester.tap(card);
|
|
await tester.pumpAndSettle();
|
|
|
|
final player = tester.widget<PlayerPage>(find.byType(PlayerPage).last);
|
|
expect(player.homeMode, isFalse);
|
|
});
|
|
|
|
testWidgets('should_fit_home_feed_and_theater_on_320_width', (tester) async {
|
|
await _pumpApp(tester, size: const Size(320, 568));
|
|
|
|
expect(find.byKey(const Key('home-feed-title')), findsOneWidget);
|
|
expect(tester.takeException(), isNull);
|
|
|
|
await tester.tap(find.byKey(const Key('tab-theater')));
|
|
await tester.pumpAndSettle();
|
|
expect(find.byKey(const Key('theater-category-chips')), findsOneWidget);
|
|
expect(find.byKey(const Key('theater-language-chips')), findsNothing);
|
|
expect(tester.takeException(), isNull);
|
|
});
|
|
}
|
|
|
|
const _tabKeys = [
|
|
Key('tab-home'),
|
|
Key('tab-theater'),
|
|
Key('tab-create'),
|
|
Key('tab-mine'),
|
|
];
|
|
|
|
Future<void> _pumpApp(
|
|
WidgetTester tester, {
|
|
Size size = const Size(390, 844),
|
|
}) async {
|
|
tester.view.physicalSize = size;
|
|
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(),
|
|
haptics: FakeHaptics(),
|
|
),
|
|
);
|
|
await tester.pumpAndSettle();
|
|
}
|