Skip to content

Commit 2afc04d

Browse files
committed
wip start on widget tests of end-cap; TODO check lack of newest hides typing-status and mark-as-read; TODO revisit realism of data
1 parent 5f882d5 commit 2afc04d

File tree

1 file changed

+61
-6
lines changed

1 file changed

+61
-6
lines changed

test/widgets/message_list_test.dart

Lines changed: 61 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ void main() {
5353
bool foundOldest = true,
5454
int? messageCount,
5555
List<Message>? messages,
56+
GetMessagesResult? fetchResult,
5657
List<ZulipStream>? streams,
5758
List<User>? users,
5859
List<Subscription>? subscriptions,
@@ -77,12 +78,17 @@ void main() {
7778
// prepare message list data
7879
await store.addUser(eg.selfUser);
7980
await store.addUsers(users ?? []);
80-
assert((messageCount == null) != (messages == null));
81-
messages ??= List.generate(messageCount!, (index) {
82-
return eg.streamMessage(sender: eg.selfUser);
83-
});
84-
connection.prepare(json:
85-
eg.newestGetMessagesResult(foundOldest: foundOldest, messages: messages).toJson());
81+
if (fetchResult != null) {
82+
assert(foundOldest && messageCount == null && messages == null);
83+
} else {
84+
assert((messageCount == null) != (messages == null));
85+
messages ??= List.generate(messageCount!, (index) {
86+
return eg.streamMessage(sender: eg.selfUser);
87+
});
88+
fetchResult = eg.newestGetMessagesResult(
89+
foundOldest: foundOldest, messages: messages);
90+
}
91+
connection.prepare(json: fetchResult.toJson());
8692

8793
await tester.pumpWidget(TestZulipApp(accountId: selfAccount.id,
8894
skipAssertAccountExists: skipAssertAccountExists,
@@ -618,6 +624,55 @@ void main() {
618624
});
619625
});
620626

627+
group('markers at end of list', () {
628+
final findLoadingIndicator = find.byType(CircularProgressIndicator);
629+
630+
testWidgets('spacer when have newest', (tester) async {
631+
final messages = List.generate(10,
632+
(i) => eg.streamMessage(content: '<p>message $i</p>'));
633+
await setupMessageListPage(tester, narrow: CombinedFeedNarrow(),
634+
fetchResult: eg.nearGetMessagesResult(anchor: messages.last.id,
635+
foundOldest: true, foundNewest: true, messages: messages));
636+
check(findMessageListScrollController(tester)!.position)
637+
.extentAfter.equals(0);
638+
639+
// There's no loading indicator.
640+
check(findLoadingIndicator).findsNothing();
641+
// The last message is spaced above the bottom of the viewport.
642+
check(tester.getRect(find.text('message 9')))
643+
.bottom..isGreaterThan(400)..isLessThan(570);
644+
});
645+
646+
testWidgets('loading indicator displaces spacer etc.', (tester) async {
647+
await setupMessageListPage(tester, narrow: CombinedFeedNarrow(),
648+
skipPumpAndSettle: true,
649+
fetchResult: eg.nearGetMessagesResult(anchor: 1000,
650+
foundOldest: true, foundNewest: false,
651+
messages: List.generate(10,
652+
(i) => eg.streamMessage(id: 100 + i, content: '<p>message $i</p>'))));
653+
await tester.pump();
654+
655+
// The message list will immediately start fetching newer messages.
656+
connection.prepare(json: eg.newerGetMessagesResult(
657+
anchor: 109, foundNewest: true, messages: List.generate(100,
658+
(i) => eg.streamMessage(id: 110 + i))).toJson());
659+
await tester.pump(Duration(milliseconds: 10));
660+
await tester.pump();
661+
662+
// There's a loading indicator.
663+
check(findLoadingIndicator).findsOne();
664+
// It's at the bottom.
665+
check(findMessageListScrollController(tester)!.position)
666+
.extentAfter.equals(0);
667+
final loadingIndicatorRect = tester.getRect(findLoadingIndicator);
668+
check(loadingIndicatorRect).bottom.isGreaterThan(575);
669+
// The last message is shortly above it; no spacer or anything else.
670+
check(tester.getRect(find.text('message 9')))
671+
.bottom.isGreaterThan(loadingIndicatorRect.top - 36); // TODO where's this space going?
672+
await tester.pumpAndSettle();
673+
});
674+
});
675+
621676
group('TypingStatusWidget', () {
622677
final users = [eg.selfUser, eg.otherUser, eg.thirdUser, eg.fourthUser];
623678
final finder = find.descendant(

0 commit comments

Comments
 (0)