Skip to content

Commit

Permalink
fix: visibility bug
Browse files Browse the repository at this point in the history
add changelog entry
format files and comments
  • Loading branch information
FritzMatthaeus committed Jan 3, 2025
1 parent 2dbf20e commit 91ca76a
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 13 deletions.
5 changes: 5 additions & 0 deletions packages/patrol_finders/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
## Unreleased

- Add `alignment` parameter to `waitUntilVisible` in order to improve visibility check on Row and Column widgets.
- Add `isVisibleAt` method to check if a widget is visible at a given alignment in case `visible` fails.

## 2.6.0

- Patch `enterText` into same field twice. (#2461)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -513,7 +513,8 @@ class PatrolFinder implements MatchFinder {
@override
String describeMatch(Plurality plurality) => finder.describeMatch(plurality);

/// Returns true if this finder finds at least 1 visible widget at the given [alignment].
/// Returns true if this finder finds at least 1 visible widget
/// at the given [alignment].
///
/// {@macro patrol_tester.alignment_on_visible_check}
bool isVisibleAt({Alignment alignment = Alignment.center}) {
Expand All @@ -529,9 +530,9 @@ class PatrolFinder implements MatchFinder {
}

/// Returns true if this finder finds at least 1 visible widget.
///
///
/// will call [isVisibleAt] with [Alignment.center]
///
///
/// In case this returns false and you are sure that the widget is visible,
/// try calling [isVisibleAt] with a different [Alignment] parameter.
bool get visible => isVisibleAt();
Expand Down
29 changes: 19 additions & 10 deletions packages/patrol_finders/lib/src/custom_finders/patrol_tester.dart
Original file line number Diff line number Diff line change
Expand Up @@ -492,18 +492,21 @@ class PatrolTester {
/// want to override this global setting, set [timeout].
///
/// {@template patrol_tester.alignment_on_visible_check}
/// Provide [alignment] to fine tune the visibility check by calling [Finder.hitTestable] at this [alignment]
/// of the [Widget]. This might be helpful in case the tested [Widget]
/// is or contains a [Row] or a [Column]. The default [Alignment.center] might always be the best choice as the following example demonstrates:
///
/// Provide [alignment] to fine tune the visibility check by calling
/// [Finder.hitTestable] at this [alignment] of the [Widget].
/// This might be helpful in case the tested [Widget] is or contains a [Row]
/// or a [Column]. The default [Alignment.center] might always be the best
/// choice as the following example demonstrates:
///
/// ```dart
///
/// /// This [Widget] will only be found when calling await $(Foo).waitUntilVisible(alignment: Alignment.topCenter)
///
/// /// This [Widget] will only be found when calling
/// ///await $(Foo).waitUntilVisible(alignment: Alignment.topCenter)
/// class Foo extends StatelessWidget {
/// Foo({Key? key}) : super(key: key);
/// @override
/// Widget build(BuildContext context) {
/// return const Column(
/// return const Column(
/// children: [
/// Text(
/// 'Foo',
Expand All @@ -515,8 +518,14 @@ class PatrolTester {
/// }
/// }
/// ```
/// As there is an empty [SizedBox] in the center of the [Column], calling ``await $(Foo).waitUntilVisible()`` will fail as the underlying [Finder.hitTestable] will not find any hit-testable widget.
/// Changing the ``alignment`` parameter to ``Alignment.topCenter`` and calling ``await $(Foo).waitUntilVisible(alignment: Alignment.topCenter)`` will make the test pass as the underlying [Finder.hitTestable] will find the [Text] widget at the top of the [Column].
/// As there is an empty [SizedBox] in the center of the [Column],
/// calling ``await $(Foo).waitUntilVisible()`` will fail
/// as the underlying [Finder.hitTestable] will not find any
/// hit-testable widget. Changing the ``alignment`` parameter
/// to ``Alignment.topCenter`` and calling
/// ``await $(Foo).waitUntilVisible(alignment: Alignment.topCenter)``
/// will make the test pass as the underlying [Finder.hitTestable]
/// will find the [Text] widget at the top of the [Column].
/// {@endtemplate}
Future<PatrolFinder> waitUntilVisible(
Finder finder, {
Expand All @@ -533,7 +542,7 @@ class PatrolTester {
function: () async {
final duration = timeout ?? config.visibleTimeout;
final end = tester.binding.clock.now().add(duration);
final hitTestableFinder = finder.hitTestable(at: alignment);
final hitTestableFinder = finder.hitTestable(at: alignment);
while (hitTestableFinder.evaluate().isEmpty) {
final now = tester.binding.clock.now();
if (now.isAfter(end)) {
Expand Down

0 comments on commit 91ca76a

Please sign in to comment.