Files
openchamber-android-native/test/composer_box_test.dart
T

60 lines
2.0 KiB
Dart
Raw Normal View History

import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:openchamber/widgets/composer_box.dart';
void main() {
testWidgets('the composer opens on focus and folds when the IME closes',
(tester) async {
final controller = TextEditingController();
final focus = FocusNode();
final keyboard = ValueNotifier<double>(0);
addTearDown(controller.dispose);
addTearDown(focus.dispose);
addTearDown(keyboard.dispose);
// A stand-in for the second row's contents: it only exists while open.
const model = Text('MODEL');
// The page owns the keyboard inset (a Scaffold removes it from the body),
// so the test feeds it in as the screens do.
await tester.pumpWidget(MaterialApp(
home: ValueListenableBuilder<double>(
valueListenable: keyboard,
builder: (context, inset, _) => Scaffold(
body: ComposerBox(
controller: controller,
focusNode: focus,
hint: 'hi',
keyboardInset: inset,
leading: const Icon(Icons.attach_file),
model: model,
trailing: const Icon(Icons.send),
),
),
),
));
// Unfocused: one line, no model pill.
expect(find.text('MODEL'), findsNothing);
// Focus: the composer opens into two rows.
focus.requestFocus();
await tester.pumpAndSettle();
expect(find.text('MODEL'), findsOneWidget);
// The soft keyboard rises, then the back gesture closes it while the
// field keeps focus: the composer folds back to one line.
keyboard.value = 300;
await tester.pumpAndSettle();
expect(find.text('MODEL'), findsOneWidget);
keyboard.value = 0;
await tester.pumpAndSettle();
expect(find.text('MODEL'), findsNothing);
expect(focus.hasFocus, isTrue);
// Typing again brings the keyboard back: the composer opens.
keyboard.value = 300;
await tester.pumpAndSettle();
expect(find.text('MODEL'), findsOneWidget);
});
}