diff --git a/dev/bots/check_code_samples.dart b/dev/bots/check_code_samples.dart index 4622830b93..c37046959e 100644 --- a/dev/bots/check_code_samples.dart +++ b/dev/bots/check_code_samples.dart @@ -358,6 +358,5 @@ final Set _knownMissingTests = { 'examples/api/test/widgets/restoration/restoration_mixin.0_test.dart', 'examples/api/test/widgets/actions/focusable_action_detector.0_test.dart', 'examples/api/test/widgets/focus_scope/focus_scope.0_test.dart', - 'examples/api/test/widgets/scroll_view/custom_scroll_view.1_test.dart', 'examples/api/test/gestures/pointer_signal_resolver/pointer_signal_resolver.0_test.dart', }; diff --git a/examples/api/test/widgets/scroll_view/custom_scroll_view.1_test.dart b/examples/api/test/widgets/scroll_view/custom_scroll_view.1_test.dart new file mode 100644 index 0000000000..007cbf44e8 --- /dev/null +++ b/examples/api/test/widgets/scroll_view/custom_scroll_view.1_test.dart @@ -0,0 +1,47 @@ +// 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/widgets/scroll_view/custom_scroll_view.1.dart' as example; +import 'package:flutter_test/flutter_test.dart'; + +void main() { + testWidgets('What should be visible in the initial state.', (WidgetTester tester) async { + await tester.pumpWidget(const example.CustomScrollViewExampleApp()); + + expect(find.descendant( + of: find.byType(IconButton), + matching: find.byIcon(Icons.add), + ), findsOne); + expect(find.byType(SliverList), findsOne); + + // Initial state should present only "Item: 0" on the SliverList. + expect(find.widgetWithText(SliverList, 'Item: 0'), findsOne); + expect(find.widgetWithText(SliverList, 'Item: -1'), findsNothing); + expect(find.widgetWithText(SliverList, 'Item: 1'), findsNothing); +}); + + testWidgets('Items are added correctly', (WidgetTester tester) async { + await tester.pumpWidget(const example.CustomScrollViewExampleApp()); + + await tester.tap(find.byType(IconButton)); + await tester.pump(); + + // 'Item: -1' is invisible before scrolling. + expect(find.widgetWithText(SliverList, 'Item: -1'), findsNothing); + expect(find.widgetWithText(SliverList, 'Item: 1'), findsOne); + + // Scroll the updated screen. + await tester.drag(find.byType(CustomScrollView), const Offset(0.0, 50.0)); + await tester.pump(); + + // An additional SliverList appears. + expect(find.byType(SliverList), findsExactly(2)); + + // All items are visible. + expect(find.widgetWithText(SliverList, 'Item: -1'), findsOne); + expect(find.widgetWithText(SliverList, 'Item: 0'), findsOne); + expect(find.widgetWithText(SliverList, 'Item: 1'), findsOne); + }); +}