|
| 1 | +// Copyright 2014 The Flutter Authors. All rights reserved. |
| 2 | +// Use of this source code is governed by a BSD-style license that can be |
| 3 | +// found in the LICENSE file. |
| 4 | + |
| 5 | +import 'package:flutter/material.dart'; |
| 6 | +import 'package:flutter_api_samples/widgets/scroll_view/custom_scroll_view.1.dart' as example; |
| 7 | +import 'package:flutter_test/flutter_test.dart'; |
| 8 | + |
| 9 | +void main() { |
| 10 | + testWidgets('What should be visible in the initial state.', (WidgetTester tester) async { |
| 11 | + await tester.pumpWidget(const example.CustomScrollViewExampleApp()); |
| 12 | + |
| 13 | + expect(find.descendant( |
| 14 | + of: find.byType(IconButton), |
| 15 | + matching: find.byIcon(Icons.add), |
| 16 | + ), findsOne); |
| 17 | + expect(find.byType(SliverList), findsOne); |
| 18 | + |
| 19 | + // Initial state should present only "Item: 0" on the SliverList. |
| 20 | + expect(find.widgetWithText(SliverList, 'Item: 0'), findsOne); |
| 21 | + expect(find.widgetWithText(SliverList, 'Item: -1'), findsNothing); |
| 22 | + expect(find.widgetWithText(SliverList, 'Item: 1'), findsNothing); |
| 23 | +}); |
| 24 | + |
| 25 | + testWidgets('Items are added correctly', (WidgetTester tester) async { |
| 26 | + await tester.pumpWidget(const example.CustomScrollViewExampleApp()); |
| 27 | + |
| 28 | + await tester.tap(find.byType(IconButton)); |
| 29 | + await tester.pump(); |
| 30 | + |
| 31 | + // 'Item: -1' is invisible before scrolling. |
| 32 | + expect(find.widgetWithText(SliverList, 'Item: -1'), findsNothing); |
| 33 | + expect(find.widgetWithText(SliverList, 'Item: 1'), findsOne); |
| 34 | + |
| 35 | + // Scroll the updated screen. |
| 36 | + await tester.drag(find.byType(CustomScrollView), const Offset(0.0, 50.0)); |
| 37 | + await tester.pump(); |
| 38 | + |
| 39 | + // An additional SliverList appears. |
| 40 | + expect(find.byType(SliverList), findsExactly(2)); |
| 41 | + |
| 42 | + // All items are visible. |
| 43 | + expect(find.widgetWithText(SliverList, 'Item: -1'), findsOne); |
| 44 | + expect(find.widgetWithText(SliverList, 'Item: 0'), findsOne); |
| 45 | + expect(find.widgetWithText(SliverList, 'Item: 1'), findsOne); |
| 46 | + }); |
| 47 | +} |
0 commit comments