fix(home): 修复 feed 更新触发的 build 期 setState
This commit is contained in:
1 parent
862b7e92dd
commit
d227ac69fb
6 files changed
+174
-10
No files matched your search
@@ -1,5 +1,6 @@
|
||||
// Author: fruit.com.cn
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:fruitshorts/core/data/models/drama.dart';
|
||||
import 'package:fruitshorts/pages/discover/discover_types.dart';
|
||||
@@ -121,6 +122,40 @@ void main() {
|
||||
logic.dispose();
|
||||
});
|
||||
|
||||
testWidgets('should_defer_drama_notification_when_changed_during_build', (
|
||||
tester,
|
||||
) async {
|
||||
final logic = HomeLogic(dramas);
|
||||
var notifications = 0;
|
||||
var immediateNotifications = -1;
|
||||
var changed = false;
|
||||
logic.addListener(() => notifications++);
|
||||
|
||||
await tester.pumpWidget(
|
||||
MaterialApp(
|
||||
home: ListenableBuilder(
|
||||
listenable: logic,
|
||||
builder: (context, _) {
|
||||
if (!changed) {
|
||||
changed = true;
|
||||
logic.onDramaChanged(dramas[1]);
|
||||
immediateNotifications = notifications;
|
||||
}
|
||||
return const SizedBox.shrink();
|
||||
},
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
expect(immediateNotifications, 0);
|
||||
expect(tester.takeException(), isNull);
|
||||
expect(logic.currentDrama.id, 'city');
|
||||
await tester.pump();
|
||||
expect(notifications, 1);
|
||||
expect(tester.takeException(), isNull);
|
||||
logic.dispose();
|
||||
});
|
||||
|
||||
test('should_map_onto_root_tabs_when_my_page_actions_fire', () {
|
||||
final logic = HomeLogic(dramas);
|
||||
|
||||
|
||||
Reference in new issue
Block a user