Skip to content

Commit

Permalink
msglist test [nfc]: Deduplicate getAnimation helper
Browse files Browse the repository at this point in the history
  • Loading branch information
sirpengi committed Oct 25, 2023
1 parent e5cb492 commit 508f86f
Showing 1 changed file with 8 additions and 17 deletions.
25 changes: 8 additions & 17 deletions test/widgets/message_list_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -302,9 +302,9 @@ void main() {
});

group('_UnreadMarker animations', () {
Animation getAnimation(WidgetTester tester) {
Animation getAnimation(WidgetTester tester, int messageId) {
final widget = tester.widget<FadeTransition>(find.descendant(
of: find.byType(MessageItem),
of: find.byKey(ValueKey(messageId)),
matching: find.byType(FadeTransition)));
return widget.opacity;
}
Expand All @@ -313,23 +313,23 @@ void main() {
final message = eg.streamMessage(flags: [MessageFlag.read]);
await setupMessageListPage(tester, messages: [message]);

check(getAnimation(tester).value).equals(0);
check(getAnimation(tester, message.id).value).equals(0);

store.handleEvent(eg.updateMessageFlagsRemoveEvent(
MessageFlag.read, [message]));
await tester.pump(); // process handleEvent
check(getAnimation(tester).status).equals(AnimationStatus.forward);
check(getAnimation(tester, message.id).status).equals(AnimationStatus.forward);

await tester.pumpAndSettle();

check(getAnimation(tester).value).equals(1.0);
check(getAnimation(tester, message.id).value).equals(1.0);
});

testWidgets('from unread to read', (WidgetTester tester) async {
final message = eg.streamMessage(flags: []);
await setupMessageListPage(tester, messages: [message]);

check(getAnimation(tester).value).equals(1.0);
check(getAnimation(tester, message.id).value).equals(1.0);

store.handleEvent(UpdateMessageFlagsAddEvent(
id: 1,
Expand All @@ -338,25 +338,16 @@ void main() {
all: false,
));
await tester.pump(); // process handleEvent
check(getAnimation(tester).status).equals(AnimationStatus.forward);
check(getAnimation(tester, message.id).status).equals(AnimationStatus.forward);

await tester.pumpAndSettle();

check(getAnimation(tester).value).equals(0);
check(getAnimation(tester, message.id).value).equals(0);
});

testWidgets('animation state persistence', (WidgetTester tester) async {
// Check that _UnreadMarker maintains its in-progress animation
// as the number of items change in MessageList.

// TODO: pull this out into group
Animation getAnimation(WidgetTester tester, int messageId) {
final widget = tester.widget<FadeTransition>(find.descendant(
of: find.byKey(ValueKey(messageId)),
matching: find.byType(FadeTransition)));
return widget.opacity;
}

final message = eg.streamMessage(id: 1, flags: []);
await setupMessageListPage(tester, messages: [message]);

Expand Down

0 comments on commit 508f86f

Please sign in to comment.