Skip to content

Commit 7ac1759

Browse files
committed
wip msglist test: 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 1af88a0 commit 7ac1759

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
@@ -59,6 +59,7 @@ void main() {
5959
bool foundOldest = true,
6060
int? messageCount,
6161
List<Message>? messages,
62+
GetMessagesResult? fetchResult,
6263
List<ZulipStream>? streams,
6364
List<User>? users,
6465
List<Subscription>? subscriptions,
@@ -83,12 +84,17 @@ void main() {
8384
// prepare message list data
8485
await store.addUser(eg.selfUser);
8586
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());
9298

9399
await tester.pumpWidget(TestZulipApp(accountId: selfAccount.id,
94100
skipAssertAccountExists: skipAssertAccountExists,
@@ -692,6 +698,55 @@ void main() {
692698
});
693699
});
694700

701+
group('markers at end of list', () {
702+
final findLoadingIndicator = find.byType(CircularProgressIndicator);
703+
704+
testWidgets('spacer when have newest', (tester) async {
705+
final messages = List.generate(10,
706+
(i) => eg.streamMessage(content: '<p>message $i</p>'));
707+
await setupMessageListPage(tester, narrow: CombinedFeedNarrow(),
708+
fetchResult: eg.nearGetMessagesResult(anchor: messages.last.id,
709+
foundOldest: true, foundNewest: true, messages: messages));
710+
check(findMessageListScrollController(tester)!.position)
711+
.extentAfter.equals(0);
712+
713+
// There's no loading indicator.
714+
check(findLoadingIndicator).findsNothing();
715+
// The last message is spaced above the bottom of the viewport.
716+
check(tester.getRect(find.text('message 9')))
717+
.bottom..isGreaterThan(400)..isLessThan(570);
718+
});
719+
720+
testWidgets('loading indicator displaces spacer etc.', (tester) async {
721+
await setupMessageListPage(tester, narrow: CombinedFeedNarrow(),
722+
skipPumpAndSettle: true,
723+
fetchResult: eg.nearGetMessagesResult(anchor: 1000,
724+
foundOldest: true, foundNewest: false,
725+
messages: List.generate(10,
726+
(i) => eg.streamMessage(id: 100 + i, content: '<p>message $i</p>'))));
727+
await tester.pump();
728+
729+
// The message list will immediately start fetching newer messages.
730+
connection.prepare(json: eg.newerGetMessagesResult(
731+
anchor: 109, foundNewest: true, messages: List.generate(100,
732+
(i) => eg.streamMessage(id: 110 + i))).toJson());
733+
await tester.pump(Duration(milliseconds: 10));
734+
await tester.pump();
735+
736+
// There's a loading indicator.
737+
check(findLoadingIndicator).findsOne();
738+
// It's at the bottom.
739+
check(findMessageListScrollController(tester)!.position)
740+
.extentAfter.equals(0);
741+
final loadingIndicatorRect = tester.getRect(findLoadingIndicator);
742+
check(loadingIndicatorRect).bottom.isGreaterThan(575);
743+
// The last message is shortly above it; no spacer or anything else.
744+
check(tester.getRect(find.text('message 9')))
745+
.bottom.isGreaterThan(loadingIndicatorRect.top - 36); // TODO where's this space going?
746+
await tester.pumpAndSettle();
747+
});
748+
});
749+
695750
group('TypingStatusWidget', () {
696751
final users = [eg.selfUser, eg.otherUser, eg.thirdUser, eg.fourthUser];
697752
final finder = find.descendant(

0 commit comments

Comments
 (0)