test sliver fill remaining examples (#148041)
Par of #130459. Adds tests all `SliverFillRemaining` examples.
This commit is contained in:
parent
e5f7800171
commit
708fe97f9e
@ -433,10 +433,6 @@ final Set<String> _knownMissingTests = <String>{
|
||||
'examples/api/test/widgets/scrollbar/raw_scrollbar.desktop.0_test.dart',
|
||||
'examples/api/test/widgets/scrollbar/raw_scrollbar.shape.0_test.dart',
|
||||
'examples/api/test/widgets/scrollbar/raw_scrollbar.0_test.dart',
|
||||
'examples/api/test/widgets/sliver_fill/sliver_fill_remaining.2_test.dart',
|
||||
'examples/api/test/widgets/sliver_fill/sliver_fill_remaining.1_test.dart',
|
||||
'examples/api/test/widgets/sliver_fill/sliver_fill_remaining.3_test.dart',
|
||||
'examples/api/test/widgets/sliver_fill/sliver_fill_remaining.0_test.dart',
|
||||
'examples/api/test/widgets/interactive_viewer/interactive_viewer.constrained.0_test.dart',
|
||||
'examples/api/test/widgets/interactive_viewer/interactive_viewer.transformation_controller.0_test.dart',
|
||||
'examples/api/test/widgets/interactive_viewer/interactive_viewer.0_test.dart',
|
||||
|
@ -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));
|
||||
});
|
||||
}
|
@ -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));
|
||||
});
|
||||
}
|
@ -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);
|
||||
});
|
||||
}
|
@ -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);
|
||||
});
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user