@@ -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,86 @@ 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+ /// Check if the topic and content inputs use the expected hint texts.
337+ ///
338+ /// If `topicHintText` is `null` , check that the topic input is not present.
339+ ///
340+ /// This does not check if the hint texts are present but invisible.
341+ void checkComposeBoxHintTexts (WidgetTester tester, {
342+ String ? topicHintText,
343+ required String contentHintText,
344+ }) {
345+ if (topicHintText != null ) {
346+ check (find.descendant (
347+ of: topicInputFinder, matching: find.text (topicHintText))).findsOne ();
348+ } else {
349+ check (topicInputFinder).findsNothing ();
350+ }
351+ check (find.descendant (
352+ of: contentInputFinder, matching: find.text (contentHintText))).findsOne ();
353+ }
354+
355+ group ('to ChannelNarrow' , () {
356+ testWidgets ('with empty topic' , (tester) async {
357+ await prepare (tester, narrow: ChannelNarrow (channel.streamId));
358+ checkComposeBoxHintTexts (tester,
359+ topicHintText: 'Topic' ,
360+ contentHintText: 'Message #${channel .name } > (no topic)' );
361+ });
362+
363+ testWidgets ('with non-empty topic' , (tester) async {
364+ final narrow = ChannelNarrow (channel.streamId);
365+ await prepare (tester, narrow: narrow);
366+ await enterTopic (tester, narrow: narrow, topic: 'new topic' );
367+ await tester.pump ();
368+ checkComposeBoxHintTexts (tester,
369+ topicHintText: 'Topic' ,
370+ contentHintText: 'Message #${channel .name } > new topic' );
371+ });
372+ });
373+
374+ testWidgets ('to TopicNarrow' , (tester) async {
375+ await prepare (tester,
376+ narrow: TopicNarrow (channel.streamId, TopicName ('topic' )));
377+ checkComposeBoxHintTexts (tester,
378+ contentHintText: 'Message #${channel .name } > topic' );
379+ });
380+
381+ testWidgets ('to DmNarrow with self' , (tester) async {
382+ await prepare (tester, narrow: DmNarrow .withUser (
383+ eg.selfUser.userId, selfUserId: eg.selfUser.userId));
384+ checkComposeBoxHintTexts (tester,
385+ contentHintText: 'Jot down something' );
386+ });
387+
388+ testWidgets ('to 1:1 DmNarrow' , (tester) async {
389+ await prepare (tester, narrow: DmNarrow .withUser (
390+ eg.otherUser.userId, selfUserId: eg.selfUser.userId));
391+ checkComposeBoxHintTexts (tester,
392+ contentHintText: 'Message @${eg .otherUser .fullName }' );
393+ });
394+
395+ testWidgets ('to group DmNarrow' , (tester) async {
396+ await prepare (tester, narrow: DmNarrow .withOtherUsers (
397+ [eg.otherUser.userId, eg.thirdUser.userId],
398+ selfUserId: eg.selfUser.userId));
399+ checkComposeBoxHintTexts (tester,
400+ contentHintText: 'Message group' );
401+ });
402+ });
403+
321404 group ('ComposeBox textCapitalization' , () {
322405 void checkComposeBoxTextFields (WidgetTester tester, {
323406 required bool expectTopicTextField,
0 commit comments