Merge: Ctrl+1-9 focuses the opened chat's composer
This commit is contained in:
@@ -82,6 +82,20 @@ Future<void> _ctrl(WidgetTester tester, LogicalKeyboardKey digit) async {
|
||||
|
||||
Finder _thread(String id) => find.byKey(ValueKey('chat-thread-$id'));
|
||||
|
||||
EditableText _composer(WidgetTester tester, String id) =>
|
||||
tester.widget<EditableText>(
|
||||
find.descendant(
|
||||
of: find.byKey(ValueKey('chat-composer-$id')),
|
||||
matching: find.byType(EditableText),
|
||||
),
|
||||
);
|
||||
|
||||
bool _composerFocused(WidgetTester tester, String id) =>
|
||||
_composer(tester, id).focusNode.hasPrimaryFocus;
|
||||
|
||||
String _composerText(WidgetTester tester, String id) =>
|
||||
_composer(tester, id).controller.text;
|
||||
|
||||
void main() {
|
||||
testWidgets('starred chats lead the list alphabetically', (tester) async {
|
||||
await _pumpShell(tester, const Size(1280, 800));
|
||||
@@ -122,6 +136,51 @@ void main() {
|
||||
await tester.pumpWidget(const SizedBox.shrink());
|
||||
});
|
||||
|
||||
testWidgets('Ctrl+N puts the keyboard in the opened chat\'s composer', (
|
||||
tester,
|
||||
) async {
|
||||
await _pumpShell(tester, const Size(1280, 800));
|
||||
// A tap opens a chat without moving focus into its composer.
|
||||
await tester.tap(find.byKey(const Key('chat-row-r')));
|
||||
await tester.pumpAndSettle();
|
||||
expect(_thread('r'), findsOneWidget);
|
||||
expect(_composerFocused(tester, 'r'), isFalse);
|
||||
|
||||
// From the keyboard another chat opens with its composer focused, and
|
||||
// typing lands there at once.
|
||||
await _ctrl(tester, LogicalKeyboardKey.digit2);
|
||||
expect(_thread('z'), findsOneWidget);
|
||||
expect(_composerFocused(tester, 'z'), isTrue);
|
||||
// The text connection the focused field opened receives the typing.
|
||||
tester.testTextInput.enterText('h');
|
||||
await tester.pump();
|
||||
expect(_composerText(tester, 'z'), 'h');
|
||||
|
||||
// The chat already open: focus returns from elsewhere to its composer.
|
||||
FocusManager.instance.primaryFocus?.unfocus();
|
||||
await tester.pump();
|
||||
expect(_composerFocused(tester, 'z'), isFalse);
|
||||
await _ctrl(tester, LogicalKeyboardKey.digit2);
|
||||
expect(_composerFocused(tester, 'z'), isTrue);
|
||||
|
||||
// A later tap on another row leaves focus alone.
|
||||
await tester.tap(find.byKey(const Key('chat-row-a')));
|
||||
await tester.pumpAndSettle();
|
||||
expect(_thread('a'), findsOneWidget);
|
||||
expect(_composerFocused(tester, 'a'), isFalse);
|
||||
await tester.pumpWidget(const SizedBox.shrink());
|
||||
});
|
||||
|
||||
testWidgets('Ctrl+N focuses the composer of the chat page on a phone', (
|
||||
tester,
|
||||
) async {
|
||||
await _pumpShell(tester, const Size(390, 844));
|
||||
await _ctrl(tester, LogicalKeyboardKey.digit3);
|
||||
expect(_thread('r'), findsOneWidget);
|
||||
expect(_composerFocused(tester, 'r'), isTrue);
|
||||
await tester.pumpWidget(const SizedBox.shrink());
|
||||
});
|
||||
|
||||
testWidgets('Ctrl+N opens the chat as its own page on a phone', (
|
||||
tester,
|
||||
) async {
|
||||
|
||||
Reference in New Issue
Block a user