Skip to content

Commit

Permalink
3 More test cases to go bitch
Browse files Browse the repository at this point in the history
  • Loading branch information
E-m-i-n-e-n-c-e committed Jan 22, 2025
1 parent 6cf427f commit 0725cfe
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 7 deletions.
6 changes: 4 additions & 2 deletions lib/model/message_list.dart
Original file line number Diff line number Diff line change
Expand Up @@ -487,7 +487,7 @@ class MessageListView with ChangeNotifier, _MessageSequence {
// Anchor message ID is used to fetch messages from a specific point in the list.
// It is set when the user navigates to a message list page with a specific anchor message.
int? anchorMessageId;
int? get anchorIndex => anchorMessageId != null ? findItemWithMessageId(anchorMessageId!) : null;
int get anchorIndex => anchorMessageId != null ? findItemWithMessageId(anchorMessageId!) : 0;
factory MessageListView.init(
{required PerAccountStore store, required Narrow narrow, int? anchorMessageId}) {
final view = MessageListView._(store: store, narrow: narrow, anchorMessageId: anchorMessageId);
Expand Down Expand Up @@ -591,7 +591,9 @@ class MessageListView with ChangeNotifier, _MessageSequence {
? kMessageListFetchBatchSize ~/2 // Fetch messages before and after anchor
: 0, // Don't fetch newer messages when no anchor
);
anchorMessageId ??= result.messages.last.id;
if(result.messages.isNotEmpty){
anchorMessageId ??= result.messages.last.id;
}

if (this.generation > generation) return;
store.reconcileMessages(result.messages);
Expand Down
8 changes: 4 additions & 4 deletions lib/widgets/message_list.dart
Original file line number Diff line number Diff line change
Expand Up @@ -483,8 +483,8 @@ class _MessageListState extends State<MessageList> with PerAccountStoreAwareStat
model!.addListener(_modelChanged);
await model!.fetchInitial();
setState(() {
oldItems = model!.items.sublist(0, model!.anchorIndex!+1);
newItems = model!.items.sublist(model!.anchorIndex!+1, model!.items.length);
oldItems = model!.items.sublist(0, model!.anchorIndex+1);
newItems = model!.items.sublist(model!.anchorIndex+1, model!.items.length);
});
}

Expand All @@ -498,8 +498,8 @@ class _MessageListState extends State<MessageList> with PerAccountStoreAwareStat
final previousLength = oldItems.length + newItems.length;

setState(() {
oldItems = model!.items.sublist(0, model!.anchorIndex!+1);
newItems = model!.items.sublist(model!.anchorIndex!+1, model!.items.length);
oldItems = model!.items.sublist(0, model!.anchorIndex+1);
newItems = model!.items.sublist(model!.anchorIndex+1, model!.items.length);
// The actual state lives in the [MessageListView] model.
// This method was called because that just changed.
});
Expand Down
10 changes: 9 additions & 1 deletion test/widgets/message_list_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -366,7 +366,7 @@ void main() {
await tester.tap(find.byType(ScrollToBottomButton));
await tester.pumpAndSettle();
check(isButtonVisible(tester)).equals(false);
check(scrollController.position.pixels).equals(0);
check(scrollController.position.maxScrollExtent - scrollController.position.pixels).isLessThan(36);
});
});

Expand Down Expand Up @@ -720,6 +720,10 @@ void main() {
final existingMessage = eg.streamMessage(
stream: eg.stream(), topic: 'new topic', content: 'Existing message');
prepareGetMessageResponse([existingMessage, message]);
// Prepare response for fetchInitial after move
connection.prepare(json: eg.newestGetMessagesResult(
foundOldest: true,
messages: [existingMessage, message]).toJson());
handleMessageMoveEvent([message], 'new topic');
await tester.pump(const Duration(seconds: 1));

Expand All @@ -732,6 +736,10 @@ void main() {
await setupMessageListPage(tester, narrow: narrow, messages: [message], streams: [channel]);

prepareGetMessageResponse([message]);
// Prepare response for fetchInitial after move
connection.prepare(json: eg.newestGetMessagesResult(
foundOldest: true,
messages: [message]).toJson());
handleMessageMoveEvent([message], 'new topic');
await tester.pump(const Duration(seconds: 1));

Expand Down

0 comments on commit 0725cfe

Please sign in to comment.