Skip to content

Commit 92facbd

Browse files
committed
compose_box test: Enter topic with a helper
A request looking up topics within a channel is sent whenever the topic input gets edited. Previously, the response to this request was prepared in a general helper. We move it to a more focused helper to improve reusability, and to simplify the general helper, because only two test cases currently need this feature. This also includes a brief check that consumes the reqeust, confirming that the request is indeed the expected one. Signed-off-by: Zixuan James Li <[email protected]>
1 parent b4a61d8 commit 92facbd

File tree

1 file changed

+21
-9
lines changed

1 file changed

+21
-9
lines changed

test/widgets/compose_box_test.dart

+21-9
Original file line numberDiff line numberDiff line change
@@ -42,11 +42,6 @@ void main() {
4242
await store.addUsers([eg.selfUser, ...users]);
4343
connection = store.connection as FakeApiConnection;
4444

45-
if (narrow is ChannelNarrow) {
46-
// Ensure topics are loaded before testing actual logic.
47-
connection.prepare(body:
48-
jsonEncode(GetStreamTopicsResult(topics: [eg.getStreamTopicsEntry()]).toJson()));
49-
}
5045
final controllerKey = GlobalKey<ComposeBoxController>();
5146
await tester.pumpWidget(TestZulipApp(accountId: eg.selfAccount.id,
5247
child: ComposeBox(controllerKey: controllerKey, narrow: narrow)));
@@ -55,6 +50,21 @@ void main() {
5550
return controllerKey;
5651
}
5752

53+
Future<void> enterTopic(WidgetTester tester, {
54+
required ChannelNarrow narrow,
55+
required String topic,
56+
}) async {
57+
final topicInputFinder = find.byWidgetPredicate(
58+
(widget) => widget is TextField && widget.controller is ComposeTopicController);
59+
60+
connection.prepare(body:
61+
jsonEncode(GetStreamTopicsResult(topics: [eg.getStreamTopicsEntry()]).toJson()));
62+
await tester.enterText(topicInputFinder, topic);
63+
check(connection.takeRequests()).single
64+
..method.equals('GET')
65+
..url.path.equals('/api/v1/users/me/${narrow.streamId}/topics');
66+
}
67+
5868
group('ComposeContentController', () {
5969
group('insertPadded', () {
6070
// Like `parseMarkedText` in test/model/autocomplete_test.dart,
@@ -271,12 +281,13 @@ void main() {
271281
TypingNotifier.debugEnable = false;
272282
addTearDown(TypingNotifier.debugReset);
273283

274-
final controllerKey = await prepareComposeBox(tester, narrow: ChannelNarrow(eg.stream().streamId));
284+
final narrow = ChannelNarrow(eg.stream().streamId);
285+
final controllerKey = await prepareComposeBox(tester, narrow: narrow);
275286
final composeBoxController = controllerKey.currentState!;
276287

277288
// (When we check that the send button looks disabled, it should be because
278289
// the file is uploading, not a pre-existing reason.)
279-
composeBoxController.topicController!.value = const TextEditingValue(text: 'some topic');
290+
await enterTopic(tester, narrow: narrow, topic: 'some topic');
280291
composeBoxController.contentController.value = const TextEditingValue(text: 'see image: ');
281292
await tester.pump();
282293
checkAppearsLoading(tester, false);
@@ -330,12 +341,13 @@ void main() {
330341
TypingNotifier.debugEnable = false;
331342
addTearDown(TypingNotifier.debugReset);
332343

333-
final controllerKey = await prepareComposeBox(tester, narrow: ChannelNarrow(eg.stream().streamId));
344+
final narrow = ChannelNarrow(eg.stream().streamId);
345+
final controllerKey = await prepareComposeBox(tester, narrow: narrow);
334346
final composeBoxController = controllerKey.currentState!;
335347

336348
// (When we check that the send button looks disabled, it should be because
337349
// the file is uploading, not a pre-existing reason.)
338-
composeBoxController.topicController!.value = const TextEditingValue(text: 'some topic');
350+
await enterTopic(tester, narrow: narrow, topic: 'some topic');
339351
composeBoxController.contentController.value = const TextEditingValue(text: 'see image: ');
340352
await tester.pump();
341353
checkAppearsLoading(tester, false);

0 commit comments

Comments
 (0)