39 lines
1.2 KiB
Dart
39 lines
1.2 KiB
Dart
import 'package:flutter_test/flutter_test.dart';
|
|
import 'package:ikar/backend/modules/chats.dart';
|
|
import 'package:ikar/frontend/screens/chats/chat_unread_count.dart';
|
|
|
|
CachedChat chat(int id, int unread) => CachedChat(
|
|
id: id,
|
|
accountId: 1,
|
|
type: 'DIALOG',
|
|
unreadCount: unread,
|
|
lastEventTime: 0,
|
|
cachedAt: 0,
|
|
dontDisturbUntil: ChatsModule.muteOff,
|
|
isOnline: false,
|
|
seenTime: 0,
|
|
participants: const {},
|
|
);
|
|
|
|
void main() {
|
|
test('one chat with multiple unread messages counts as one', () {
|
|
expect(countUnreadChats([chat(1, 20)]), 1);
|
|
});
|
|
test('each unread chat contributes once', () {
|
|
expect(countUnreadChats([chat(1, 1), chat(2, 8), chat(3, 99)]), 3);
|
|
});
|
|
test('read chats do not contribute and an empty list is zero', () {
|
|
expect(countUnreadChats([chat(1, 0), chat(2, 7), chat(3, 0)]), 1);
|
|
expect(countUnreadChats([chat(1, 0), chat(2, 0)]), 0);
|
|
expect(countUnreadChats([]), 0);
|
|
});
|
|
test('reading a chat subtracts one, regardless of messages read', () {
|
|
final chats = [chat(1, 50), chat(2, 4)];
|
|
expect(countUnreadChats(chats), 2);
|
|
chats[0] = chats[0].copyWith(unreadCount: 0);
|
|
expect(countUnreadChats(chats), 1);
|
|
chats[1] = chats[1].copyWith(unreadCount: 0);
|
|
expect(countUnreadChats(chats), 0);
|
|
});
|
|
}
|