전역 구조 리팩터링 및 테스트 확장
This commit is contained in:
54
test/widgets/dialog_keyboard_shortcuts_test.dart
Normal file
54
test/widgets/dialog_keyboard_shortcuts_test.dart
Normal file
@@ -0,0 +1,54 @@
|
||||
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);
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user