Unverified Commit 42924e27 authored by Taha Tesser's avatar Taha Tesser Committed by GitHub

Update `Divider`/`VerticalDivider` and theme tests for M2/M3 (#130415)

Updated unit tests for `Divider`/ `VerticalDivider`  and theme to have M2 and M3 versions.

More info in https://github.com/flutter/flutter/pull/128725
parent 58acd609
...@@ -4,16 +4,29 @@ ...@@ -4,16 +4,29 @@
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart'; import 'package:flutter_test/flutter_test.dart';
import '../rendering/mock_canvas.dart'; import '../rendering/mock_canvas.dart';
void main() { void main() {
testWidgets('Divider control test', (WidgetTester tester) async { testWidgets('Material3 - Divider control test', (WidgetTester tester) async {
await tester.pumpWidget(
MaterialApp(
theme: ThemeData(useMaterial3: true),
home: const Center(child: Divider()),
),
);
final RenderBox box = tester.firstRenderObject(find.byType(Divider));
expect(box.size.height, 16.0);
final Container container = tester.widget(find.byType(Container));
final BoxDecoration decoration = container.decoration! as BoxDecoration;
expect(decoration.border!.bottom.width, 1.0);
});
testWidgets('Material2 - Divider control test', (WidgetTester tester) async {
await tester.pumpWidget( await tester.pumpWidget(
MaterialApp( MaterialApp(
theme: ThemeData(useMaterial3: false), theme: ThemeData(useMaterial3: false),
home: const Center( home: const Center(child: Divider()),
child: Divider(),
),
), ),
); );
final RenderBox box = tester.firstRenderObject(find.byType(Divider)); final RenderBox box = tester.firstRenderObject(find.byType(Divider));
...@@ -27,11 +40,7 @@ void main() { ...@@ -27,11 +40,7 @@ void main() {
await tester.pumpWidget( await tester.pumpWidget(
const Directionality( const Directionality(
textDirection: TextDirection.ltr, textDirection: TextDirection.ltr,
child: Center( child: Center(child: Divider(thickness: 5.0)),
child: Divider(
thickness: 5.0,
),
),
), ),
); );
final Container container = tester.widget(find.byType(Container)); final Container container = tester.widget(find.byType(Container));
...@@ -47,11 +56,7 @@ void main() { ...@@ -47,11 +56,7 @@ void main() {
await tester.pumpWidget( await tester.pumpWidget(
const Directionality( const Directionality(
textDirection: TextDirection.ltr, textDirection: TextDirection.ltr,
child: Center( child: Center(child: Divider(indent: customIndent)),
child: Divider(
indent: customIndent,
),
),
), ),
); );
// The divider line is drawn with a DecoratedBox with a border // The divider line is drawn with a DecoratedBox with a border
...@@ -63,11 +68,7 @@ void main() { ...@@ -63,11 +68,7 @@ void main() {
await tester.pumpWidget( await tester.pumpWidget(
const Directionality( const Directionality(
textDirection: TextDirection.ltr, textDirection: TextDirection.ltr,
child: Center( child: Center(child: Divider(endIndent: customIndent)),
child: Divider(
endIndent: customIndent,
),
),
), ),
); );
dividerRect = tester.getRect(find.byType(Divider)); dividerRect = tester.getRect(find.byType(Divider));
...@@ -92,13 +93,26 @@ void main() { ...@@ -92,13 +93,26 @@ void main() {
expect(lineRect.right, dividerRect.right - customIndent); expect(lineRect.right, dividerRect.right - customIndent);
}); });
testWidgets('Vertical Divider Test', (WidgetTester tester) async { testWidgets('Material3 - Vertical Divider Test', (WidgetTester tester) async {
await tester.pumpWidget(
MaterialApp(
theme: ThemeData(useMaterial3: true),
home: const Center(child: VerticalDivider()),
),
);
final RenderBox box = tester.firstRenderObject(find.byType(VerticalDivider));
expect(box.size.width, 16.0);
final Container container = tester.widget(find.byType(Container));
final BoxDecoration decoration = container.decoration! as BoxDecoration;
final Border border = decoration.border! as Border;
expect(border.left.width, 1.0);
});
testWidgets('Material2 - Vertical Divider Test', (WidgetTester tester) async {
await tester.pumpWidget( await tester.pumpWidget(
MaterialApp( MaterialApp(
theme: ThemeData(useMaterial3: false), theme: ThemeData(useMaterial3: false),
home: const Center( home: const Center(child: VerticalDivider()),
child: VerticalDivider(),
),
), ),
); );
final RenderBox box = tester.firstRenderObject(find.byType(VerticalDivider)); final RenderBox box = tester.firstRenderObject(find.byType(VerticalDivider));
...@@ -113,11 +127,7 @@ void main() { ...@@ -113,11 +127,7 @@ void main() {
await tester.pumpWidget( await tester.pumpWidget(
const Directionality( const Directionality(
textDirection: TextDirection.ltr, textDirection: TextDirection.ltr,
child: Center( child: Center(child: VerticalDivider(thickness: 5.0)),
child: VerticalDivider(
thickness: 5.0,
),
),
), ),
); );
final Container container = tester.widget(find.byType(Container)); final Container container = tester.widget(find.byType(Container));
...@@ -158,11 +168,7 @@ void main() { ...@@ -158,11 +168,7 @@ void main() {
await tester.pumpWidget( await tester.pumpWidget(
const Directionality( const Directionality(
textDirection: TextDirection.ltr, textDirection: TextDirection.ltr,
child: Center( child: Center(child: VerticalDivider(indent: customIndent)),
child: VerticalDivider(
indent: customIndent,
),
),
), ),
); );
// The divider line is drawn with a DecoratedBox with a border // The divider line is drawn with a DecoratedBox with a border
...@@ -174,11 +180,7 @@ void main() { ...@@ -174,11 +180,7 @@ void main() {
await tester.pumpWidget( await tester.pumpWidget(
const Directionality( const Directionality(
textDirection: TextDirection.ltr, textDirection: TextDirection.ltr,
child: Center( child: Center(child: VerticalDivider(endIndent: customIndent)),
child: VerticalDivider(
endIndent: customIndent,
),
),
), ),
); );
dividerRect = tester.getRect(find.byType(VerticalDivider)); dividerRect = tester.getRect(find.byType(VerticalDivider));
......
...@@ -26,9 +26,9 @@ void main() { ...@@ -26,9 +26,9 @@ void main() {
const DividerThemeData().debugFillProperties(builder); const DividerThemeData().debugFillProperties(builder);
final List<String> description = builder.properties final List<String> description = builder.properties
.where((DiagnosticsNode node) => !node.isFiltered(DiagnosticLevel.info)) .where((DiagnosticsNode node) => !node.isFiltered(DiagnosticLevel.info))
.map((DiagnosticsNode node) => node.toString()) .map((DiagnosticsNode node) => node.toString())
.toList(); .toList();
expect(description, <String>[]); expect(description, <String>[]);
}); });
...@@ -44,9 +44,9 @@ void main() { ...@@ -44,9 +44,9 @@ void main() {
).debugFillProperties(builder); ).debugFillProperties(builder);
final List<String> description = builder.properties final List<String> description = builder.properties
.where((DiagnosticsNode node) => !node.isFiltered(DiagnosticLevel.info)) .where((DiagnosticsNode node) => !node.isFiltered(DiagnosticLevel.info))
.map((DiagnosticsNode node) => node.toString()) .map((DiagnosticsNode node) => node.toString())
.toList(); .toList();
expect(description, <String>[ expect(description, <String>[
'color: Color(0xffffffff)', 'color: Color(0xffffffff)',
...@@ -57,7 +57,7 @@ void main() { ...@@ -57,7 +57,7 @@ void main() {
]); ]);
}); });
group('Horizontal Divider', () { group('Material3 - Horizontal Divider', () {
testWidgets('Passing no DividerThemeData returns defaults', (WidgetTester tester) async { testWidgets('Passing no DividerThemeData returns defaults', (WidgetTester tester) async {
final ThemeData theme = ThemeData(useMaterial3: true); final ThemeData theme = ThemeData(useMaterial3: true);
await tester.pumpWidget(MaterialApp( await tester.pumpWidget(MaterialApp(
...@@ -159,7 +159,7 @@ void main() { ...@@ -159,7 +159,7 @@ void main() {
}); });
}); });
group('Vertical Divider', () { group('Material3 - Vertical Divider', () {
testWidgets('Passing no DividerThemeData returns defaults', (WidgetTester tester) async { testWidgets('Passing no DividerThemeData returns defaults', (WidgetTester tester) async {
final ThemeData theme = ThemeData(useMaterial3: true); final ThemeData theme = ThemeData(useMaterial3: true);
await tester.pumpWidget(MaterialApp( await tester.pumpWidget(MaterialApp(
...@@ -270,7 +270,7 @@ void main() { ...@@ -270,7 +270,7 @@ void main() {
// support is deprecated and the APIs are removed, these tests // support is deprecated and the APIs are removed, these tests
// can be deleted. // can be deleted.
group('Horizontal Divider', () { group('Material2 - Horizontal Divider', () {
testWidgets('Passing no DividerThemeData returns defaults', (WidgetTester tester) async { testWidgets('Passing no DividerThemeData returns defaults', (WidgetTester tester) async {
await tester.pumpWidget(MaterialApp( await tester.pumpWidget(MaterialApp(
theme: ThemeData(useMaterial3: false), theme: ThemeData(useMaterial3: false),
...@@ -313,7 +313,7 @@ void main() { ...@@ -313,7 +313,7 @@ void main() {
}); });
}); });
group('Vertical Divider', () { group('Material2 - Vertical Divider', () {
testWidgets('Passing no DividerThemeData returns defaults', (WidgetTester tester) async { testWidgets('Passing no DividerThemeData returns defaults', (WidgetTester tester) async {
await tester.pumpWidget(MaterialApp( await tester.pumpWidget(MaterialApp(
theme: ThemeData(useMaterial3: false), theme: ThemeData(useMaterial3: false),
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment