Unverified Commit 40d0c69f authored by Kate Lovett's avatar Kate Lovett Committed by GitHub

Make scrollbar assertions less aggressive (#84809)

parent 604c59e5
...@@ -360,7 +360,7 @@ void main() { ...@@ -360,7 +360,7 @@ void main() {
} }
await tester.pumpWidget(viewWithScroll()); await tester.pumpWidget(viewWithScroll());
final dynamic exception = tester.takeException(); final AssertionError exception = tester.takeException() as AssertionError;
expect(exception, isAssertionError); expect(exception, isAssertionError);
}, },
); );
...@@ -390,7 +390,7 @@ void main() { ...@@ -390,7 +390,7 @@ void main() {
} }
await tester.pumpWidget(viewWithScroll()); await tester.pumpWidget(viewWithScroll());
final dynamic exception = tester.takeException(); final AssertionError exception = tester.takeException() as AssertionError;
expect(exception, isAssertionError); expect(exception, isAssertionError);
}, },
); );
...@@ -961,10 +961,16 @@ void main() { ...@@ -961,10 +961,16 @@ void main() {
await tester.pumpAndSettle(); await tester.pumpAndSettle();
final dynamic exception = tester.takeException(); AssertionError? exception = tester.takeException() as AssertionError?;
// The scrollbar is not visible and cannot be interacted with, so no assertion.
expect(exception, isNull);
// Scroll to trigger the scrollbar to come into view.
final TestGesture gesture = await tester.startGesture(tester.getCenter(find.byType(SingleChildScrollView)));
await gesture.moveBy(const Offset(0.0, -20.0));
exception = tester.takeException() as AssertionError;
expect(exception, isAssertionError); expect(exception, isAssertionError);
expect( expect(
(exception as AssertionError).message, exception.message,
contains("The Scrollbar's ScrollController has no ScrollPosition attached."), contains("The Scrollbar's ScrollController has no ScrollPosition attached."),
); );
}); });
......
...@@ -128,7 +128,7 @@ void main() { ...@@ -128,7 +128,7 @@ void main() {
of: find.byType(Scrollbar), of: find.byType(Scrollbar),
matching: find.byType(CustomPaint), matching: find.byType(CustomPaint),
).first); ).first);
final dynamic scrollPainter = custom.foregroundPainter; final ScrollbarPainter? scrollPainter = custom.foregroundPainter as ScrollbarPainter?;
// Dragging makes the scrollbar first appear. // Dragging makes the scrollbar first appear.
await tester.drag(find.text('0'), const Offset(0.0, -10.0)); await tester.drag(find.text('0'), const Offset(0.0, -10.0));
await tester.pump(const Duration(milliseconds: 200)); await tester.pump(const Duration(milliseconds: 200));
...@@ -141,7 +141,7 @@ void main() { ...@@ -141,7 +141,7 @@ void main() {
viewportDimension: 100.0, viewportDimension: 100.0,
axisDirection: AxisDirection.down, axisDirection: AxisDirection.down,
); );
scrollPainter.update(metrics, AxisDirection.down); scrollPainter!.update(metrics, AxisDirection.down);
final TestCanvas canvas = TestCanvas(); final TestCanvas canvas = TestCanvas();
scrollPainter.paint(canvas, const Size(10.0, 100.0)); scrollPainter.paint(canvas, const Size(10.0, 100.0));
...@@ -171,7 +171,7 @@ void main() { ...@@ -171,7 +171,7 @@ void main() {
} }
await tester.pumpWidget(viewWithScroll()); await tester.pumpWidget(viewWithScroll());
final dynamic exception = tester.takeException(); final AssertionError exception = tester.takeException() as AssertionError;
expect(exception, isAssertionError); expect(exception, isAssertionError);
}, },
); );
...@@ -199,7 +199,7 @@ void main() { ...@@ -199,7 +199,7 @@ void main() {
} }
await tester.pumpWidget(viewWithScroll()); await tester.pumpWidget(viewWithScroll());
final dynamic exception = tester.takeException(); final AssertionError exception = tester.takeException() as AssertionError;
expect(exception, isAssertionError); expect(exception, isAssertionError);
}, },
); );
......
...@@ -381,13 +381,13 @@ void main() { ...@@ -381,13 +381,13 @@ void main() {
axisDirection: AxisDirection.down, axisDirection: AxisDirection.down,
); );
final ScrollbarPainter p = _buildPainter( final ScrollbarPainter painter = _buildPainter(
padding: padding, padding: padding,
scrollMetrics: metrics, scrollMetrics: metrics,
); );
testWidgets('down', (WidgetTester tester) async { testWidgets('down', (WidgetTester tester) async {
p.update( painter.update(
metrics.copyWith( metrics.copyWith(
viewportDimension: size.height, viewportDimension: size.height,
pixels: double.negativeInfinity, pixels: double.negativeInfinity,
...@@ -396,13 +396,13 @@ void main() { ...@@ -396,13 +396,13 @@ void main() {
); );
// Top overscroll. // Top overscroll.
p.paint(testCanvas, size); painter.paint(testCanvas, size);
final Rect rect0 = captureRect(); final Rect rect0 = captureRect();
expect(rect0.top, padding.top); expect(rect0.top, padding.top);
expect(size.width - rect0.right, padding.right); expect(size.width - rect0.right, padding.right);
// Bottom overscroll. // Bottom overscroll.
p.update( painter.update(
metrics.copyWith( metrics.copyWith(
viewportDimension: size.height, viewportDimension: size.height,
pixels: double.infinity, pixels: double.infinity,
...@@ -410,14 +410,14 @@ void main() { ...@@ -410,14 +410,14 @@ void main() {
AxisDirection.down, AxisDirection.down,
); );
p.paint(testCanvas, size); painter.paint(testCanvas, size);
final Rect rect1 = captureRect(); final Rect rect1 = captureRect();
expect(size.height - rect1.bottom, padding.bottom); expect(size.height - rect1.bottom, padding.bottom);
expect(size.width - rect1.right, padding.right); expect(size.width - rect1.right, padding.right);
}); });
testWidgets('up', (WidgetTester tester) async { testWidgets('up', (WidgetTester tester) async {
p.update( painter.update(
metrics.copyWith( metrics.copyWith(
viewportDimension: size.height, viewportDimension: size.height,
pixels: double.infinity, pixels: double.infinity,
...@@ -427,13 +427,13 @@ void main() { ...@@ -427,13 +427,13 @@ void main() {
); );
// Top overscroll. // Top overscroll.
p.paint(testCanvas, size); painter.paint(testCanvas, size);
final Rect rect0 = captureRect(); final Rect rect0 = captureRect();
expect(rect0.top, padding.top); expect(rect0.top, padding.top);
expect(size.width - rect0.right, padding.right); expect(size.width - rect0.right, padding.right);
// Bottom overscroll. // Bottom overscroll.
p.update( painter.update(
metrics.copyWith( metrics.copyWith(
viewportDimension: size.height, viewportDimension: size.height,
pixels: double.negativeInfinity, pixels: double.negativeInfinity,
...@@ -442,14 +442,14 @@ void main() { ...@@ -442,14 +442,14 @@ void main() {
AxisDirection.up, AxisDirection.up,
); );
p.paint(testCanvas, size); painter.paint(testCanvas, size);
final Rect rect1 = captureRect(); final Rect rect1 = captureRect();
expect(size.height - rect1.bottom, padding.bottom); expect(size.height - rect1.bottom, padding.bottom);
expect(size.width - rect1.right, padding.right); expect(size.width - rect1.right, padding.right);
}); });
testWidgets('left', (WidgetTester tester) async { testWidgets('left', (WidgetTester tester) async {
p.update( painter.update(
metrics.copyWith( metrics.copyWith(
viewportDimension: size.width, viewportDimension: size.width,
pixels: double.negativeInfinity, pixels: double.negativeInfinity,
...@@ -459,13 +459,13 @@ void main() { ...@@ -459,13 +459,13 @@ void main() {
); );
// Right overscroll. // Right overscroll.
p.paint(testCanvas, size); painter.paint(testCanvas, size);
final Rect rect0 = captureRect(); final Rect rect0 = captureRect();
expect(size.height - rect0.bottom, padding.bottom); expect(size.height - rect0.bottom, padding.bottom);
expect(size.width - rect0.right, padding.right); expect(size.width - rect0.right, padding.right);
// Left overscroll. // Left overscroll.
p.update( painter.update(
metrics.copyWith( metrics.copyWith(
viewportDimension: size.width, viewportDimension: size.width,
pixels: double.infinity, pixels: double.infinity,
...@@ -474,14 +474,14 @@ void main() { ...@@ -474,14 +474,14 @@ void main() {
AxisDirection.left, AxisDirection.left,
); );
p.paint(testCanvas, size); painter.paint(testCanvas, size);
final Rect rect1 = captureRect(); final Rect rect1 = captureRect();
expect(size.height - rect1.bottom, padding.bottom); expect(size.height - rect1.bottom, padding.bottom);
expect(rect1.left, padding.left); expect(rect1.left, padding.left);
}); });
testWidgets('right', (WidgetTester tester) async { testWidgets('right', (WidgetTester tester) async {
p.update( painter.update(
metrics.copyWith( metrics.copyWith(
viewportDimension: size.width, viewportDimension: size.width,
pixels: double.infinity, pixels: double.infinity,
...@@ -491,13 +491,13 @@ void main() { ...@@ -491,13 +491,13 @@ void main() {
); );
// Right overscroll. // Right overscroll.
p.paint(testCanvas, size); painter.paint(testCanvas, size);
final Rect rect0 = captureRect(); final Rect rect0 = captureRect();
expect(size.height - rect0.bottom, padding.bottom); expect(size.height - rect0.bottom, padding.bottom);
expect(size.width - rect0.right, padding.right); expect(size.width - rect0.right, padding.right);
// Left overscroll. // Left overscroll.
p.update( painter.update(
metrics.copyWith( metrics.copyWith(
viewportDimension: size.width, viewportDimension: size.width,
pixels: double.negativeInfinity, pixels: double.negativeInfinity,
...@@ -506,7 +506,7 @@ void main() { ...@@ -506,7 +506,7 @@ void main() {
AxisDirection.right, AxisDirection.right,
); );
p.paint(testCanvas, size); painter.paint(testCanvas, size);
final Rect rect1 = captureRect(); final Rect rect1 = captureRect();
expect(size.height - rect1.bottom, padding.bottom); expect(size.height - rect1.bottom, padding.bottom);
expect(rect1.left, padding.left); expect(rect1.left, padding.left);
...@@ -525,7 +525,7 @@ void main() { ...@@ -525,7 +525,7 @@ void main() {
); );
const double minOverscrollLength = 8.0; const double minOverscrollLength = 8.0;
final ScrollbarPainter p = _buildPainter( final ScrollbarPainter painter = _buildPainter(
padding: padding, padding: padding,
scrollMetrics: metrics, scrollMetrics: metrics,
minLength: 36.0, minLength: 36.0,
...@@ -533,54 +533,54 @@ void main() { ...@@ -533,54 +533,54 @@ void main() {
); );
// No overscroll gives a full sized thumb. // No overscroll gives a full sized thumb.
p.update( painter.update(
metrics.copyWith( metrics.copyWith(
pixels: 0.0, pixels: 0.0,
), ),
AxisDirection.down, AxisDirection.down,
); );
p.paint(testCanvas, size); painter.paint(testCanvas, size);
final double fullThumbExtent = captureRect().height; final double fullThumbExtent = captureRect().height;
expect(fullThumbExtent, greaterThan(_kMinThumbExtent)); expect(fullThumbExtent, greaterThan(_kMinThumbExtent));
// Scrolling to the middle also gives a full sized thumb. // Scrolling to the middle also gives a full sized thumb.
p.update( painter.update(
metrics.copyWith( metrics.copyWith(
pixels: scrollExtent / 2, pixels: scrollExtent / 2,
), ),
AxisDirection.down, AxisDirection.down,
); );
p.paint(testCanvas, size); painter.paint(testCanvas, size);
expect(captureRect().height, moreOrLessEquals(fullThumbExtent, epsilon: 1e-6)); expect(captureRect().height, moreOrLessEquals(fullThumbExtent, epsilon: 1e-6));
// Scrolling just to the very end also gives a full sized thumb. // Scrolling just to the very end also gives a full sized thumb.
p.update( painter.update(
metrics.copyWith( metrics.copyWith(
pixels: scrollExtent, pixels: scrollExtent,
), ),
AxisDirection.down, AxisDirection.down,
); );
p.paint(testCanvas, size); painter.paint(testCanvas, size);
expect(captureRect().height, moreOrLessEquals(fullThumbExtent, epsilon: 1e-6)); expect(captureRect().height, moreOrLessEquals(fullThumbExtent, epsilon: 1e-6));
// Scrolling just past the end shrinks the thumb slightly. // Scrolling just past the end shrinks the thumb slightly.
p.update( painter.update(
metrics.copyWith( metrics.copyWith(
pixels: scrollExtent * 1.001, pixels: scrollExtent * 1.001,
), ),
AxisDirection.down, AxisDirection.down,
); );
p.paint(testCanvas, size); painter.paint(testCanvas, size);
expect(captureRect().height, moreOrLessEquals(fullThumbExtent, epsilon: 2.0)); expect(captureRect().height, moreOrLessEquals(fullThumbExtent, epsilon: 2.0));
// Scrolling way past the end shrinks the thumb to minimum. // Scrolling way past the end shrinks the thumb to minimum.
p.update( painter.update(
metrics.copyWith( metrics.copyWith(
pixels: double.infinity, pixels: double.infinity,
), ),
AxisDirection.down, AxisDirection.down,
); );
p.paint(testCanvas, size); painter.paint(testCanvas, size);
expect(captureRect().height, minOverscrollLength); expect(captureRect().height, minOverscrollLength);
}); });
...@@ -1163,10 +1163,10 @@ void main() { ...@@ -1163,10 +1163,10 @@ void main() {
), ),
); );
await tester.pumpAndSettle(); await tester.pumpAndSettle();
final dynamic exception = tester.takeException(); final AssertionError exception = tester.takeException() as AssertionError;
expect(exception, isAssertionError); expect(exception, isAssertionError);
expect( expect(
(exception as AssertionError).message, exception.message,
contains("The Scrollbar's ScrollController has no ScrollPosition attached."), contains("The Scrollbar's ScrollController has no ScrollPosition attached."),
); );
}); });
...@@ -1198,10 +1198,16 @@ void main() { ...@@ -1198,10 +1198,16 @@ void main() {
await tester.pumpAndSettle(); await tester.pumpAndSettle();
final dynamic exception = tester.takeException(); AssertionError? exception = tester.takeException() as AssertionError?;
// The scrollbar is not visible and cannot be interacted with, so no assertion.
expect(exception, isNull);
// Scroll to trigger the scrollbar to come into view.
final TestGesture gesture = await tester.startGesture(tester.getCenter(find.byType(SingleChildScrollView)));
await gesture.moveBy(const Offset(0.0, -20.0));
exception = tester.takeException() as AssertionError;
expect(exception, isAssertionError); expect(exception, isAssertionError);
expect( expect(
(exception as AssertionError).message, exception.message,
contains("The Scrollbar's ScrollController has no ScrollPosition attached."), contains("The Scrollbar's ScrollController has no ScrollPosition attached."),
); );
}); });
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment