@@ -359,10 +359,12 @@ void main() {
359
359
Future <void > prepare ({
360
360
List <User > users = const [],
361
361
List <RecentDmConversation > dmConversations = const [],
362
+ List <Message > messages = const [],
362
363
}) async {
363
364
store = eg.store (initialSnapshot: eg.initialSnapshot (
364
365
recentPrivateConversations: dmConversations));
365
366
await store.addUsers (users);
367
+ await store.addMessages (messages);
366
368
}
367
369
368
370
group ('MentionAutocompleteView.compareNullable' , () {
@@ -379,6 +381,62 @@ void main() {
379
381
380
382
test ('both of [a] and [b] are null' , () async {
381
383
check (MentionAutocompleteView .compareNullable (null , null )).equals (0 );
384
+ check (MentionAutocompleteView .compareNullable (null , null )).equals (0 );
385
+ });
386
+ });
387
+
388
+ group ('MentionAutocompleteView.compareByRecency' , () {
389
+ final userA = eg.otherUser;
390
+ final userB = eg.thirdUser;
391
+ final stream = eg.stream ();
392
+ const topic1 = 'topic1' ;
393
+ const topic2 = 'topic2' ;
394
+
395
+ Message message (User sender, String topic) {
396
+ return eg.streamMessage (
397
+ sender: sender,
398
+ stream: stream,
399
+ topic: topic,
400
+ );
401
+ }
402
+
403
+ int compareAB ({required String ? topic}) {
404
+ return MentionAutocompleteView .compareByRecency (userA, userB,
405
+ streamId: stream.streamId,
406
+ topic: topic,
407
+ store: store,
408
+ );
409
+ }
410
+
411
+ test ('prioritizes the user with more recent activity in the topic' , () async {
412
+ await prepare (messages: [
413
+ message (userA, topic1),
414
+ message (userB, topic1),
415
+ ]);
416
+ check (compareAB (topic: topic1)).isGreaterThan (0 );
417
+ });
418
+
419
+ test ('prioritizes the user with more recent activity in the stream '
420
+ 'if there is no activity in the topic from both users' , () async {
421
+ await prepare (messages: [
422
+ message (userA, topic1),
423
+ message (userB, topic1),
424
+ ]);
425
+ check (compareAB (topic: topic2)).isGreaterThan (0 );
426
+ });
427
+
428
+ test ('prioritizes the user with more recent activity in the stream '
429
+ 'if there is no topic provided' , () async {
430
+ await prepare (messages: [
431
+ message (userA, topic1),
432
+ message (userB, topic2),
433
+ ]);
434
+ check (compareAB (topic: null )).isGreaterThan (0 );
435
+ });
436
+
437
+ test ('prioritizes none of the users if there is no activity in the stream from both users' , () async {
438
+ await prepare (messages: []);
439
+ check (compareAB (topic: null )).equals (0 );
382
440
});
383
441
});
384
442
@@ -436,8 +494,11 @@ void main() {
436
494
});
437
495
438
496
group ('autocomplete suggests relevant users in the intended order' , () {
439
- // The order should be:
440
- // 1. Users most recent in the DM conversations
497
+ // 1. Users most recent in the current topic/stream.
498
+ // 2. Users most recent in the DM conversations.
499
+
500
+ final stream = eg.stream ();
501
+ const topic = 'topic' ;
441
502
442
503
Future <void > checkResultsIn (Narrow narrow, {required List <int > expected}) async {
443
504
final users = [
@@ -454,7 +515,15 @@ void main() {
454
515
RecentDmConversation (userIds: [0 , 1 ], maxMessageId: 100 ),
455
516
];
456
517
457
- await prepare (users: users, dmConversations: dmConversations);
518
+ final messages = [
519
+ eg.streamMessage (sender: users[0 ], stream: stream, topic: topic),
520
+ eg.streamMessage (sender: users[4 ], stream: stream),
521
+ ];
522
+
523
+ await prepare (
524
+ users: users,
525
+ dmConversations: dmConversations,
526
+ messages: messages);
458
527
final view = MentionAutocompleteView .init (store: store, narrow: narrow);
459
528
460
529
bool done = false ;
@@ -468,11 +537,11 @@ void main() {
468
537
}
469
538
470
539
test ('StreamNarrow' , () async {
471
- await checkResultsIn (const StreamNarrow (1 ), expected: [3 , 0 , 1 , 2 , 4 ]);
540
+ await checkResultsIn (StreamNarrow (stream.streamId ), expected: [4 , 0 , 3 , 1 , 2 ]);
472
541
});
473
542
474
543
test ('TopicNarrow' , () async {
475
- await checkResultsIn (const TopicNarrow (1 , ' topic' ), expected: [3 , 0 , 1 , 2 , 4 ]);
544
+ await checkResultsIn (TopicNarrow (stream.streamId, topic), expected: [0 , 4 , 3 , 1 , 2 ]);
476
545
});
477
546
478
547
test ('DmNarrow' , () async {
0 commit comments