55 lines
1.3 KiB
Dart
55 lines
1.3 KiB
Dart
import 'package:flutter/services.dart';
|
|
import 'package:flutter_test/flutter_test.dart';
|
|
import 'package:flutter/material.dart';
|
|
import 'package:superport_v2/widgets/components/keyboard_shortcuts.dart';
|
|
|
|
void main() {
|
|
testWidgets('DialogKeyboardShortcuts handles escape and enter', (
|
|
tester,
|
|
) async {
|
|
var escape = 0;
|
|
var submit = 0;
|
|
|
|
await tester.pumpWidget(
|
|
MaterialApp(
|
|
home: DialogKeyboardShortcuts(
|
|
onEscape: () => escape++,
|
|
onSubmit: () => submit++,
|
|
child: const SizedBox.shrink(),
|
|
),
|
|
),
|
|
);
|
|
|
|
await tester.sendKeyEvent(LogicalKeyboardKey.escape);
|
|
await tester.pump();
|
|
expect(escape, 1);
|
|
|
|
await tester.sendKeyEvent(LogicalKeyboardKey.enter);
|
|
await tester.pump();
|
|
expect(submit, 1);
|
|
});
|
|
|
|
testWidgets('DialogKeyboardShortcuts does not submit from multiline input', (
|
|
tester,
|
|
) async {
|
|
var submit = 0;
|
|
|
|
await tester.pumpWidget(
|
|
MaterialApp(
|
|
home: DialogKeyboardShortcuts(
|
|
onSubmit: () => submit++,
|
|
child: const Material(child: TextField(maxLines: 5)),
|
|
),
|
|
),
|
|
);
|
|
|
|
await tester.tap(find.byType(TextField));
|
|
await tester.pump();
|
|
|
|
await tester.sendKeyEvent(LogicalKeyboardKey.enter);
|
|
await tester.pump();
|
|
|
|
expect(submit, 0);
|
|
});
|
|
}
|