Keep Cupertino web Search keyboard input stable
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:pipelines_app/core/api_gateway.dart';
|
||||
@@ -129,4 +130,58 @@ void main() {
|
||||
variant: TargetPlatformVariant.only(platform),
|
||||
);
|
||||
}
|
||||
testWidgets(
|
||||
'Cupertino Command slash retains primary focus after query updates',
|
||||
(tester) async {
|
||||
final composer = TextEditingController(text: 'draft');
|
||||
final focus = FocusNode();
|
||||
addTearDown(composer.dispose);
|
||||
addTearDown(focus.dispose);
|
||||
await tester.pumpWidget(
|
||||
CupertinoApp(
|
||||
home: AdaptiveShell(
|
||||
cupertino: true,
|
||||
destination: AppDestination.chat,
|
||||
destinationBodies: {
|
||||
AppDestination.chat: (_) =>
|
||||
CupertinoTextField(controller: composer, focusNode: focus),
|
||||
AppDestination.search: (_) => SearchScreen(
|
||||
gateway: _Gateway(),
|
||||
onOpen: (_) {},
|
||||
embedded: true,
|
||||
),
|
||||
},
|
||||
),
|
||||
),
|
||||
);
|
||||
await tester.pumpAndSettle();
|
||||
focus.requestFocus();
|
||||
await tester.pump();
|
||||
await _chord(tester, [
|
||||
LogicalKeyboardKey.metaLeft,
|
||||
], LogicalKeyboardKey.slash);
|
||||
EditableText field() => tester.widget<EditableText>(
|
||||
find.descendant(
|
||||
of: find.byKey(searchFieldKey),
|
||||
matching: find.byType(EditableText),
|
||||
),
|
||||
);
|
||||
expect(field().focusNode.hasPrimaryFocus, isTrue);
|
||||
await tester.enterText(find.byKey(searchFieldKey), 'release');
|
||||
await tester.pumpAndSettle(const Duration(milliseconds: 300));
|
||||
await tester.pump(const Duration(seconds: 1));
|
||||
expect(field().controller.text, 'release');
|
||||
expect(field().focusNode.hasPrimaryFocus, isTrue);
|
||||
await tester.tap(find.byKey(const ValueKey('shell.destination.chat')));
|
||||
await tester.pumpAndSettle();
|
||||
focus.requestFocus();
|
||||
await tester.pump();
|
||||
await _chord(tester, [
|
||||
LogicalKeyboardKey.metaLeft,
|
||||
], LogicalKeyboardKey.slash);
|
||||
expect(field().controller.text, 'release');
|
||||
expect(field().focusNode.hasPrimaryFocus, isTrue);
|
||||
},
|
||||
variant: TargetPlatformVariant.only(TargetPlatform.macOS),
|
||||
);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,89 @@
|
||||
import 'dart:ui' show Tristate;
|
||||
|
||||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:pipelines_app/ui/input/cupertino_web_search_field.dart';
|
||||
|
||||
void main() {
|
||||
for (final provided in [false, true]) {
|
||||
testWidgets(
|
||||
'native clear preserves semantics and focus (provided node: $provided)',
|
||||
(tester) async {
|
||||
final semantics = tester.ensureSemantics();
|
||||
|
||||
try {
|
||||
final text = TextEditingController();
|
||||
final focus = FocusNode();
|
||||
addTearDown(text.dispose);
|
||||
addTearDown(focus.dispose);
|
||||
var clears = 0;
|
||||
await tester.pumpWidget(
|
||||
CupertinoApp(
|
||||
home: CupertinoPageScaffold(
|
||||
child: Center(
|
||||
child: CupertinoWebSearchField(
|
||||
controller: text,
|
||||
placeholder: 'Search',
|
||||
focusNode: provided ? focus : null,
|
||||
onCleared: () {
|
||||
clears++;
|
||||
text.clear();
|
||||
},
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
final field = find.byType(EditableText);
|
||||
final effective = tester.widget<EditableText>(field).focusNode;
|
||||
effective.requestFocus();
|
||||
await tester.pumpAndSettle();
|
||||
final height = tester
|
||||
.getSize(find.byType(CupertinoWebSearchField))
|
||||
.height;
|
||||
final before = tester.getSemantics(field);
|
||||
final identity = before.id;
|
||||
expect(
|
||||
before.getSemanticsData().flagsCollection.isEnabled,
|
||||
Tristate.isTrue,
|
||||
);
|
||||
await tester.enterText(
|
||||
find.byType(CupertinoSearchTextField),
|
||||
'release',
|
||||
);
|
||||
await tester.pumpAndSettle();
|
||||
final after = tester.getSemantics(field);
|
||||
expect(after.id, identity);
|
||||
expect(
|
||||
tester.getSize(find.byType(CupertinoWebSearchField)).height,
|
||||
height,
|
||||
);
|
||||
expect(
|
||||
after.getSemanticsData().flagsCollection.isEnabled,
|
||||
Tristate.isTrue,
|
||||
);
|
||||
expect(effective.hasPrimaryFocus, isTrue);
|
||||
await tester.tap(find.byType(CupertinoButton));
|
||||
await tester.pumpAndSettle();
|
||||
expect(text.text, isEmpty);
|
||||
expect(clears, 1);
|
||||
expect(
|
||||
tester.getSize(find.byType(CupertinoWebSearchField)).height,
|
||||
height,
|
||||
);
|
||||
expect(effective.hasPrimaryFocus, isTrue);
|
||||
expect(tester.getSemantics(field).id, identity);
|
||||
await tester.enterText(
|
||||
find.byType(CupertinoSearchTextField),
|
||||
'again',
|
||||
);
|
||||
await tester.pumpAndSettle();
|
||||
expect(text.text, 'again');
|
||||
expect(effective.hasPrimaryFocus, isTrue);
|
||||
} finally {
|
||||
semantics.dispose();
|
||||
}
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user