@@ -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,85 @@ 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+ /// This checks the input's configured hint text without regard to whether
337+ /// it's currently visible, as it won't be if the user has entered some text.
338+ ///
339+ /// If `topicHintText` is `null` , check that the topic input is not present.
340+ void checkComposeBoxHintTexts (WidgetTester tester, {
341+ String ? topicHintText,
342+ required String contentHintText,
343+ }) {
344+ if (topicHintText != null ) {
345+ check (tester.widget <TextField >(topicInputFinder))
346+ .decoration.isNotNull ().hintText.equals (topicHintText);
347+ } else {
348+ check (topicInputFinder).findsNothing ();
349+ }
350+ check (tester.widget <TextField >(contentInputFinder))
351+ .decoration.isNotNull ().hintText.equals (contentHintText);
352+ }
353+
354+ group ('to ChannelNarrow' , () {
355+ testWidgets ('with empty topic' , (tester) async {
356+ await prepare (tester, narrow: ChannelNarrow (channel.streamId));
357+ checkComposeBoxHintTexts (tester,
358+ topicHintText: 'Topic' ,
359+ contentHintText: 'Message #${channel .name } > (no topic)' );
360+ });
361+
362+ testWidgets ('with non-empty topic' , (tester) async {
363+ final narrow = ChannelNarrow (channel.streamId);
364+ await prepare (tester, narrow: narrow);
365+ await enterTopic (tester, narrow: narrow, topic: 'new topic' );
366+ await tester.pump ();
367+ checkComposeBoxHintTexts (tester,
368+ topicHintText: 'Topic' ,
369+ contentHintText: 'Message #${channel .name } > new topic' );
370+ });
371+ });
372+
373+ testWidgets ('to TopicNarrow' , (tester) async {
374+ await prepare (tester,
375+ narrow: TopicNarrow (channel.streamId, TopicName ('topic' )));
376+ checkComposeBoxHintTexts (tester,
377+ contentHintText: 'Message #${channel .name } > topic' );
378+ });
379+
380+ testWidgets ('to DmNarrow with self' , (tester) async {
381+ await prepare (tester, narrow: DmNarrow .withUser (
382+ eg.selfUser.userId, selfUserId: eg.selfUser.userId));
383+ checkComposeBoxHintTexts (tester,
384+ contentHintText: 'Jot down something' );
385+ });
386+
387+ testWidgets ('to 1:1 DmNarrow' , (tester) async {
388+ await prepare (tester, narrow: DmNarrow .withUser (
389+ eg.otherUser.userId, selfUserId: eg.selfUser.userId));
390+ checkComposeBoxHintTexts (tester,
391+ contentHintText: 'Message @${eg .otherUser .fullName }' );
392+ });
393+
394+ testWidgets ('to group DmNarrow' , (tester) async {
395+ await prepare (tester, narrow: DmNarrow .withOtherUsers (
396+ [eg.otherUser.userId, eg.thirdUser.userId],
397+ selfUserId: eg.selfUser.userId));
398+ checkComposeBoxHintTexts (tester,
399+ contentHintText: 'Message group' );
400+ });
401+ });
402+
321403 group ('ComposeBox textCapitalization' , () {
322404 void checkComposeBoxTextFields (WidgetTester tester, {
323405 required bool expectTopicTextField,
0 commit comments