@@ -146,6 +146,53 @@ void main() {
146
146
});
147
147
});
148
148
149
+ group ('count helpers' , () {
150
+ test ('countInAllMessagesNarrow' , () {
151
+ final stream1 = eg.stream ();
152
+ final stream2 = eg.stream ();
153
+ prepare ();
154
+ fillWithMessages ([
155
+ eg.streamMessage (stream: stream1, topic: 'a' , flags: []),
156
+ eg.streamMessage (stream: stream1, topic: 'b' , flags: []),
157
+ eg.streamMessage (stream: stream1, topic: 'b' , flags: []),
158
+ eg.streamMessage (stream: stream2, topic: 'c' , flags: []),
159
+ eg.dmMessage (from: eg.otherUser, to: [eg.selfUser], flags: []),
160
+ eg.dmMessage (from: eg.thirdUser, to: [eg.selfUser], flags: []),
161
+ ]);
162
+ check (model.countInAllMessagesNarrow ()).equals (6 );
163
+ });
164
+
165
+ test ('countInStreamNarrow' , () {
166
+ final stream = eg.stream ();
167
+ prepare ();
168
+ fillWithMessages ([
169
+ eg.streamMessage (stream: stream, topic: 'a' , flags: []),
170
+ eg.streamMessage (stream: stream, topic: 'a' , flags: []),
171
+ eg.streamMessage (stream: stream, topic: 'b' , flags: []),
172
+ eg.streamMessage (stream: stream, topic: 'b' , flags: []),
173
+ eg.streamMessage (stream: stream, topic: 'b' , flags: []),
174
+ ]);
175
+ check (model.countInStreamNarrow (stream.streamId)).equals (5 );
176
+ });
177
+
178
+ test ('countInTopicNarrow' , () {
179
+ final stream = eg.stream ();
180
+ prepare ();
181
+ fillWithMessages (List .generate (7 , (i) => eg.streamMessage (
182
+ stream: stream, topic: 'a' , flags: [])));
183
+ check (model.countInTopicNarrow (stream.streamId, 'a' )).equals (7 );
184
+ });
185
+
186
+ test ('countInDmNarrow' , () {
187
+ prepare ();
188
+ fillWithMessages (List .generate (5 , (i) => eg.dmMessage (
189
+ from: eg.otherUser, to: [eg.selfUser], flags: [])));
190
+ final narrow = DmNarrow .withUser (
191
+ eg.otherUser.userId, selfUserId: eg.selfUser.userId);
192
+ check (model.countInDmNarrow (narrow)).equals (5 );
193
+ });
194
+ });
195
+
149
196
group ('handleMessageEvent' , () {
150
197
for (final (isUnread, isStream, isDirectMentioned, isWildcardMentioned) in [
151
198
(true , true , true , true ),
0 commit comments