From 879fa83461526a327d34036f278d7040f5f539c2 Mon Sep 17 00:00:00 2001 From: Valentin Vignal <32538273+ValentinVignal@users.noreply.github.com> Date: Fri, 19 Jul 2024 17:23:32 +0800 Subject: [PATCH] Add test for scrollbar.1.dart (#151463) Contributes to https://github.com/flutter/flutter/issues/130459 It adds a test for - `examples/api/lib/material/scrollbar/scrollbar.1.dart` --- dev/bots/check_code_samples.dart | 1 - .../material/scrollbar/scrollbar.0_test.dart | 18 ++++++++++++ .../material/scrollbar/scrollbar.1_test.dart | 29 +++++++++++++++++++ 3 files changed, 47 insertions(+), 1 deletion(-) create mode 100644 examples/api/test/material/scrollbar/scrollbar.1_test.dart diff --git a/dev/bots/check_code_samples.dart b/dev/bots/check_code_samples.dart index ad86ad037e..5bd22aa7fb 100644 --- a/dev/bots/check_code_samples.dart +++ b/dev/bots/check_code_samples.dart @@ -322,7 +322,6 @@ final Set _knownMissingTests = { 'examples/api/test/material/flexible_space_bar/flexible_space_bar.0_test.dart', 'examples/api/test/material/chip/deletable_chip_attributes.on_deleted.0_test.dart', 'examples/api/test/material/expansion_panel/expansion_panel_list.expansion_panel_list_radio.0_test.dart', - 'examples/api/test/material/scrollbar/scrollbar.1_test.dart', 'examples/api/test/material/search_anchor/search_anchor.0_test.dart', 'examples/api/test/material/search_anchor/search_anchor.1_test.dart', 'examples/api/test/material/search_anchor/search_anchor.2_test.dart', diff --git a/examples/api/test/material/scrollbar/scrollbar.0_test.dart b/examples/api/test/material/scrollbar/scrollbar.0_test.dart index 330f4f9408..0b5323714c 100644 --- a/examples/api/test/material/scrollbar/scrollbar.0_test.dart +++ b/examples/api/test/material/scrollbar/scrollbar.0_test.dart @@ -18,4 +18,22 @@ void main() { expect(tester.takeException(), isNull); }, variant: TargetPlatformVariant.all()); + + testWidgets('The scrollbar should be painted when the user scrolls', (WidgetTester tester) async { + await tester.pumpWidget( + const example.ScrollbarExampleApp(), + ); + await tester.pump(); + await tester.pump(const Duration(milliseconds: 10)); // Wait for the thumb to start appearing. + + expect(find.text('item 0'), findsOne); + expect(find.text('item 9'), findsNothing); + expect(find.byType(Scrollbar), 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(find.byType(Scrollbar).last, paints..rect()); + }); } diff --git a/examples/api/test/material/scrollbar/scrollbar.1_test.dart b/examples/api/test/material/scrollbar/scrollbar.1_test.dart new file mode 100644 index 0000000000..6ad117f6e6 --- /dev/null +++ b/examples/api/test/material/scrollbar/scrollbar.1_test.dart @@ -0,0 +1,29 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'package:flutter/material.dart'; +import 'package:flutter_api_samples/material/scrollbar/scrollbar.1.dart' as example; +import 'package:flutter_test/flutter_test.dart'; + +void main() { + testWidgets('The scrollbar thumb should be visible at all time', (WidgetTester tester) async { + await tester.pumpWidget( + const example.ScrollbarExampleApp(), + ); + await tester.pump(); + await tester.pump(const Duration(milliseconds: 10)); // Wait for the thumb to start appearing. + + expect(find.widgetWithText(AppBar, 'Scrollbar Sample'), findsOne); + + expect(find.text('item 0'), findsOne); + expect(find.text('item 9'), findsNothing); + expect(find.byType(Scrollbar), 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(find.byType(Scrollbar), paints..rect()); + }); +}