Add RichText support to find.text() (#87197)
This commit is contained in:
committed by
GitHub
parent
db3cc6e318
commit
87b17c8ccf
@@ -27,6 +27,84 @@ void main() {
|
||||
|
||||
expect(find.text('test'), findsOneWidget);
|
||||
});
|
||||
|
||||
group('findRichText', () {
|
||||
testWidgets('finds RichText widgets when enabled',
|
||||
(WidgetTester tester) async {
|
||||
await tester.pumpWidget(_boilerplate(RichText(
|
||||
text: const TextSpan(
|
||||
text: 't',
|
||||
children: <TextSpan>[
|
||||
TextSpan(text: 'est'),
|
||||
],
|
||||
),
|
||||
)));
|
||||
|
||||
expect(find.text('test', findRichText: true), findsOneWidget);
|
||||
});
|
||||
|
||||
testWidgets('finds Text widgets once when enabled',
|
||||
(WidgetTester tester) async {
|
||||
await tester.pumpWidget(_boilerplate(const Text('test2')));
|
||||
|
||||
expect(find.text('test2', findRichText: true), findsOneWidget);
|
||||
});
|
||||
|
||||
testWidgets('does not find RichText widgets when disabled',
|
||||
(WidgetTester tester) async {
|
||||
await tester.pumpWidget(_boilerplate(RichText(
|
||||
text: const TextSpan(
|
||||
text: 't',
|
||||
children: <TextSpan>[
|
||||
TextSpan(text: 'est'),
|
||||
],
|
||||
),
|
||||
)));
|
||||
|
||||
expect(find.text('test', findRichText: false), findsNothing);
|
||||
});
|
||||
|
||||
testWidgets(
|
||||
'does not find Text and RichText separated by semantics widgets twice',
|
||||
(WidgetTester tester) async {
|
||||
// If rich: true found both Text and RichText, this would find two widgets.
|
||||
await tester.pumpWidget(_boilerplate(
|
||||
const Text('test', semanticsLabel: 'foo'),
|
||||
));
|
||||
|
||||
expect(find.text('test'), findsOneWidget);
|
||||
});
|
||||
|
||||
testWidgets('finds Text.rich widgets when enabled',
|
||||
(WidgetTester tester) async {
|
||||
await tester.pumpWidget(_boilerplate(const Text.rich(
|
||||
TextSpan(
|
||||
text: 't',
|
||||
children: <TextSpan>[
|
||||
TextSpan(text: 'est'),
|
||||
TextSpan(text: '3'),
|
||||
],
|
||||
),
|
||||
)));
|
||||
|
||||
expect(find.text('test3', findRichText: true), findsOneWidget);
|
||||
});
|
||||
|
||||
testWidgets('finds Text.rich widgets when disabled',
|
||||
(WidgetTester tester) async {
|
||||
await tester.pumpWidget(_boilerplate(const Text.rich(
|
||||
TextSpan(
|
||||
text: 't',
|
||||
children: <TextSpan>[
|
||||
TextSpan(text: 'est'),
|
||||
TextSpan(text: '3'),
|
||||
],
|
||||
),
|
||||
)));
|
||||
|
||||
expect(find.text('test3', findRichText: false), findsOneWidget);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
group('textContaining', () {
|
||||
|
||||
Reference in New Issue
Block a user