@@ -59,6 +59,7 @@ void main() {
59
59
bool foundOldest = true ,
60
60
int ? messageCount,
61
61
List <Message >? messages,
62
+ GetMessagesResult ? fetchResult,
62
63
List <ZulipStream >? streams,
63
64
List <User >? users,
64
65
List <Subscription >? subscriptions,
@@ -83,12 +84,17 @@ void main() {
83
84
// prepare message list data
84
85
await store.addUser (eg.selfUser);
85
86
await store.addUsers (users ?? []);
86
- assert ((messageCount == null ) != (messages == null ));
87
- messages ?? = List .generate (messageCount! , (index) {
88
- return eg.streamMessage (sender: eg.selfUser);
89
- });
90
- connection.prepare (json:
91
- eg.newestGetMessagesResult (foundOldest: foundOldest, messages: messages).toJson ());
87
+ if (fetchResult != null ) {
88
+ assert (foundOldest && messageCount == null && messages == null );
89
+ } else {
90
+ assert ((messageCount == null ) != (messages == null ));
91
+ messages ?? = List .generate (messageCount! , (index) {
92
+ return eg.streamMessage (sender: eg.selfUser);
93
+ });
94
+ fetchResult = eg.newestGetMessagesResult (
95
+ foundOldest: foundOldest, messages: messages);
96
+ }
97
+ connection.prepare (json: fetchResult.toJson ());
92
98
93
99
await tester.pumpWidget (TestZulipApp (accountId: selfAccount.id,
94
100
skipAssertAccountExists: skipAssertAccountExists,
@@ -696,6 +702,63 @@ void main() {
696
702
});
697
703
});
698
704
705
+ // TODO test markers at start of list (`_buildStartCap`)
706
+
707
+ group ('markers at end of list' , () {
708
+ final findLoadingIndicator = find.byType (CircularProgressIndicator );
709
+
710
+ testWidgets ('spacer when have newest' , (tester) async {
711
+ final messages = List .generate (10 ,
712
+ (i) => eg.streamMessage (content: '<p>message $i </p>' ));
713
+ await setupMessageListPage (tester, narrow: CombinedFeedNarrow (),
714
+ fetchResult: eg.nearGetMessagesResult (anchor: messages.last.id,
715
+ foundOldest: true , foundNewest: true , messages: messages));
716
+ check (findMessageListScrollController (tester)! .position)
717
+ .extentAfter.equals (0 );
718
+
719
+ // There's no loading indicator.
720
+ check (findLoadingIndicator).findsNothing ();
721
+ // The last message is spaced above the bottom of the viewport.
722
+ check (tester.getRect (find.text ('message 9' )))
723
+ .bottom..isGreaterThan (400 )..isLessThan (570 );
724
+ });
725
+
726
+ testWidgets ('loading indicator displaces spacer etc.' , (tester) async {
727
+ await setupMessageListPage (tester, narrow: CombinedFeedNarrow (),
728
+ skipPumpAndSettle: true ,
729
+ // TODO(#1569) fix realism of this data: foundNewest false should mean
730
+ // some messages found after anchor (and then we might need to scroll
731
+ // to cause fetching newer messages).
732
+ fetchResult: eg.nearGetMessagesResult (anchor: 1000 ,
733
+ foundOldest: true , foundNewest: false ,
734
+ messages: List .generate (10 ,
735
+ (i) => eg.streamMessage (id: 100 + i, content: '<p>message $i </p>' ))));
736
+ await tester.pump ();
737
+
738
+ // The message list will immediately start fetching newer messages.
739
+ connection.prepare (json: eg.newerGetMessagesResult (
740
+ anchor: 109 , foundNewest: true , messages: List .generate (100 ,
741
+ (i) => eg.streamMessage (id: 110 + i))).toJson ());
742
+ await tester.pump (Duration (milliseconds: 10 ));
743
+ await tester.pump ();
744
+
745
+ // There's a loading indicator.
746
+ check (findLoadingIndicator).findsOne ();
747
+ // It's at the bottom.
748
+ check (findMessageListScrollController (tester)! .position)
749
+ .extentAfter.equals (0 );
750
+ final loadingIndicatorRect = tester.getRect (findLoadingIndicator);
751
+ check (loadingIndicatorRect).bottom.isGreaterThan (575 );
752
+ // The last message is shortly above it; no spacer or anything else.
753
+ check (tester.getRect (find.text ('message 9' )))
754
+ .bottom.isGreaterThan (loadingIndicatorRect.top - 36 ); // TODO(#1569) where's this space going?
755
+ await tester.pumpAndSettle ();
756
+ });
757
+
758
+ // TODO(#1569) test no typing status or mark-read button when not haveNewest
759
+ // (even without loading indicator)
760
+ });
761
+
699
762
group ('TypingStatusWidget' , () {
700
763
final users = [eg.selfUser, eg.otherUser, eg.thirdUser, eg.fourthUser];
701
764
final finder = find.descendant (
0 commit comments