-
Notifications
You must be signed in to change notification settings - Fork 26.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test sliver fill remaining examples (#148041)
Par of #130459. Adds tests all `SliverFillRemaining` examples.
- Loading branch information
1 parent
e5f7800
commit 708fe97
Showing
5 changed files
with
149 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
42 changes: 42 additions & 0 deletions
42
examples/api/test/widgets/sliver_fill/sliver_fill_remaining.0_test.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
// 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/sliver_fill/sliver_fill_remaining.0.dart' as example; | ||
import 'package:flutter_test/flutter_test.dart'; | ||
|
||
void main() { | ||
testWidgets('shows how SliverFillRemaining takes up remaining space', (WidgetTester tester) async { | ||
await tester.pumpWidget(const example.SliverFillRemainingExampleApp()); | ||
expect(find.text('SliverFillRemaining Sample'), findsOneWidget); | ||
expect(find.byType(CustomScrollView), findsOneWidget); | ||
|
||
expect(find.descendant( | ||
of: find.byType(SliverToBoxAdapter), | ||
matching: find.byType(Container)), findsOneWidget); | ||
final Container upperContainer = tester.widget(find.descendant( | ||
of: find.byType(SliverToBoxAdapter), | ||
matching: find.byType(Container))); | ||
expect(upperContainer.color, Colors.amber[300]); | ||
|
||
expect(find.byType(SliverFillRemaining), findsOneWidget); | ||
expect(find.descendant( | ||
of: find.byType(SliverFillRemaining), | ||
matching: find.byType(Container)), findsOneWidget); | ||
expect(find.byIcon(Icons.sentiment_very_satisfied), findsOneWidget); | ||
final Icon lowerIcon = tester.widget(find.descendant( | ||
of: find.byType(SliverFillRemaining), | ||
matching: find.byType(Icon))); | ||
expect(lowerIcon.color, Colors.blue[900]); | ||
|
||
final double total = tester.getSize(find.byType(CustomScrollView)).height; | ||
final double upperHeight = tester.getSize(find.descendant( | ||
of: find.byType(SliverToBoxAdapter), | ||
matching: find.byType(Container))).height; | ||
final double lowerHeight = tester.getSize(find.descendant( | ||
of: find.byType(SliverFillRemaining), | ||
matching: find.byType(Icon))).height; | ||
expect(upperHeight + lowerHeight, equals(total)); | ||
}); | ||
} |
43 changes: 43 additions & 0 deletions
43
examples/api/test/widgets/sliver_fill/sliver_fill_remaining.1_test.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
// 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/sliver_fill/sliver_fill_remaining.1.dart' as example; | ||
import 'package:flutter_test/flutter_test.dart'; | ||
|
||
void main() { | ||
testWidgets('Shows all elements', (WidgetTester tester) async { | ||
await tester.pumpWidget(const example.SliverFillRemainingExampleApp()); | ||
expect(find.text('SliverFillRemaining Sample'), findsOneWidget); | ||
expect(find.byType(CustomScrollView), findsOneWidget); | ||
expect(find.byWidgetPredicate((Widget widget) => (widget is Container) | ||
&& widget.color == Colors.amber[200]), | ||
findsNWidgets(2)); | ||
expect(find.byWidgetPredicate((Widget widget) => (widget is Container) | ||
&& widget.color == Colors.blue[200]), | ||
findsOneWidget); | ||
expect(find.byWidgetPredicate((Widget widget) => (widget is Container) | ||
&& widget.color == Colors.orange[300]), | ||
findsOneWidget); | ||
expect(find.byType(SliverFixedExtentList), findsOneWidget); | ||
expect(find.byType(SliverFillRemaining), findsOneWidget); | ||
expect(find.byType(FlutterLogo), findsOneWidget); | ||
}); | ||
|
||
testWidgets('Fills up all available space', (WidgetTester tester) async { | ||
await tester.pumpWidget(const example.SliverFillRemainingExampleApp()); | ||
|
||
final double listSpace = tester.getSize(find.byType(CustomScrollView)).height; | ||
double contentHeight = 0.0; | ||
for (final Widget widget in tester.widgetList(find.byWidgetPredicate( | ||
(Widget widget) => | ||
(widget is Container) | ||
&& <Color>[Colors.orange[300]!, Colors.blue[200]!, Colors.amber[200]!] | ||
.contains(widget.color))) | ||
) { | ||
contentHeight += tester.getSize(find.byWidget(widget)).height; | ||
} | ||
expectLater(contentHeight, equals(listSpace)); | ||
}); | ||
} |
31 changes: 31 additions & 0 deletions
31
examples/api/test/widgets/sliver_fill/sliver_fill_remaining.2_test.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
// 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/sliver_fill/sliver_fill_remaining.2.dart' as example; | ||
import 'package:flutter_test/flutter_test.dart'; | ||
|
||
void main() { | ||
testWidgets('Shows all elements', (WidgetTester tester) async { | ||
await tester.pumpWidget(const example.SliverFillRemainingExampleApp()); | ||
expect(find.text('SliverFillRemaining Sample'), findsOneWidget); | ||
expect(find.byType(CustomScrollView), findsOneWidget); | ||
expect(find.byType(SliverFixedExtentList), findsOneWidget); | ||
|
||
expect(find.byWidgetPredicate((Widget widget) => (widget is Container) | ||
&& widget.color == Colors.indigo[200], | ||
skipOffstage: false, | ||
), findsNWidgets(3)); | ||
expect(find.byWidgetPredicate((Widget widget) => (widget is Container) | ||
&& widget.color == Colors.orange[200] | ||
), findsNWidgets(2)); | ||
expect(find.byType(Container, skipOffstage: false,), findsNWidgets(5)); | ||
|
||
expect(find.byType(SliverFillRemaining), findsNothing); | ||
await tester.scrollUntilVisible(find.byType(SliverFillRemaining), 20); | ||
expect(find.byType(SliverFillRemaining), findsOneWidget); | ||
expect(find.byIcon(Icons.pan_tool), findsOneWidget); | ||
expect(tester.widget<Icon>(find.byIcon(Icons.pan_tool)).color, Colors.blueGrey); | ||
}); | ||
} |
33 changes: 33 additions & 0 deletions
33
examples/api/test/widgets/sliver_fill/sliver_fill_remaining.3_test.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
// 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/sliver_fill/sliver_fill_remaining.3.dart' as example; | ||
import 'package:flutter_test/flutter_test.dart'; | ||
|
||
void main() { | ||
testWidgets('Shows all elements', (WidgetTester tester) async { | ||
await tester.pumpWidget(const example.SliverFillRemainingExampleApp()); | ||
expect(find.text('SliverFillRemaining Sample'), findsOneWidget); | ||
expect(find.byType(ElevatedButton), findsOneWidget); | ||
expect(find.text('Bottom Pinned Button!'), findsOneWidget); | ||
expect(find.byType(CustomScrollView), findsOneWidget); | ||
final CustomScrollView scroll = tester.widget(find.byType(CustomScrollView)); | ||
expect(scroll.physics, isA<BouncingScrollPhysics>(). | ||
having((BouncingScrollPhysics bsp) => bsp.parent, 'parent', isA<AlwaysScrollableScrollPhysics>())); | ||
|
||
expect(find.byWidgetPredicate((Widget widget) => (widget is Container) | ||
&& widget.color == Colors.tealAccent[700], | ||
), findsOneWidget); | ||
expect(find.byWidgetPredicate((Widget widget) => (widget is Container) | ||
&& widget.color == Colors.teal[100] | ||
), findsOneWidget); | ||
expect(find.byType(Container), findsNWidgets(2)); | ||
|
||
expect(find.byType(SliverFillRemaining), findsOneWidget); | ||
final SliverFillRemaining fill = tester.widget(find.byType(SliverFillRemaining)); | ||
expect(fill.hasScrollBody, false); | ||
expect(fill.fillOverscroll, true); | ||
}); | ||
} |