fix(flutter): 首页 feed 静默刷新与进度条细节

This commit is contained in:
Zhou Weidong committed 2026-10-20 14:11:42 +08:00
1 parent a3126723d2
commit 82fe237c24
8 files changed
+190 -17

No files matched your search

@@ -0,0 +1,72 @@
// Author: fruit.com.cn
import 'package:flutter_test/flutter_test.dart';
import 'package:fruitshorts/core/data/models/drama.dart';
import 'package:fruitshorts/core/data/models/home_feed.dart';
import 'package:fruitshorts/core/data/repositories/catalog_repository.dart';
import 'package:fruitshorts/core/data/services/catalog_controller.dart';
void main() {
test('should_keep_state_when_silent_refresh_fails', () async {
final repository = _FakeCatalog(fail: true);
final controller = CatalogController(repository);
const oldFeed = HomeFeed();
controller.feed = oldFeed;
final ok = await controller.refresh();
expect(ok, isFalse);
expect(controller.feed, same(oldFeed));
expect(controller.loading, isFalse);
expect(controller.error, isNull);
});
test(
'should_replace_feed_without_touching_loading_when_refresh_succeeds',
() async {
final repository = _FakeCatalog();
final controller = CatalogController(repository);
controller.feed = const HomeFeed();
final next = HomeFeed(
sections: [
FeedSection(code: 'new', title: 'New', dramas: const [_drama]),
],
);
repository.next = next;
final ok = await controller.refresh();
expect(ok, isTrue);
expect(controller.feed, same(next));
expect(controller.loading, isFalse);
expect(controller.error, isNull);
},
);
}
class _FakeCatalog implements CatalogRepository {
_FakeCatalog({this.fail = false});
bool fail;
HomeFeed next = const HomeFeed();
@override
Future<HomeFeed> fetchHomeFeed() async {
if (fail) throw StateError('offline');
return next;
}
@override
Future<HomeFeed> fetchDiscoverFeed() async => const HomeFeed();
@override
Future<Drama> fetchDrama(String dramaId) async => _drama;
}
const _drama = Drama(
id: 'refresh-drama',
title: 'Refresh Drama',
synopsis: 'synopsis',
posterUrl: '',
detailLoaded: true,
);
+44
View File
@@ -211,6 +211,12 @@ void main() {
final bar = tester.getRect(find.byKey(const Key('home-feed-full-series')));
expect(bar.height, 44);
expect(
tester
.widget<Container>(find.byKey(const Key('home-feed-full-series-bg')))
.color,
const Color(0x4D000000),
);
expect(
tester.getRect(find.textContaining('Watch full series')).center.dy,
closeTo(bar.center.dy, 2),
@@ -219,6 +225,23 @@ void main() {
tester.getSize(find.byKey(const Key('home-feed-progress-thumb'))),
const Size(6, 6),
);
expect(
tester.getSize(find.byKey(const Key('home-feed-progress'))).height,
greaterThanOrEqualTo(24),
);
expect(
tester
.getRect(find.byKey(const Key('home-feed-progress-thumb')))
.center
.dy,
closeTo(
tester
.getRect(find.byKey(const Key('home-feed-progress-track')))
.center
.dy,
0.5,
),
);
await tester.tap(find.byKey(const Key('home-feed-refresh')));
await tester.pump();
@@ -233,6 +256,23 @@ void main() {
tester.getSize(find.byKey(const Key('home-feed-progress-thumb'))),
const Size(10, 10),
);
expect(
tester.getSize(find.byKey(const Key('home-feed-progress-track'))).height,
4,
);
expect(
tester
.getRect(find.byKey(const Key('home-feed-progress-thumb')))
.center
.dy,
closeTo(
tester
.getRect(find.byKey(const Key('home-feed-progress-track')))
.center
.dy,
0.5,
),
);
await gesture.up();
await tester.pumpAndSettle();
expect(seeked, isNotNull);
@@ -241,6 +281,10 @@ void main() {
tester.getSize(find.byKey(const Key('home-feed-progress-thumb'))),
const Size(6, 6),
);
expect(
tester.getSize(find.byKey(const Key('home-feed-progress-track'))).height,
2,
);
await tester.tap(find.byKey(const Key('home-feed-full-series')));
await tester.pump();
+26
View File
@@ -96,6 +96,32 @@ void main() {
expect(find.text('Coming soon'), findsOneWidget);
});
testWidgets('should_refresh_feed_without_blank_loading', (tester) async {
await _pumpApp(tester);
await tester.tap(find.byKey(const Key('home-feed-refresh')));
await tester.pump();
expect(find.byType(CircularProgressIndicator), findsNothing);
expect(find.byKey(const Key('home-feed-title')), findsOneWidget);
await tester.pumpAndSettle();
expect(find.byKey(const Key('home-feed-title')), findsOneWidget);
});
testWidgets('should_keep_feed_rail_above_bottom_panels', (tester) async {
await _pumpApp(tester);
final railTop = tester.getCenter(find.byKey(const Key('rail-save'))).dy;
final railBottom = tester
.getRect(find.byKey(const Key('rail-share')))
.bottom;
final infoTop = tester
.getRect(find.byKey(const Key('home-feed-series-meta')))
.top;
expect(railTop, greaterThan(844 * 0.35));
expect(railBottom, lessThanOrEqualTo(infoTop));
});
testWidgets('should_restore_light_theme_after_leaving_feed_tab', (
tester,
) async {