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
14150788
Unverified
Commit
14150788
authored
Sep 16, 2020
by
Christian Mürtz
Committed by
GitHub
Sep 16, 2020
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Find text containing in tests (#65072)
parent
a17b3309
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
77 additions
and
0 deletions
+77
-0
finders.dart
packages/flutter_test/lib/src/finders.dart
+37
-0
finders_test.dart
packages/flutter_test/test/finders_test.dart
+40
-0
No files found.
packages/flutter_test/lib/src/finders.dart
View file @
14150788
...
@@ -36,6 +36,20 @@ class CommonFinders {
...
@@ -36,6 +36,20 @@ class CommonFinders {
/// nodes that are [Offstage] or that are from inactive [Route]s.
/// nodes that are [Offstage] or that are from inactive [Route]s.
Finder
text
(
String
text
,
{
bool
skipOffstage
=
true
})
=>
_TextFinder
(
text
,
skipOffstage:
skipOffstage
);
Finder
text
(
String
text
,
{
bool
skipOffstage
=
true
})
=>
_TextFinder
(
text
,
skipOffstage:
skipOffstage
);
/// Finds [Text] and [EditableText] widgets which contain the given
/// `pattern` argument.
///
/// ## Sample code
///
/// ```dart
/// expect(find.textContain('Back'), findsOneWidget);
/// expect(find.textContain(RegExp(r'(\w+)')), findsOneWidget);
/// ```
///
/// If the `skipOffstage` argument is true (the default), then this skips
/// nodes that are [Offstage] or that are from inactive [Route]s.
Finder
textContaining
(
Pattern
pattern
,
{
bool
skipOffstage
=
true
})
=>
_TextContainingFinder
(
pattern
,
skipOffstage:
skipOffstage
);
/// Looks for widgets that contain a [Text] descendant with `text`
/// Looks for widgets that contain a [Text] descendant with `text`
/// in it.
/// in it.
///
///
...
@@ -556,6 +570,29 @@ class _TextFinder extends MatchFinder {
...
@@ -556,6 +570,29 @@ class _TextFinder extends MatchFinder {
}
}
}
}
class
_TextContainingFinder
extends
MatchFinder
{
_TextContainingFinder
(
this
.
pattern
,
{
bool
skipOffstage
=
true
})
:
super
(
skipOffstage:
skipOffstage
);
final
Pattern
pattern
;
@override
String
get
description
=>
'text containing
$pattern
'
;
@override
bool
matches
(
Element
candidate
)
{
final
Widget
widget
=
candidate
.
widget
;
if
(
widget
is
Text
)
{
if
(
widget
.
data
!=
null
)
return
widget
.
data
.
contains
(
pattern
);
return
widget
.
textSpan
.
toPlainText
().
contains
(
pattern
);
}
else
if
(
widget
is
EditableText
)
{
return
widget
.
controller
.
text
.
contains
(
pattern
);
}
return
false
;
}
}
class
_KeyFinder
extends
MatchFinder
{
class
_KeyFinder
extends
MatchFinder
{
_KeyFinder
(
this
.
key
,
{
bool
skipOffstage
=
true
})
:
super
(
skipOffstage:
skipOffstage
);
_KeyFinder
(
this
.
key
,
{
bool
skipOffstage
=
true
})
:
super
(
skipOffstage:
skipOffstage
);
...
...
packages/flutter_test/test/finders_test.dart
View file @
14150788
...
@@ -30,6 +30,46 @@ void main() {
...
@@ -30,6 +30,46 @@ void main() {
});
});
});
});
group
(
'textContaining'
,
()
{
testWidgets
(
'finds Text widgets'
,
(
WidgetTester
tester
)
async
{
await
tester
.
pumpWidget
(
_boilerplate
(
const
Text
(
'this is a test'
),
));
expect
(
find
.
textContaining
(
RegExp
(
r'test'
)),
findsOneWidget
);
expect
(
find
.
textContaining
(
'test'
),
findsOneWidget
);
expect
(
find
.
textContaining
(
'a'
),
findsOneWidget
);
expect
(
find
.
textContaining
(
's'
),
findsOneWidget
);
});
testWidgets
(
'finds Text.rich widgets'
,
(
WidgetTester
tester
)
async
{
await
tester
.
pumpWidget
(
_boilerplate
(
const
Text
.
rich
(
TextSpan
(
text:
'this'
,
children:
<
TextSpan
>[
TextSpan
(
text:
'is'
),
TextSpan
(
text:
'a'
),
TextSpan
(
text:
'test'
),
],
),
)));
expect
(
find
.
textContaining
(
RegExp
(
r'isatest'
)),
findsOneWidget
);
expect
(
find
.
textContaining
(
'isatest'
),
findsOneWidget
);
});
testWidgets
(
'finds EditableText widgets'
,
(
WidgetTester
tester
)
async
{
await
tester
.
pumpWidget
(
MaterialApp
(
home:
Scaffold
(
body:
_boilerplate
(
TextField
(
controller:
TextEditingController
()..
text
=
'this is test'
,
)),
),
));
expect
(
find
.
textContaining
(
RegExp
(
r'test'
)),
findsOneWidget
);
expect
(
find
.
textContaining
(
'test'
),
findsOneWidget
);
});
});
group
(
'semantics'
,
()
{
group
(
'semantics'
,
()
{
testWidgets
(
'Throws StateError if semantics are not enabled'
,
(
WidgetTester
tester
)
async
{
testWidgets
(
'Throws StateError if semantics are not enabled'
,
(
WidgetTester
tester
)
async
{
expect
(()
=>
find
.
bySemanticsLabel
(
'Add'
),
throwsStateError
);
expect
(()
=>
find
.
bySemanticsLabel
(
'Add'
),
throwsStateError
);
...
...
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