Unverified Commit 4252aa0f authored by hgraceb's avatar hgraceb Committed by GitHub

Improve slider's value indicator display test (#139198)

The previous test for #128137 does not effectively regress and verify #123313 because the issue is specific to desktop platforms.
parent 72aafe86
......@@ -11,7 +11,7 @@
import 'dart:async';
import 'package:flutter/cupertino.dart';
import 'package:flutter/gestures.dart' show kPrimaryButton;
import 'package:flutter/gestures.dart' show PointerDeviceKind, kPrimaryButton;
import 'package:flutter/material.dart';
import 'package:flutter/scheduler.dart';
import 'package:flutter/services.dart';
......@@ -137,13 +137,18 @@ class _LiveWidgetController extends LiveWidgetController {
return finder;
}
@override
Future<void> tap(FinderBase<Element> finder, { int? pointer, int buttons = kPrimaryButton, bool warnIfMissed = true }) async {
await super.tap(await _waitForElement(finder), pointer: pointer, buttons: buttons, warnIfMissed: warnIfMissed);
}
Future<void> scrollIntoView(FinderBase<Element> finder, {required double alignment}) async {
final FinderBase<Element> target = await _waitForElement(finder);
await Scrollable.ensureVisible(target.evaluate().single, duration: const Duration(milliseconds: 100), alignment: alignment);
}
@override
Future<void> tap(FinderBase<Element> finder, {
int? pointer,
int buttons = kPrimaryButton,
bool warnIfMissed = true,
PointerDeviceKind kind = PointerDeviceKind.touch,
}) async {
await super.tap(await _waitForElement(finder), pointer: pointer, buttons: buttons, warnIfMissed: warnIfMissed, kind: kind);
}
}
......@@ -3432,7 +3432,7 @@ void main() {
await gesture.up();
await tester.pumpAndSettle();
expect(value, isNot(equals(0.5)));
// The slider does not have have focus after the value is changed.
// The slider does not have focus after the value is changed.
expect(focusNode.hasFocus, false);
});
......@@ -3618,8 +3618,8 @@ void main() {
);
}, variant: TargetPlatformVariant.desktop());
testWidgetsWithLeakTracking('Value indicator disappears after adjusting the slider', (WidgetTester tester) async {
// This is a regression test for https://github.com/flutter/flutter/issues/123313.
// Regression test for https://github.com/flutter/flutter/issues/123313, which only occurs on desktop platforms.
testWidgetsWithLeakTracking('Value indicator disappears after adjusting the slider on desktop', (WidgetTester tester) async {
final ThemeData theme = ThemeData(useMaterial3: true);
const double currentValue = 0.5;
await tester.pumpWidget(MaterialApp(
......@@ -3630,7 +3630,7 @@ void main() {
value: currentValue,
divisions: 5,
label: currentValue.toStringAsFixed(1),
onChanged: (double value) {},
onChanged: (_) {},
),
),
),
......@@ -3647,8 +3647,8 @@ void main() {
final Offset sliderCenter = tester.getCenter(find.byType(Slider));
final Offset tapLocation = Offset(sliderCenter.dx + 50, sliderCenter.dy);
// Tap the slider to bring up the value indicator.
await tester.tapAt(tapLocation);
// Tap the slider by mouse to bring up the value indicator.
await tester.tapAt(tapLocation, kind: PointerDeviceKind.mouse);
await tester.pumpAndSettle();
// Value indicator is visible.
......@@ -3666,7 +3666,7 @@ void main() {
valueIndicatorBox,
isNot(paints..scale()..path(color: theme.colorScheme.primary)),
);
});
}, variant: TargetPlatformVariant.desktop());
testWidgetsWithLeakTracking('Value indicator remains when Slider is in focus on desktop', (WidgetTester tester) async {
double value = 0.5;
......
......@@ -987,14 +987,25 @@ abstract class WidgetController {
/// For example, a test that verifies that tapping a disabled button does not
/// trigger the button would set `warnIfMissed` to false, because the button
/// would ignore the tap.
Future<void> tap(finders.FinderBase<Element> finder, {int? pointer, int buttons = kPrimaryButton, bool warnIfMissed = true}) {
return tapAt(getCenter(finder, warnIfMissed: warnIfMissed, callee: 'tap'), pointer: pointer, buttons: buttons);
Future<void> tap(
finders.FinderBase<Element> finder, {
int? pointer,
int buttons = kPrimaryButton,
bool warnIfMissed = true,
PointerDeviceKind kind = PointerDeviceKind.touch,
}) {
return tapAt(getCenter(finder, warnIfMissed: warnIfMissed, callee: 'tap'), pointer: pointer, buttons: buttons, kind: kind);
}
/// Dispatch a pointer down / pointer up sequence at the given location.
Future<void> tapAt(Offset location, {int? pointer, int buttons = kPrimaryButton}) {
Future<void> tapAt(
Offset location, {
int? pointer,
int buttons = kPrimaryButton,
PointerDeviceKind kind = PointerDeviceKind.touch,
}) {
return TestAsyncUtils.guard<void>(() async {
final TestGesture gesture = await startGesture(location, pointer: pointer, buttons: buttons);
final TestGesture gesture = await startGesture(location, pointer: pointer, buttons: buttons, kind: kind);
await gesture.up();
});
}
......@@ -1012,9 +1023,20 @@ abstract class WidgetController {
/// * [tap], which presses and releases a pointer at the given location.
/// * [longPress], which presses and releases a pointer with a gap in
/// between long enough to trigger the long-press gesture.
Future<TestGesture> press(finders.FinderBase<Element> finder, {int? pointer, int buttons = kPrimaryButton, bool warnIfMissed = true}) {
Future<TestGesture> press(
finders.FinderBase<Element> finder, {
int? pointer,
int buttons = kPrimaryButton,
bool warnIfMissed = true,
PointerDeviceKind kind = PointerDeviceKind.touch,
}) {
return TestAsyncUtils.guard<TestGesture>(() {
return startGesture(getCenter(finder, warnIfMissed: warnIfMissed, callee: 'press'), pointer: pointer, buttons: buttons);
return startGesture(
getCenter(finder, warnIfMissed: warnIfMissed, callee: 'press'),
pointer: pointer,
buttons: buttons,
kind: kind,
);
});
}
......@@ -1030,15 +1052,31 @@ abstract class WidgetController {
/// later verify that long-pressing the same location (using the same finder)
/// has no effect (since the widget is now obscured), setting `warnIfMissed`
/// to false on that second call.
Future<void> longPress(finders.FinderBase<Element> finder, {int? pointer, int buttons = kPrimaryButton, bool warnIfMissed = true}) {
return longPressAt(getCenter(finder, warnIfMissed: warnIfMissed, callee: 'longPress'), pointer: pointer, buttons: buttons);
Future<void> longPress(
finders.FinderBase<Element> finder, {
int? pointer,
int buttons = kPrimaryButton,
bool warnIfMissed = true,
PointerDeviceKind kind = PointerDeviceKind.touch,
}) {
return longPressAt(
getCenter(finder, warnIfMissed: warnIfMissed, callee: 'longPress'),
pointer: pointer,
buttons: buttons,
kind: kind,
);
}
/// Dispatch a pointer down / pointer up sequence at the given location with
/// a delay of [kLongPressTimeout] + [kPressTimeout] between the two events.
Future<void> longPressAt(Offset location, {int? pointer, int buttons = kPrimaryButton}) {
Future<void> longPressAt(
Offset location, {
int? pointer,
int buttons = kPrimaryButton,
PointerDeviceKind kind = PointerDeviceKind.touch,
}) {
return TestAsyncUtils.guard<void>(() async {
final TestGesture gesture = await startGesture(location, pointer: pointer, buttons: buttons);
final TestGesture gesture = await startGesture(location, pointer: pointer, buttons: buttons, kind: kind);
await pump(kLongPressTimeout + kPressTimeout);
await gesture.up();
});
......
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