Skip to content

Commit 39d2f10

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 32ee272 commit 39d2f10

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
@@ -55,6 +55,7 @@ void main() {
5555
bool foundOldest = true,
5656
int? messageCount,
5757
List<Message>? messages,
58+
GetMessagesResult? fetchResult,
5859
List<ZulipStream>? streams,
5960
List<User>? users,
6061
List<Subscription>? subscriptions,
@@ -79,12 +80,17 @@ void main() {
7980
// prepare message list data
8081
await store.addUser(eg.selfUser);
8182
await store.addUsers(users ?? []);
82-
assert((messageCount == null) != (messages == null));
83-
messages ??= List.generate(messageCount!, (index) {
84-
return eg.streamMessage(sender: eg.selfUser);
85-
});
86-
connection.prepare(json:
87-
eg.newestGetMessagesResult(foundOldest: foundOldest, messages: messages).toJson());
83+
if (fetchResult != null) {
84+
assert(foundOldest && messageCount == null && messages == null);
85+
} else {
86+
assert((messageCount == null) != (messages == null));
87+
messages ??= List.generate(messageCount!, (index) {
88+
return eg.streamMessage(sender: eg.selfUser);
89+
});
90+
fetchResult = eg.newestGetMessagesResult(
91+
foundOldest: foundOldest, messages: messages);
92+
}
93+
connection.prepare(json: fetchResult.toJson());
8894

8995
await tester.pumpWidget(TestZulipApp(accountId: selfAccount.id,
9096
skipAssertAccountExists: skipAssertAccountExists,
@@ -620,6 +626,55 @@ void main() {
620626
});
621627
});
622628

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

0 commit comments

Comments
 (0)