fix(flutter): 增加剧场搜索清空按钮
This commit is contained in:
1 parent
fb0585c9cf
commit
9870502901
2 files changed
+115
-8
No files matched your search
@@ -0,0 +1,57 @@
|
||||
// Author: fruit.com.cn
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:fruitshorts/l10n/app_localizations.dart';
|
||||
import 'package:fruitshorts/pages/discover/widgets/discover_search_field.dart';
|
||||
|
||||
void main() {
|
||||
testWidgets('should_clear_text_and_keep_focus_when_clear_is_tapped', (
|
||||
tester,
|
||||
) async {
|
||||
final controller = TextEditingController();
|
||||
final focusNode = FocusNode();
|
||||
final changes = <String>[];
|
||||
addTearDown(controller.dispose);
|
||||
addTearDown(focusNode.dispose);
|
||||
|
||||
await tester.pumpWidget(
|
||||
MaterialApp(
|
||||
locale: const Locale('en'),
|
||||
localizationsDelegates: AppLocalizations.localizationsDelegates,
|
||||
supportedLocales: AppLocalizations.supportedLocales,
|
||||
home: Scaffold(
|
||||
body: DiscoverSearchField(
|
||||
controller: controller,
|
||||
focusNode: focusNode,
|
||||
onChanged: changes.add,
|
||||
loading: true,
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
final search = find.byKey(const Key('discover-search'));
|
||||
expect(find.byKey(const Key('discover-search-clear')), findsNothing);
|
||||
|
||||
await tester.tap(search);
|
||||
await tester.enterText(search, 'velvet');
|
||||
await tester.pump();
|
||||
changes.clear();
|
||||
|
||||
final clear = find.byKey(const Key('discover-search-clear'));
|
||||
final loading = find.byKey(const Key('discover-search-loading'));
|
||||
expect(clear, findsOneWidget);
|
||||
expect(loading, findsOneWidget);
|
||||
expect(tester.getSize(clear), const Size(18, 18));
|
||||
expect(tester.getRect(loading).right, lessThan(tester.getRect(clear).left));
|
||||
|
||||
await tester.tap(clear);
|
||||
await tester.pump();
|
||||
|
||||
expect(controller.text, isEmpty);
|
||||
expect(changes, ['']);
|
||||
expect(find.byKey(const Key('discover-search-clear')), findsNothing);
|
||||
expect(focusNode.hasFocus, isTrue);
|
||||
});
|
||||
}
|
||||
Reference in new issue
Block a user