fix(flutter): feed 长按加速与刷新转圈
This commit is contained in:
1 parent
564c0dbbef
commit
ea9ea6e606
5 files changed
+317
-103
No files matched your search
@@ -1,5 +1,7 @@
|
||||
// Author: fruit.com.cn
|
||||
|
||||
import 'dart:async';
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:shared_preferences_platform_interface/in_memory_shared_preferences_async.dart';
|
||||
@@ -104,6 +106,11 @@ void main() {
|
||||
controller: null,
|
||||
liked: true,
|
||||
saved: false,
|
||||
visible: true,
|
||||
boosting: false,
|
||||
onTogglePlay: () {},
|
||||
onBoostStart: () {},
|
||||
onBoostEnd: () {},
|
||||
likeCount: 1006,
|
||||
favoriteCount: 32000,
|
||||
commentCount: 12,
|
||||
@@ -114,7 +121,7 @@ void main() {
|
||||
onEpisodes: () {},
|
||||
onDetail: () {},
|
||||
onOpenFullPlayer: () {},
|
||||
onRefreshFeed: () {},
|
||||
onRefreshFeed: () async => true,
|
||||
onDownload: () {},
|
||||
onClear: () {},
|
||||
onSearch: () {},
|
||||
@@ -189,6 +196,11 @@ void main() {
|
||||
controller: controller,
|
||||
liked: false,
|
||||
saved: false,
|
||||
visible: true,
|
||||
boosting: false,
|
||||
onTogglePlay: () {},
|
||||
onBoostStart: () {},
|
||||
onBoostEnd: () {},
|
||||
onLike: () {},
|
||||
onSave: () {},
|
||||
onComments: () {},
|
||||
@@ -196,7 +208,10 @@ void main() {
|
||||
onEpisodes: () {},
|
||||
onDetail: () {},
|
||||
onOpenFullPlayer: () => opened++,
|
||||
onRefreshFeed: () => refreshed++,
|
||||
onRefreshFeed: () async {
|
||||
refreshed++;
|
||||
return true;
|
||||
},
|
||||
onDownload: () {},
|
||||
onClear: () {},
|
||||
onSearch: () {},
|
||||
@@ -254,11 +269,11 @@ void main() {
|
||||
await tester.pump();
|
||||
expect(
|
||||
tester.getSize(find.byKey(const Key('home-feed-progress-thumb'))),
|
||||
const Size(10, 10),
|
||||
const Size(14, 14),
|
||||
);
|
||||
expect(
|
||||
tester.getSize(find.byKey(const Key('home-feed-progress-track'))).height,
|
||||
4,
|
||||
6,
|
||||
);
|
||||
expect(
|
||||
tester
|
||||
@@ -290,4 +305,75 @@ void main() {
|
||||
await tester.pump();
|
||||
expect(opened, 1);
|
||||
});
|
||||
|
||||
testWidgets('should_show_refresh_spinner_until_refresh_finishes', (
|
||||
tester,
|
||||
) async {
|
||||
final completer = Completer<bool>();
|
||||
var calls = 0;
|
||||
await tester.pumpWidget(
|
||||
MaterialApp(
|
||||
theme: AppTheme.light(),
|
||||
locale: const Locale('en'),
|
||||
supportedLocales: AppLocalizations.supportedLocales,
|
||||
localizationsDelegates: AppLocalizations.localizationsDelegates,
|
||||
home: Builder(
|
||||
builder: (context) => Scaffold(
|
||||
body: HomeFeedOverlay(
|
||||
l10n: AppLocalizations.of(context)!,
|
||||
drama: const Drama(
|
||||
id: 'refresh-drama',
|
||||
title: 'Refresh Drama',
|
||||
synopsis: 'synopsis',
|
||||
posterUrl: '',
|
||||
totalEpisodes: 8,
|
||||
),
|
||||
episode: const Episode(
|
||||
id: 'refresh-episode',
|
||||
number: 1,
|
||||
title: 'Episode 1',
|
||||
isFree: true,
|
||||
),
|
||||
controller: null,
|
||||
liked: false,
|
||||
saved: false,
|
||||
visible: true,
|
||||
boosting: false,
|
||||
onTogglePlay: () {},
|
||||
onBoostStart: () {},
|
||||
onBoostEnd: () {},
|
||||
onLike: () {},
|
||||
onSave: () {},
|
||||
onComments: () {},
|
||||
onShare: () {},
|
||||
onEpisodes: () {},
|
||||
onDetail: () {},
|
||||
onOpenFullPlayer: () {},
|
||||
onRefreshFeed: () {
|
||||
calls++;
|
||||
return completer.future;
|
||||
},
|
||||
onDownload: () {},
|
||||
onClear: () {},
|
||||
onSearch: () {},
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
await tester.tap(find.byKey(const Key('home-feed-refresh')));
|
||||
await tester.pump();
|
||||
expect(find.byKey(const Key('home-feed-refreshing')), findsOneWidget);
|
||||
|
||||
await tester.tap(find.byKey(const Key('home-feed-refresh')));
|
||||
await tester.pump();
|
||||
expect(calls, 1);
|
||||
|
||||
completer.complete(true);
|
||||
await tester.pumpAndSettle();
|
||||
expect(find.byKey(const Key('home-feed-refreshing')), findsNothing);
|
||||
expect(find.byIcon(Icons.refresh_rounded), findsOneWidget);
|
||||
});
|
||||
}
|
||||
@@ -118,10 +118,42 @@ void main() {
|
||||
.getRect(find.byKey(const Key('home-feed-series-meta')))
|
||||
.top;
|
||||
|
||||
expect(railTop, greaterThan(844 * 0.35));
|
||||
expect(railTop, greaterThan(844 * 0.45));
|
||||
expect(railBottom, lessThanOrEqualTo(infoTop));
|
||||
});
|
||||
|
||||
testWidgets('should_boost_feed_on_side_long_press', (tester) async {
|
||||
await _pumpApp(tester);
|
||||
expect(find.byKey(const Key('home-feed-title')), findsOneWidget);
|
||||
|
||||
final gesture = await tester.startGesture(const Offset(60, 300));
|
||||
await tester.pump(const Duration(milliseconds: 700));
|
||||
await tester.pump();
|
||||
|
||||
expect(find.byKey(const Key('home-feed-speed-boost-hint')), findsOneWidget);
|
||||
expect(find.byKey(const Key('home-feed-full-series')), findsOneWidget);
|
||||
expect(find.byKey(const Key('home-feed-title')), findsNothing);
|
||||
expect(find.byKey(const Key('rail-save')), findsNothing);
|
||||
|
||||
await gesture.up();
|
||||
await tester.pumpAndSettle();
|
||||
expect(find.byKey(const Key('home-feed-speed-boost-hint')), findsNothing);
|
||||
expect(find.byKey(const Key('home-feed-title')), findsOneWidget);
|
||||
expect(find.byKey(const Key('rail-save')), findsOneWidget);
|
||||
});
|
||||
|
||||
testWidgets('should_open_more_sheet_on_center_long_press', (tester) async {
|
||||
await _pumpApp(tester);
|
||||
|
||||
final gesture = await tester.startGesture(const Offset(195, 300));
|
||||
await tester.pump(const Duration(milliseconds: 700));
|
||||
await tester.pump();
|
||||
await gesture.up();
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
expect(find.byKey(const Key('home-feed-clear')), findsOneWidget);
|
||||
});
|
||||
|
||||
testWidgets('should_restore_light_theme_after_leaving_feed_tab', (
|
||||
tester,
|
||||
) async {
|
||||
|
||||
Reference in new issue
Block a user