Skip to content

Commit

Permalink
compose test: Test ComposeBox directly, without MessageListPage
Browse files Browse the repository at this point in the history
This lets us simplify the setup significantly.
  • Loading branch information
gnprice committed Jan 25, 2024
1 parent cf31b9e commit 3c91597
Showing 1 changed file with 7 additions and 26 deletions.
33 changes: 7 additions & 26 deletions test/widgets/compose_box_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,10 @@ import 'package:checks/checks.dart';
import 'package:flutter/material.dart';
import 'package:flutter_gen/gen_l10n/zulip_localizations.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:zulip/api/route/messages.dart';
import 'package:zulip/model/narrow.dart';
import 'package:zulip/widgets/compose_box.dart';
import 'package:zulip/widgets/message_list.dart';
import 'package:zulip/widgets/store.dart';

import '../api/fake_api.dart';
import '../example_data.dart' as eg;
import '../flutter_checks.dart';
import '../model/binding.dart';
Expand Down Expand Up @@ -119,42 +116,26 @@ void main() {
});

group('ComposeBox textCapitalization', () {
final message = eg.streamMessage();
late GlobalKey<ComposeBoxController> controllerKey;

Future<void> prepareComposeBox(WidgetTester tester, Narrow narrow) async {
addTearDown(testBinding.reset);
await testBinding.globalStore.add(eg.selfAccount, eg.initialSnapshot(
streams: [eg.stream(streamId: message.streamId)],
));
final store = await testBinding.globalStore.perAccount(eg.selfAccount.id);
final connection = store.connection as FakeApiConnection;

// prepare message list data
connection.prepare(json: GetMessagesResult(
anchor: message.id,
foundNewest: true,
foundOldest: true,
foundAnchor: true,
historyLimited: false,
messages: [message],
).toJson());
await testBinding.globalStore.add(eg.selfAccount, eg.initialSnapshot());

controllerKey = GlobalKey();
await tester.pumpWidget(
MaterialApp(
localizationsDelegates: ZulipLocalizations.localizationsDelegates,
supportedLocales: ZulipLocalizations.supportedLocales,
home: GlobalStoreWidget(
child: PerAccountStoreWidget(
accountId: eg.selfAccount.id,
child: MessageListPage(narrow: narrow)))));

// global store, per-account store, and message list get loaded
child: ComposeBox(controllerKey: controllerKey, narrow: narrow)))));
await tester.pumpAndSettle();
}

void checkComposeBoxTextFields(WidgetTester tester, {required bool expectTopicTextField}) {
final composeBoxController = tester.widget<ComposeBox>(find.byType(ComposeBox))
.controllerKey!.currentState!;
final composeBoxController = controllerKey.currentState!;

final topicTextField = tester.widgetList<TextField>(find.byWidgetPredicate(
(widget) => widget is TextField
Expand All @@ -174,12 +155,12 @@ void main() {
}

testWidgets('_StreamComposeBox', (tester) async {
await prepareComposeBox(tester, StreamNarrow(message.streamId));
await prepareComposeBox(tester, StreamNarrow(eg.stream().streamId));
checkComposeBoxTextFields(tester, expectTopicTextField: true);
});

testWidgets('_FixedDestinationComposeBox', (tester) async {
await prepareComposeBox(tester, TopicNarrow.ofMessage(message));
await prepareComposeBox(tester, TopicNarrow.ofMessage(eg.streamMessage()));
checkComposeBoxTextFields(tester, expectTopicTextField: false);
});
});
Expand Down

0 comments on commit 3c91597

Please sign in to comment.