Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Bug on waitUntilVisible() and visible #2464

Merged
merged 11 commits into from
Jan 11, 2025
Original file line number Diff line number Diff line change
@@ -409,7 +409,6 @@ class PatrolFinder implements MatchFinder {
Future<PatrolFinder> waitUntilVisible({
Duration? timeout,
bool enablePatrolLog = true,
Alignment alignment = Alignment.center,
}) =>
wrapWithPatrolLog(
action: 'waitUntilVisible',
@@ -418,7 +417,6 @@ class PatrolFinder implements MatchFinder {
this,
timeout: timeout,
enablePatrolLog: false,
alignment: alignment,
),
enablePatrolLog: enablePatrolLog,
);
Original file line number Diff line number Diff line change
@@ -2,6 +2,7 @@ import 'package:flutter/foundation.dart';
import 'package:flutter/widgets.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:patrol_finders/patrol_finders.dart';
import 'package:patrol_finders/src/custom_finders/utils.dart';
import 'package:patrol_log/patrol_log.dart';

/// Common configuration for [PatrolTester] and [PatrolFinder].
@@ -521,7 +522,6 @@ class PatrolTester {
Finder finder, {
Duration? timeout,
bool enablePatrolLog = true,
Alignment alignment = Alignment.center,
}) {
return TestAsyncUtils.guard(
() => wrapWithPatrolLog(
@@ -532,20 +532,22 @@ class PatrolTester {
function: () async {
final duration = timeout ?? config.visibleTimeout;
final end = tester.binding.clock.now().add(duration);
final hitTestableFinder = finder.hitTestable(at: alignment);
while (hitTestableFinder.evaluate().isEmpty) {
final hitTestableFinders = alignments.map((alignment) => finder.hitTestable(at: alignment));
final hitTestableEvaluations = hitTestableFinders.map((finder) => finder.evaluate());
while (hitTestableEvaluations.map((result) => result.isNotEmpty).firstOrNull == null) {
final now = tester.binding.clock.now();
if (now.isAfter(end)) {
throw WaitUntilVisibleTimeoutException(
finder: finder,
duration: duration,
);
}

}
await tester.pump(const Duration(milliseconds: 100));
}

return PatrolFinder(finder: hitTestableFinder, tester: this);
return PatrolFinder(
finder: hitTestableFinders.firstWhere((finder) => finder.evaluate().isNotEmpty),
tester: this,
);
},
),
);
15 changes: 15 additions & 0 deletions packages/patrol_finders/lib/src/custom_finders/utils.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import 'package:flutter/material.dart';

/// Makes it possible to retrieve a name that this [Symbol] was created with.
extension SymbolName on Symbol {
/// Returns the name that this [Symbol] was created with.
@@ -9,3 +11,16 @@ extension SymbolName on Symbol {
return symbol.substring(8, symbol.length - 2);
}
}

/// List of all [Alignment] values.
const alignments = [
Alignment.center,
Alignment.bottomCenter,
Alignment.bottomLeft,
Alignment.bottomRight,
Alignment.centerLeft,
Alignment.centerRight,
Alignment.topCenter,
Alignment.topLeft,
Alignment.topRight,
];