Allow find.byTooltip to use a RegEx (#149348)

## Description

This adds the ability for `find.byTooltip` to use a `RegEx` to match the tooltip.

Also, adds some tests for `byTooltip`, since there weren't any.

## Tests
 - added tests
This commit is contained in:
Greg Spencer
2024-06-04 14:43:06 -07:00
committed by GitHub
parent c77c0cf0bc
commit ea8ae8c81b
2 changed files with 109 additions and 3 deletions

View File

@@ -365,13 +365,20 @@ class CommonFinders {
///
/// ```dart
/// expect(find.byTooltip('Back'), findsOneWidget);
/// expect(find.byTooltip(RegExp('Back.*')), findsNWidgets(2));
/// ```
///
/// If the `skipOffstage` argument is true (the default), then this skips
/// nodes that are [Offstage] or that are from inactive [Route]s.
Finder byTooltip(String message, { bool skipOffstage = true }) {
Finder byTooltip(Pattern message, {bool skipOffstage = true}) {
return byWidgetPredicate(
(Widget widget) => widget is Tooltip && widget.message == message,
(Widget widget) {
return widget is Tooltip &&
(message is RegExp
? ((widget.message != null && message.hasMatch(widget.message!)) ||
(widget.richMessage != null && message.hasMatch(widget.richMessage!.toPlainText())))
: ((widget.message ?? widget.richMessage?.toPlainText()) == message));
},
skipOffstage: skipOffstage,
);
}