@@ -78,14 +78,17 @@ void main() {
7878 controller = tester.state <ComposeBoxState >(find.byType (ComposeBox )).controller;
7979 }
8080
81+ /// A [Finder] for the topic input.
82+ ///
83+ /// To enter some text, use [enterTopic] .
84+ final topicInputFinder = find.byWidgetPredicate (
85+ (widget) => widget is TextField && widget.controller is ComposeTopicController );
86+
8187 /// Set the topic input's text to [topic] , using [WidgetTester.enterText] .
8288 Future <void > enterTopic (WidgetTester tester, {
8389 required ChannelNarrow narrow,
8490 required String topic,
8591 }) async {
86- final topicInputFinder = find.byWidgetPredicate (
87- (widget) => widget is TextField && widget.controller is ComposeTopicController );
88-
8992 connection.prepare (body:
9093 jsonEncode (GetStreamTopicsResult (topics: [eg.getStreamTopicsEntry ()]).toJson ()));
9194 await tester.enterText (topicInputFinder, topic);
@@ -318,6 +321,81 @@ void main() {
318321 });
319322 });
320323
324+ group ('ComposeBox hintText' , () {
325+ final channel = eg.stream ();
326+
327+ Future <void > prepare (WidgetTester tester, {
328+ required Narrow narrow,
329+ }) async {
330+ await prepareComposeBox (tester,
331+ narrow: narrow,
332+ otherUsers: [eg.otherUser, eg.thirdUser],
333+ streams: [channel]);
334+ }
335+
336+ void checkComposeBoxHintTexts (WidgetTester tester, {
337+ String ? topicHintText,
338+ required String contentHintText,
339+ }) {
340+ if (topicHintText != null ) {
341+ check (find.descendant (
342+ of: topicInputFinder, matching: find.text (topicHintText))).findsOne ();
343+ } else {
344+ check (topicInputFinder).findsNothing ();
345+ }
346+ check (find.descendant (
347+ of: contentInputFinder, matching: find.text (contentHintText))).findsOne ();
348+ }
349+
350+ group ('to ChannelNarrow' , () {
351+ testWidgets ('with empty topic' , (tester) async {
352+ await prepare (tester, narrow: ChannelNarrow (channel.streamId));
353+ checkComposeBoxHintTexts (tester,
354+ topicHintText: 'Topic' ,
355+ contentHintText: 'Message #${channel .name } > (no topic)' );
356+ });
357+
358+ testWidgets ('with non-empty topic' , (tester) async {
359+ final narrow = ChannelNarrow (channel.streamId);
360+ await prepare (tester, narrow: narrow);
361+ await enterTopic (tester, narrow: narrow, topic: 'new topic' );
362+ await tester.pump ();
363+ checkComposeBoxHintTexts (tester,
364+ topicHintText: 'Topic' ,
365+ contentHintText: 'Message #${channel .name } > new topic' );
366+ });
367+ });
368+
369+ testWidgets ('to TopicNarrow' , (tester) async {
370+ await prepare (tester,
371+ narrow: TopicNarrow (channel.streamId, TopicName ('topic' )));
372+ checkComposeBoxHintTexts (tester,
373+ contentHintText: 'Message #${channel .name } > topic' );
374+ });
375+
376+ testWidgets ('to DmNarrow with self' , (tester) async {
377+ await prepare (tester, narrow: DmNarrow .withUser (
378+ eg.selfUser.userId, selfUserId: eg.selfUser.userId));
379+ checkComposeBoxHintTexts (tester,
380+ contentHintText: 'Jot down something' );
381+ });
382+
383+ testWidgets ('to 1:1 DmNarrow' , (tester) async {
384+ await prepare (tester, narrow: DmNarrow .withUser (
385+ eg.otherUser.userId, selfUserId: eg.selfUser.userId));
386+ checkComposeBoxHintTexts (tester,
387+ contentHintText: 'Message @${eg .otherUser .fullName }' );
388+ });
389+
390+ testWidgets ('to group DmNarrow' , (tester) async {
391+ await prepare (tester, narrow: DmNarrow .withOtherUsers (
392+ [eg.otherUser.userId, eg.thirdUser.userId],
393+ selfUserId: eg.selfUser.userId));
394+ checkComposeBoxHintTexts (tester,
395+ contentHintText: 'Message group' );
396+ });
397+ });
398+
321399 group ('ComposeBox textCapitalization' , () {
322400 void checkComposeBoxTextFields (WidgetTester tester, {
323401 required bool expectTopicTextField,
0 commit comments