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`
This commit is contained in:
Valentin Vignal 2024-07-19 17:23:32 +08:00 committed by GitHub
parent ea7c77f273
commit 879fa83461
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 47 additions and 1 deletions

View File

@ -322,7 +322,6 @@ final Set<String> _knownMissingTests = <String>{
'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',

View File

@ -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());
});
}

View File

@ -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());
});
}