Skip to content

Commit 86b0705

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 daac68e commit 86b0705

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
@@ -58,6 +58,7 @@ void main() {
5858
bool foundOldest = true,
5959
int? messageCount,
6060
List<Message>? messages,
61+
GetMessagesResult? fetchResult,
6162
List<ZulipStream>? streams,
6263
List<User>? users,
6364
List<Subscription>? subscriptions,
@@ -82,12 +83,17 @@ void main() {
8283
// prepare message list data
8384
await store.addUser(eg.selfUser);
8485
await store.addUsers(users ?? []);
85-
assert((messageCount == null) != (messages == null));
86-
messages ??= List.generate(messageCount!, (index) {
87-
return eg.streamMessage(sender: eg.selfUser);
88-
});
89-
connection.prepare(json:
90-
eg.newestGetMessagesResult(foundOldest: foundOldest, messages: messages).toJson());
86+
if (fetchResult != null) {
87+
assert(foundOldest && messageCount == null && messages == null);
88+
} else {
89+
assert((messageCount == null) != (messages == null));
90+
messages ??= List.generate(messageCount!, (index) {
91+
return eg.streamMessage(sender: eg.selfUser);
92+
});
93+
fetchResult = eg.newestGetMessagesResult(
94+
foundOldest: foundOldest, messages: messages);
95+
}
96+
connection.prepare(json: fetchResult.toJson());
9197

9298
await tester.pumpWidget(TestZulipApp(accountId: selfAccount.id,
9399
skipAssertAccountExists: skipAssertAccountExists,
@@ -661,6 +667,55 @@ void main() {
661667
});
662668
});
663669

670+
group('markers at end of list', () {
671+
final findLoadingIndicator = find.byType(CircularProgressIndicator);
672+
673+
testWidgets('spacer when have newest', (tester) async {
674+
final messages = List.generate(10,
675+
(i) => eg.streamMessage(content: '<p>message $i</p>'));
676+
await setupMessageListPage(tester, narrow: CombinedFeedNarrow(),
677+
fetchResult: eg.nearGetMessagesResult(anchor: messages.last.id,
678+
foundOldest: true, foundNewest: true, messages: messages));
679+
check(findMessageListScrollController(tester)!.position)
680+
.extentAfter.equals(0);
681+
682+
// There's no loading indicator.
683+
check(findLoadingIndicator).findsNothing();
684+
// The last message is spaced above the bottom of the viewport.
685+
check(tester.getRect(find.text('message 9')))
686+
.bottom..isGreaterThan(400)..isLessThan(570);
687+
});
688+
689+
testWidgets('loading indicator displaces spacer etc.', (tester) async {
690+
await setupMessageListPage(tester, narrow: CombinedFeedNarrow(),
691+
skipPumpAndSettle: true,
692+
fetchResult: eg.nearGetMessagesResult(anchor: 1000,
693+
foundOldest: true, foundNewest: false,
694+
messages: List.generate(10,
695+
(i) => eg.streamMessage(id: 100 + i, content: '<p>message $i</p>'))));
696+
await tester.pump();
697+
698+
// The message list will immediately start fetching newer messages.
699+
connection.prepare(json: eg.newerGetMessagesResult(
700+
anchor: 109, foundNewest: true, messages: List.generate(100,
701+
(i) => eg.streamMessage(id: 110 + i))).toJson());
702+
await tester.pump(Duration(milliseconds: 10));
703+
await tester.pump();
704+
705+
// There's a loading indicator.
706+
check(findLoadingIndicator).findsOne();
707+
// It's at the bottom.
708+
check(findMessageListScrollController(tester)!.position)
709+
.extentAfter.equals(0);
710+
final loadingIndicatorRect = tester.getRect(findLoadingIndicator);
711+
check(loadingIndicatorRect).bottom.isGreaterThan(575);
712+
// The last message is shortly above it; no spacer or anything else.
713+
check(tester.getRect(find.text('message 9')))
714+
.bottom.isGreaterThan(loadingIndicatorRect.top - 36); // TODO where's this space going?
715+
await tester.pumpAndSettle();
716+
});
717+
});
718+
664719
group('TypingStatusWidget', () {
665720
final users = [eg.selfUser, eg.otherUser, eg.thirdUser, eg.fourthUser];
666721
final finder = find.descendant(

0 commit comments

Comments
 (0)