Skip to content

Commit c4fee15

Browse files
committed
actions_test [nfc]: Create updateMessageFlagsStartingFromAnchor test group
1 parent f37e338 commit c4fee15

File tree

1 file changed

+61
-18
lines changed

1 file changed

+61
-18
lines changed

test/widgets/actions_test.dart

Lines changed: 61 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,47 @@ 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+
final narrow = TopicNarrow.ofMessage(eg.streamMessage());
299+
final apiNarrow = narrow.apiEncode()..add(ApiNarrowIsUnread());
300+
301+
Future<bool> invokeUpdateMessageFlagsStartingFromAnchor() =>
302+
updateMessageFlagsStartingFromAnchor(
303+
context: context,
304+
apiNarrow: apiNarrow,
305+
op: UpdateMessageFlagsOp.add,
306+
flag: MessageFlag.read,
307+
includeAnchor: false,
308+
startingAnchor: AnchorCode.oldest,
309+
onCompletedMessage: onCompletedMessage,
310+
onFailedTitle: onFailedTitle,
311+
progressMessage: progressMessage);
312+
313+
testWidgets('smoke test', (tester) async {
314+
await prepare(tester);
315+
connection.prepare(json: UpdateMessageFlagsForNarrowResult(
316+
processedCount: 11, updatedCount: 3,
317+
firstProcessedId: 1, lastProcessedId: 1980,
318+
foundOldest: true, foundNewest: true).toJson());
319+
final didPass = invokeUpdateMessageFlagsStartingFromAnchor();
320+
await tester.pump(Duration.zero);
321+
check(connection.lastRequest).isA<http.Request>()
322+
..method.equals('POST')
323+
..url.path.equals('/api/v1/messages/flags/narrow')
324+
..bodyFields.deepEquals({
325+
'anchor': 'oldest',
326+
'include_anchor': 'false',
327+
'num_before': '0',
328+
'num_after': '1000',
329+
'narrow': jsonEncode(apiNarrow),
330+
'op': 'add',
331+
'flag': 'read',
332+
});
333+
check(await didPass).isTrue();
334+
});
335+
});
293336
}

0 commit comments

Comments
 (0)