Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Sign in
Toggle navigation
F
Front-End
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
abdullh.alsoleman
Front-End
Commits
ff1f8dd1
Unverified
Commit
ff1f8dd1
authored
Sep 19, 2018
by
Jonah Williams
Committed by
GitHub
Sep 19, 2018
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add RichText support to find.text (#21964)
parent
7dd82813
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
43 additions
and
0 deletions
+43
-0
finders.dart
packages/flutter_test/lib/src/finders.dart
+16
-0
finders_test.dart
packages/flutter_test/test/finders_test.dart
+27
-0
No files found.
packages/flutter_test/lib/src/finders.dart
View file @
ff1f8dd1
...
...
@@ -498,6 +498,22 @@ class _TextFinder extends MatchFinder {
}
else
if
(
candidate
.
widget
is
EditableText
)
{
final
EditableText
editable
=
candidate
.
widget
;
return
editable
.
controller
.
text
==
text
;
}
else
if
(
candidate
.
widget
is
RichText
)
{
bool
parentIsText
=
false
;
// check if the direct parent is a Text widget. if so, do not match it
// twice. We make an exception for semantics since those may be placed
// between a Text and Rich text.
candidate
.
visitAncestorElements
((
Element
parent
)
{
if
(
parent
.
widget
is
Text
)
{
parentIsText
=
true
;
return
false
;
}
else
if
(
parent
.
widget
is
ExcludeSemantics
||
parent
.
widget
is
Semantics
)
{
return
true
;
}
return
false
;
});
final
RichText
richText
=
candidate
.
widget
;
return
!
parentIsText
&&
richText
.
text
.
toPlainText
()
==
text
;
}
return
false
;
}
...
...
packages/flutter_test/test/finders_test.dart
View file @
ff1f8dd1
...
...
@@ -27,6 +27,33 @@ void main() {
expect
(
find
.
text
(
'test'
),
findsOneWidget
);
});
testWidgets
(
'finds RichText widgets'
,
(
WidgetTester
tester
)
async
{
await
tester
.
pumpWidget
(
_boilerplate
(
const
RichText
(
text:
TextSpan
(
text:
't'
,
children:
<
TextSpan
>[
TextSpan
(
text:
'est'
),
]))
));
expect
(
find
.
text
(
'test'
),
findsOneWidget
);
});
testWidgets
(
'Does not find Text and RichText widgets'
,
(
WidgetTester
tester
)
async
{
await
tester
.
pumpWidget
(
_boilerplate
(
const
Text
(
'test'
),
));
expect
(
find
.
text
(
'test'
),
findsOneWidget
);
});
testWidgets
(
'Does not find Text and RichText separated by semantics widgets'
,
(
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
);
});
});
group
(
'hitTestable'
,
()
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment