-
Notifications
You must be signed in to change notification settings - Fork 312
Get compose box hint texts ready for general chat #1342
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
6d6dc6d
c4f9341
3523bc0
a5af8d3
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -78,14 +78,17 @@ void main() { | |
controller = tester.state<ComposeBoxState>(find.byType(ComposeBox)).controller; | ||
} | ||
|
||
/// A [Finder] for the topic input. | ||
/// | ||
/// To enter some text, use [enterTopic]. | ||
final topicInputFinder = find.byWidgetPredicate( | ||
(widget) => widget is TextField && widget.controller is ComposeTopicController); | ||
|
||
/// Set the topic input's text to [topic], using [WidgetTester.enterText]. | ||
Future<void> enterTopic(WidgetTester tester, { | ||
required ChannelNarrow narrow, | ||
required String topic, | ||
}) async { | ||
final topicInputFinder = find.byWidgetPredicate( | ||
(widget) => widget is TextField && widget.controller is ComposeTopicController); | ||
|
||
connection.prepare(body: | ||
jsonEncode(GetStreamTopicsResult(topics: [eg.getStreamTopicsEntry()]).toJson())); | ||
await tester.enterText(topicInputFinder, topic); | ||
|
@@ -318,6 +321,85 @@ void main() { | |
}); | ||
}); | ||
|
||
group('ComposeBox hintText', () { | ||
final channel = eg.stream(); | ||
|
||
Future<void> prepare(WidgetTester tester, { | ||
required Narrow narrow, | ||
}) async { | ||
await prepareComposeBox(tester, | ||
narrow: narrow, | ||
otherUsers: [eg.otherUser, eg.thirdUser], | ||
streams: [channel]); | ||
} | ||
|
||
/// This checks the input's configured hint text without regard to whether | ||
/// it's currently visible, as it won't be if the user has entered some text. | ||
Comment on lines
+336
to
+337
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hmm, this is a bit unsatisfying because it's checking a condition the user doesn't see. Ideally we'd be checking whether the user actually sees a hint, and if so then what it is. From the thread at #1342 (comment) it sounds like getting that ideal behavior might be more complicated, though. In that case it's fine to let this be — the question of whether a hint is visible isn't critical for us to test, particularly as it's mostly the responsibility of the framework's underlying text-input code anyway. |
||
/// | ||
/// If `topicHintText` is `null`, check that the topic input is not present. | ||
void checkComposeBoxHintTexts(WidgetTester tester, { | ||
String? topicHintText, | ||
required String contentHintText, | ||
}) { | ||
if (topicHintText != null) { | ||
check(tester.widget<TextField>(topicInputFinder)) | ||
.decoration.isNotNull().hintText.equals(topicHintText); | ||
} else { | ||
check(topicInputFinder).findsNothing(); | ||
} | ||
check(tester.widget<TextField>(contentInputFinder)) | ||
.decoration.isNotNull().hintText.equals(contentHintText); | ||
} | ||
|
||
group('to ChannelNarrow', () { | ||
testWidgets('with empty topic', (tester) async { | ||
await prepare(tester, narrow: ChannelNarrow(channel.streamId)); | ||
checkComposeBoxHintTexts(tester, | ||
topicHintText: 'Topic', | ||
contentHintText: 'Message #${channel.name} > (no topic)'); | ||
}); | ||
|
||
testWidgets('with non-empty topic', (tester) async { | ||
final narrow = ChannelNarrow(channel.streamId); | ||
await prepare(tester, narrow: narrow); | ||
await enterTopic(tester, narrow: narrow, topic: 'new topic'); | ||
await tester.pump(); | ||
checkComposeBoxHintTexts(tester, | ||
topicHintText: 'Topic', | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Huh, I'm surprised this test passes. When using the app, when the topic input is empty, I see the hint text "Topic" there—but I don't see (or expect to see) hint text after I've typed something; I just see the text I've typed. Do you know why this is passing? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This helper checks There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Does it? I don't see void checkComposeBoxHintTexts(WidgetTester tester, {
String? topicHintText,
required String contentHintText,
}) {
if (topicHintText != null) {
check(find.descendant(
of: topicInputFinder, matching: find.text(topicHintText))).findsOne();
} else {
check(topicInputFinder).findsNothing();
}
check(find.descendant(
of: contentInputFinder, matching: find.text(contentHintText))).findsOne();
} There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ah! I was mistaken. It doesn't check for the controller but I was probably thinking of a different revision commenting on this. |
||
contentHintText: 'Message #${channel.name} > new topic'); | ||
}); | ||
}); | ||
|
||
testWidgets('to TopicNarrow', (tester) async { | ||
await prepare(tester, | ||
narrow: TopicNarrow(channel.streamId, TopicName('topic'))); | ||
checkComposeBoxHintTexts(tester, | ||
contentHintText: 'Message #${channel.name} > topic'); | ||
}); | ||
|
||
testWidgets('to DmNarrow with self', (tester) async { | ||
await prepare(tester, narrow: DmNarrow.withUser( | ||
eg.selfUser.userId, selfUserId: eg.selfUser.userId)); | ||
checkComposeBoxHintTexts(tester, | ||
contentHintText: 'Jot down something'); | ||
}); | ||
|
||
testWidgets('to 1:1 DmNarrow', (tester) async { | ||
await prepare(tester, narrow: DmNarrow.withUser( | ||
eg.otherUser.userId, selfUserId: eg.selfUser.userId)); | ||
checkComposeBoxHintTexts(tester, | ||
contentHintText: 'Message @${eg.otherUser.fullName}'); | ||
}); | ||
|
||
testWidgets('to group DmNarrow', (tester) async { | ||
await prepare(tester, narrow: DmNarrow.withOtherUsers( | ||
[eg.otherUser.userId, eg.thirdUser.userId], | ||
selfUserId: eg.selfUser.userId)); | ||
checkComposeBoxHintTexts(tester, | ||
contentHintText: 'Message group'); | ||
}); | ||
}); | ||
|
||
group('ComposeBox textCapitalization', () { | ||
void checkComposeBoxTextFields(WidgetTester tester, { | ||
required bool expectTopicTextField, | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: I think this is a case where much of the information in the commit message is also relevant to understanding the resulting code (not only to understanding its history). So: