Skip to content

Commit 337451a

Browse files
committed
actions_test: Create updateMessageFlagsStartingFromAnchor test group
1 parent 7594536 commit 337451a

File tree

1 file changed

+52
-18
lines changed

1 file changed

+52
-18
lines changed

test/widgets/actions_test.dart

Lines changed: 52 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -24,27 +24,27 @@ import 'test_app.dart';
2424
void main() {
2525
TestZulipBinding.ensureInitialized();
2626

27-
group('markNarrowAsRead', () {
28-
late PerAccountStore store;
29-
late FakeApiConnection connection;
30-
late BuildContext context;
27+
late PerAccountStore store;
28+
late FakeApiConnection connection;
29+
late BuildContext context;
3130

32-
Future<void> prepare(WidgetTester tester, {
33-
UnreadMessagesSnapshot? unreadMsgs,
34-
}) async {
35-
addTearDown(testBinding.reset);
36-
await testBinding.globalStore.add(eg.selfAccount, eg.initialSnapshot(
37-
unreadMsgs: unreadMsgs));
38-
store = await testBinding.globalStore.perAccount(eg.selfAccount.id);
39-
connection = store.connection as FakeApiConnection;
31+
Future<void> prepare(WidgetTester tester, {
32+
UnreadMessagesSnapshot? unreadMsgs,
33+
}) async {
34+
addTearDown(testBinding.reset);
35+
await testBinding.globalStore.add(eg.selfAccount, eg.initialSnapshot(
36+
unreadMsgs: unreadMsgs));
37+
store = await testBinding.globalStore.perAccount(eg.selfAccount.id);
38+
connection = store.connection as FakeApiConnection;
4039

41-
await tester.pumpWidget(TestZulipApp(accountId: eg.selfAccount.id,
42-
child: const Scaffold(body: Placeholder())));
43-
// global store, per-account store get loaded
44-
await tester.pumpAndSettle();
45-
context = tester.element(find.byType(Placeholder));
46-
}
40+
await tester.pumpWidget(TestZulipApp(accountId: eg.selfAccount.id,
41+
child: const Scaffold(body: Placeholder())));
42+
// global store, per-account store get loaded
43+
await tester.pumpAndSettle();
44+
context = tester.element(find.byType(Placeholder));
45+
}
4746

47+
group('markNarrowAsRead', () {
4848
testWidgets('smoke test on modern server', (tester) async {
4949
final narrow = TopicNarrow.ofMessage(eg.streamMessage());
5050
await prepare(tester);
@@ -290,4 +290,38 @@ void main() {
290290
expectedMessage: 'NetworkException: Oops (ClientException: Oops)');
291291
});
292292
});
293+
294+
group('updateMessageFlagsStartingFromAnchor', () {
295+
String onCompletedMessage(int count) => 'onCompletedMessage($count)';
296+
const progressMessage = 'progressMessage';
297+
const onFailedTitle = 'onFailedTitle';
298+
299+
testWidgets('smoke test', (tester) async {
300+
final narrow = TopicNarrow.ofMessage(eg.streamMessage());
301+
final apiNarrow = narrow.apiEncode()..add(ApiNarrowIsUnread());
302+
await prepare(tester);
303+
connection.prepare(json: UpdateMessageFlagsForNarrowResult(
304+
processedCount: 11, updatedCount: 3,
305+
firstProcessedId: 1, lastProcessedId: 1980,
306+
foundOldest: true, foundNewest: true).toJson());
307+
final didPass = updateMessageFlagsStartingFromAnchor(
308+
context: context, apiNarrow: apiNarrow, op: UpdateMessageFlagsOp.add, flag: MessageFlag.read,
309+
includeAnchor: false, startingAnchor: AnchorCode.oldest, onCompletedMessage: onCompletedMessage,
310+
onFailedTitle: onFailedTitle, progressMessage: progressMessage);
311+
await tester.pump(Duration.zero);
312+
check(connection.lastRequest).isA<http.Request>()
313+
..method.equals('POST')
314+
..url.path.equals('/api/v1/messages/flags/narrow')
315+
..bodyFields.deepEquals({
316+
'anchor': 'oldest',
317+
'include_anchor': 'false',
318+
'num_before': '0',
319+
'num_after': '1000',
320+
'narrow': jsonEncode(apiNarrow),
321+
'op': 'add',
322+
'flag': 'read',
323+
});
324+
check(await didPass).isTrue();
325+
});
326+
});
293327
}

0 commit comments

Comments
 (0)