Skip to content

Commit 708fe97

Browse files
authored
test sliver fill remaining examples (#148041)
Par of #130459. Adds tests all `SliverFillRemaining` examples.
1 parent e5f7800 commit 708fe97

File tree

5 files changed

+149
-4
lines changed

5 files changed

+149
-4
lines changed

dev/bots/check_code_samples.dart

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -433,10 +433,6 @@ final Set<String> _knownMissingTests = <String>{
433433
'examples/api/test/widgets/scrollbar/raw_scrollbar.desktop.0_test.dart',
434434
'examples/api/test/widgets/scrollbar/raw_scrollbar.shape.0_test.dart',
435435
'examples/api/test/widgets/scrollbar/raw_scrollbar.0_test.dart',
436-
'examples/api/test/widgets/sliver_fill/sliver_fill_remaining.2_test.dart',
437-
'examples/api/test/widgets/sliver_fill/sliver_fill_remaining.1_test.dart',
438-
'examples/api/test/widgets/sliver_fill/sliver_fill_remaining.3_test.dart',
439-
'examples/api/test/widgets/sliver_fill/sliver_fill_remaining.0_test.dart',
440436
'examples/api/test/widgets/interactive_viewer/interactive_viewer.constrained.0_test.dart',
441437
'examples/api/test/widgets/interactive_viewer/interactive_viewer.transformation_controller.0_test.dart',
442438
'examples/api/test/widgets/interactive_viewer/interactive_viewer.0_test.dart',
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
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/sliver_fill/sliver_fill_remaining.0.dart' as example;
7+
import 'package:flutter_test/flutter_test.dart';
8+
9+
void main() {
10+
testWidgets('shows how SliverFillRemaining takes up remaining space', (WidgetTester tester) async {
11+
await tester.pumpWidget(const example.SliverFillRemainingExampleApp());
12+
expect(find.text('SliverFillRemaining Sample'), findsOneWidget);
13+
expect(find.byType(CustomScrollView), findsOneWidget);
14+
15+
expect(find.descendant(
16+
of: find.byType(SliverToBoxAdapter),
17+
matching: find.byType(Container)), findsOneWidget);
18+
final Container upperContainer = tester.widget(find.descendant(
19+
of: find.byType(SliverToBoxAdapter),
20+
matching: find.byType(Container)));
21+
expect(upperContainer.color, Colors.amber[300]);
22+
23+
expect(find.byType(SliverFillRemaining), findsOneWidget);
24+
expect(find.descendant(
25+
of: find.byType(SliverFillRemaining),
26+
matching: find.byType(Container)), findsOneWidget);
27+
expect(find.byIcon(Icons.sentiment_very_satisfied), findsOneWidget);
28+
final Icon lowerIcon = tester.widget(find.descendant(
29+
of: find.byType(SliverFillRemaining),
30+
matching: find.byType(Icon)));
31+
expect(lowerIcon.color, Colors.blue[900]);
32+
33+
final double total = tester.getSize(find.byType(CustomScrollView)).height;
34+
final double upperHeight = tester.getSize(find.descendant(
35+
of: find.byType(SliverToBoxAdapter),
36+
matching: find.byType(Container))).height;
37+
final double lowerHeight = tester.getSize(find.descendant(
38+
of: find.byType(SliverFillRemaining),
39+
matching: find.byType(Icon))).height;
40+
expect(upperHeight + lowerHeight, equals(total));
41+
});
42+
}
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
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/sliver_fill/sliver_fill_remaining.1.dart' as example;
7+
import 'package:flutter_test/flutter_test.dart';
8+
9+
void main() {
10+
testWidgets('Shows all elements', (WidgetTester tester) async {
11+
await tester.pumpWidget(const example.SliverFillRemainingExampleApp());
12+
expect(find.text('SliverFillRemaining Sample'), findsOneWidget);
13+
expect(find.byType(CustomScrollView), findsOneWidget);
14+
expect(find.byWidgetPredicate((Widget widget) => (widget is Container)
15+
&& widget.color == Colors.amber[200]),
16+
findsNWidgets(2));
17+
expect(find.byWidgetPredicate((Widget widget) => (widget is Container)
18+
&& widget.color == Colors.blue[200]),
19+
findsOneWidget);
20+
expect(find.byWidgetPredicate((Widget widget) => (widget is Container)
21+
&& widget.color == Colors.orange[300]),
22+
findsOneWidget);
23+
expect(find.byType(SliverFixedExtentList), findsOneWidget);
24+
expect(find.byType(SliverFillRemaining), findsOneWidget);
25+
expect(find.byType(FlutterLogo), findsOneWidget);
26+
});
27+
28+
testWidgets('Fills up all available space', (WidgetTester tester) async {
29+
await tester.pumpWidget(const example.SliverFillRemainingExampleApp());
30+
31+
final double listSpace = tester.getSize(find.byType(CustomScrollView)).height;
32+
double contentHeight = 0.0;
33+
for (final Widget widget in tester.widgetList(find.byWidgetPredicate(
34+
(Widget widget) =>
35+
(widget is Container)
36+
&& <Color>[Colors.orange[300]!, Colors.blue[200]!, Colors.amber[200]!]
37+
.contains(widget.color)))
38+
) {
39+
contentHeight += tester.getSize(find.byWidget(widget)).height;
40+
}
41+
expectLater(contentHeight, equals(listSpace));
42+
});
43+
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
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/sliver_fill/sliver_fill_remaining.2.dart' as example;
7+
import 'package:flutter_test/flutter_test.dart';
8+
9+
void main() {
10+
testWidgets('Shows all elements', (WidgetTester tester) async {
11+
await tester.pumpWidget(const example.SliverFillRemainingExampleApp());
12+
expect(find.text('SliverFillRemaining Sample'), findsOneWidget);
13+
expect(find.byType(CustomScrollView), findsOneWidget);
14+
expect(find.byType(SliverFixedExtentList), findsOneWidget);
15+
16+
expect(find.byWidgetPredicate((Widget widget) => (widget is Container)
17+
&& widget.color == Colors.indigo[200],
18+
skipOffstage: false,
19+
), findsNWidgets(3));
20+
expect(find.byWidgetPredicate((Widget widget) => (widget is Container)
21+
&& widget.color == Colors.orange[200]
22+
), findsNWidgets(2));
23+
expect(find.byType(Container, skipOffstage: false,), findsNWidgets(5));
24+
25+
expect(find.byType(SliverFillRemaining), findsNothing);
26+
await tester.scrollUntilVisible(find.byType(SliverFillRemaining), 20);
27+
expect(find.byType(SliverFillRemaining), findsOneWidget);
28+
expect(find.byIcon(Icons.pan_tool), findsOneWidget);
29+
expect(tester.widget<Icon>(find.byIcon(Icons.pan_tool)).color, Colors.blueGrey);
30+
});
31+
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
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/sliver_fill/sliver_fill_remaining.3.dart' as example;
7+
import 'package:flutter_test/flutter_test.dart';
8+
9+
void main() {
10+
testWidgets('Shows all elements', (WidgetTester tester) async {
11+
await tester.pumpWidget(const example.SliverFillRemainingExampleApp());
12+
expect(find.text('SliverFillRemaining Sample'), findsOneWidget);
13+
expect(find.byType(ElevatedButton), findsOneWidget);
14+
expect(find.text('Bottom Pinned Button!'), findsOneWidget);
15+
expect(find.byType(CustomScrollView), findsOneWidget);
16+
final CustomScrollView scroll = tester.widget(find.byType(CustomScrollView));
17+
expect(scroll.physics, isA<BouncingScrollPhysics>().
18+
having((BouncingScrollPhysics bsp) => bsp.parent, 'parent', isA<AlwaysScrollableScrollPhysics>()));
19+
20+
expect(find.byWidgetPredicate((Widget widget) => (widget is Container)
21+
&& widget.color == Colors.tealAccent[700],
22+
), findsOneWidget);
23+
expect(find.byWidgetPredicate((Widget widget) => (widget is Container)
24+
&& widget.color == Colors.teal[100]
25+
), findsOneWidget);
26+
expect(find.byType(Container), findsNWidgets(2));
27+
28+
expect(find.byType(SliverFillRemaining), findsOneWidget);
29+
final SliverFillRemaining fill = tester.widget(find.byType(SliverFillRemaining));
30+
expect(fill.hasScrollBody, false);
31+
expect(fill.fillOverscroll, true);
32+
});
33+
}

0 commit comments

Comments
 (0)