Skip to content

Create a WidgetTester extension to drag scroll bars (Resolves #22) #23

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

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

angelosilvestre
Copy link
Collaborator

Create a WidgetTester extension to drag scroll bars. Resolves #22

Dragging a scrollbar requires hovering over the scroll bar, waiting for it to appear, and then dragging and releasing it.

This PR adds a dragScrollbar method yo make it easier to interacting with a scrollbar.

We can't use a finder to locate the scrollbar thumb because the scrollbar widget uses a single painter to paint both the scrollbar track and the thumb.

We have a kTapMinTime constant in super_editor that we use in the tests. I needed to use the value directly here.

/// Simulates the user interacting with a Scrollbar.
extension ScrollbarInteractions on WidgetTester {
/// Press a scrollbar thumb at [thumbLocation] and drag it vertically by [delta] pixels.
Future<void> dragScrollbar(Offset thumbLocation, double delta) async {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How does the user know where there scrollbar thumb is located?

Also, we should use this in a test in this package to demonstrate that it works, and show how we expect others to use it.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Currently, there is no way to find the thumb. I filed flutter/flutter#161403.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think if the caller has to provide the thumb location then this doesn't have much value. Can you think of any workaround so that a caller can essentially say "drag the scrollbar 100px down"?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The only way it would work at the moment is if the thumb sits at the top-right of the widget. If it is at any other place, we cannot know its position.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can can't make an educated guess? What if we check the associated scroll offset, total content height, and the height of the scrollbar? Wouldn't that tell us where the thumb should be?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that, if we want to support, all scrollbar's configurations (vertical x horizontal, LTR x RTL, thumb margin, etc), we probably need most of this code...

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd appreciate specificity instead of generalities. In terms of a vertical scrollbar, where does my suggestion fail?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would fail for situations when there is margin/padding on the scrollbar (although it would be simple to add it to this code), and if it's placed on the left side instead of the right side.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What does it mean for there to be margin/padding on the scrollbar?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With margin, the thumb won't use the whole track, there will be an empty space at the edges of the scrollbar.

The padding can be applied to top/bottom/left/right, which means that the thumb might not be placed exactly at the right edge of the scrollable widget.

///
/// By default, this method expects a single [Scrollbar] in the widget tree and
/// finds it `byType`. To specify one [Scrollbar] among many, pass a [finder].
Future<void> dragScrollbar(double delta, [Finder? finder]) async {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should make this action even more clear by adding the direction to the method name, e.g., dragScrollbarDown(300) and dragScrollbarUp(300)

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Create a WidgetTester extension to drag scroll bars
2 participants