-
Notifications
You must be signed in to change notification settings - Fork 29.8k
Add test for scrollbar.1.dart #151463
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
Add test for scrollbar.1.dart #151463
Conversation
|
I'm not really happy with this test, it doesn't verify the behavior the code sample is made for (displaying the scrollbar thumb all the time). Do you have any suggestions? |
Golden are somewhat opaque, when possible it is way better to use mock canvas as it makes very explicit what is expected to be drawn. testWidgets('Scrollbar appears on drag', (WidgetTester tester) async {
await tester.pumpWidget(
const example.ScrollbarExampleApp(),
);
final Finder scrollbarFinder = find.byType(Scrollbar).last;
expect(scrollbarFinder, isNot(paints..rect()));
await tester.fling(scrollbarFinder.last, const Offset(0, -300), 10.0);
expect(scrollbarFinder.last, paints..rect());
});
This is inspired by https://github.com/flutter/flutter/blob/master/packages/flutter/test/material/scrollbar_paint_test.dart I'm not a Scrollbar testing expert 😄 , so here are two things I noticed while writing this test:
Here is a second test, that checks which items are visible before and after the scroll down: testWidgets('Scrollbar scrolls the items', (WidgetTester tester) async {
await tester.pumpWidget(
const example.ScrollbarExampleApp(),
);
expect(find.text('item 0'), findsOne);
expect(find.text('item 9'), findsNothing);
await tester.fling(find.byType(Scrollbar).last, const Offset(0, -300), 10.0);
expect(find.text('item 0'), findsNothing);
expect(find.text('item 9'), findsOne);
});
|
|
Oh wow! Thank you a lot for that huge help @bleroux ! I didn't know about I implemented the test in test: Verify scrollbar paints all even without user interaction. I also took the opportunity to make |
| await tester.pumpWidget( | ||
| const example.ScrollbarExampleApp(), | ||
| ); | ||
| await tester.pumpAndSettle(); // Waits for all the paints to be done. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I noticed I need a pumpAndSettle() here, several pumps were not doing the trick.
I guess this is because the scrollbar is not painted in the 1st frame as it needs to get the extent of the list. Is there something better to do to make the test pass here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It seems that the following would be ok (Maybe it is clearer than pumpAndSettle with a comment such as the one I added).
await tester.pump();
await tester.pump(const Duration(milliseconds: 10)); // Wait for the thumb to start appearing.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure, I made the change in test: Remove empty line and use pumps
| }, variant: TargetPlatformVariant.all()); | ||
|
|
||
| testWidgets('The scrollbar should be painted when the user scrolls', (WidgetTester tester) async { | ||
|
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Consider removing this extra line
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
😭
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry for that again, I removed it in test: Remove empty line and use pumps
bleroux
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM! Thanks!
| final Finder scrollbarFinder = find.byType(Scrollbar).last; | ||
|
|
||
| expect(find.text('item 0'), findsOne); | ||
| expect(find.text('item 9'), findsNothing); | ||
| expect(scrollbarFinder, isNot(paints..rect())); | ||
|
|
||
| await tester.fling(find.byType(Scrollbar).last, const Offset(0, -300), 10.0); | ||
|
|
||
| expect(find.text('item 0'), findsNothing); | ||
| expect(find.text('item 9'), findsOne); | ||
| expect(scrollbarFinder.last, paints..rect()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here you're using scrollbarFinder but not in the second test.
We should be consistent, i would suggest to not use scrollbarFinder as find.byType(Scrollbar).last is already simple enough.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure, I deleted it in test: Remove unnecessary scrollbarFinder
TahaTesser
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM!
Roll Flutter from 58068d8 to 7d5c1c0 (104 revisions) flutter/flutter@58068d8...7d5c1c0 2024-07-19 104349824+huycozy@users.noreply.github.com Enhances intuitiveness of RawMagnifier's example (flutter/flutter#150308) 2024-07-19 137456488+flutter-pub-roller-bot@users.noreply.github.com Roll pub packages (flutter/flutter#151992) 2024-07-19 32538273+ValentinVignal@users.noreply.github.com Add test for scrollbar.1.dart (flutter/flutter#151463) 2024-07-19 engine-flutter-autoroll@skia.org Roll Flutter Engine from ea1e53a4e810 to 969fb7abc449 (3 revisions) (flutter/flutter#152018) 2024-07-19 goderbauer@google.com docimports for rendering library (flutter/flutter#151958) 2024-07-19 engine-flutter-autoroll@skia.org Roll Flutter Engine from b65c93ea948e to ea1e53a4e810 (2 revisions) (flutter/flutter#152012) 2024-07-19 kevmoo@users.noreply.github.com painting: drop deprecated (exported) hashList and hashValues functions (flutter/flutter#151677) 2024-07-18 engine-flutter-autoroll@skia.org Roll Flutter Engine from 766f7bed7185 to b65c93ea948e (2 revisions) (flutter/flutter#152004) 2024-07-18 magder@google.com Update TESTOWNERS (flutter/flutter#151907) 2024-07-18 n7484443@naver.com chore: fix test name & add description of tests (flutter/flutter#151959) 2024-07-18 engine-flutter-autoroll@skia.org Roll Flutter Engine from 564ded4c4742 to 766f7bed7185 (2 revisions) (flutter/flutter#151998) 2024-07-18 rmolivares@renzo-olivares.dev Fix SelectionArea scrolling conflicts (flutter/flutter#151138) 2024-07-18 rmolivares@renzo-olivares.dev Fix: BaseTapAndDragGestureRecognizer should reset drag state after losing gesture arena (flutter/flutter#151989) 2024-07-18 137456488+flutter-pub-roller-bot@users.noreply.github.com Roll pub packages (flutter/flutter#151975) 2024-07-18 engine-flutter-autoroll@skia.org Roll Flutter Engine from 8bcf638eb893 to 564ded4c4742 (2 revisions) (flutter/flutter#151986) 2024-07-18 88094492+croro613@users.noreply.github.com Fix WidgetStateTextStyle's doc (flutter/flutter#151935) 2024-07-18 engine-flutter-autoroll@skia.org Roll Flutter Engine from d58ba74250ce to 8bcf638eb893 (2 revisions) (flutter/flutter#151977) 2024-07-18 kevinjchisholm@google.com Adds 3.22.3 changelog (flutter/flutter#151974) 2024-07-18 engine-flutter-autoroll@skia.org Roll Packages from d03b1b4 to c7f0526 (8 revisions) (flutter/flutter#151971) 2024-07-18 nate.w5687@gmail.com `WidgetState` mapping (flutter/flutter#146043) 2024-07-18 greg@zulip.com Fix AppBar doc to keep diagram next to its description (flutter/flutter#151937) 2024-07-18 greg@zulip.com Small fixes to Image docs: NNBD, and add a cross-reference (flutter/flutter#151938) 2024-07-18 engine-flutter-autoroll@skia.org Roll Flutter Engine from b043fe447bb3 to d58ba74250ce (1 revision) (flutter/flutter#151964) 2024-07-18 137456488+flutter-pub-roller-bot@users.noreply.github.com Roll pub packages (flutter/flutter#151946) 2024-07-18 137456488+flutter-pub-roller-bot@users.noreply.github.com Roll pub packages (flutter/flutter#151904) 2024-07-18 engine-flutter-autoroll@skia.org Roll Flutter Engine from e3abca2d8105 to b043fe447bb3 (1 revision) (flutter/flutter#151942) 2024-07-18 engine-flutter-autoroll@skia.org Roll Flutter Engine from 8073523b4623 to e3abca2d8105 (1 revision) (flutter/flutter#151936) 2024-07-18 engine-flutter-autoroll@skia.org Roll Flutter Engine from dfe22e3acc19 to 8073523b4623 (1 revision) (flutter/flutter#151934) 2024-07-18 engine-flutter-autoroll@skia.org Roll Flutter Engine from 184c3f0de6b3 to dfe22e3acc19 (1 revision) (flutter/flutter#151930) 2024-07-18 engine-flutter-autoroll@skia.org Roll Flutter Engine from 00f0f6b74da7 to 184c3f0de6b3 (1 revision) (flutter/flutter#151928) 2024-07-18 engine-flutter-autoroll@skia.org Roll Flutter Engine from d194a2f0e5da to 00f0f6b74da7 (1 revision) (flutter/flutter#151927) 2024-07-18 engine-flutter-autoroll@skia.org Roll Flutter Engine from a5a93bb80bd1 to d194a2f0e5da (3 revisions) (flutter/flutter#151925) 2024-07-17 engine-flutter-autoroll@skia.org Roll Flutter Engine from e9dc62074c2b to a5a93bb80bd1 (1 revision) (flutter/flutter#151918) 2024-07-17 yjbanov@google.com [web] use the new backlog Github project in triage links (flutter/flutter#151920) 2024-07-17 yjbanov@google.com Update Flutter-Web-Triage.md (flutter/flutter#151607) 2024-07-17 leroux_bruno@yahoo.fr Reland fix InputDecorator hint default text style on M3 (flutter/flutter#150835) 2024-07-17 engine-flutter-autoroll@skia.org Roll Flutter Engine from 39ee1a549581 to e9dc62074c2b (3 revisions) (flutter/flutter#151915) 2024-07-17 victorsanniay@gmail.com Constrain `CupertinoContextMenu` animation to safe area (flutter/flutter#151860) 2024-07-17 36861262+QuncCccccc@users.noreply.github.com Create `CarouselView` widget - Part 2 (flutter/flutter#149775) 2024-07-17 engine-flutter-autoroll@skia.org Roll Flutter Engine from 45b722b661f0 to 39ee1a549581 (3 revisions) (flutter/flutter#151905) 2024-07-17 34465683+rkishan516@users.noreply.github.com docs: Fix typo in data driven fixes test folder section (flutter/flutter#151836) 2024-07-17 zanderso@users.noreply.github.com Stop running flaky mac tests in presubmit (flutter/flutter#151870) 2024-07-17 engine-flutter-autoroll@skia.org Roll Flutter Engine from 7e2579634027 to 45b722b661f0 (1 revision) (flutter/flutter#151895) 2024-07-17 44146839+essjay05@users.noreply.github.com fix(Flutter Web App): fixes html lang typo (flutter/flutter#151866) 2024-07-17 matanlurey@users.noreply.github.com Delete `docs/engine` directory (flutter/flutter#151616) 2024-07-17 31859944+LongCatIsLooong@users.noreply.github.com Make `CupertinoSlidingSegmentedControl` type parameter non-null (flutter/flutter#151803) ...
Contributes to flutter#130459 It adds a test for - `examples/api/lib/material/scrollbar/scrollbar.1.dart`
Contributes to flutter#130459 It adds a test for - `examples/api/lib/material/scrollbar/scrollbar.1.dart`

Contributes to #130459
It adds a test for
examples/api/lib/material/scrollbar/scrollbar.1.dartPre-launch Checklist
///).If you need help, consider asking for advice on the #hackers-new channel on Discord.