Skip to content

Commit

Permalink
Update unit tests in material library for Material 3 (#128725)
Browse files Browse the repository at this point in the history
Updates most of the unit tests in the packages/flutter/test/material folder so that they'll pass if ThemeData.useMaterial3 defaults to true.

All of the tests have wired useMaterial3 to false and will need to be updated with a M3 version.

related to #127064
  • Loading branch information
QuncCccccc committed Jun 13, 2023
1 parent d499533 commit a5f8b64
Show file tree
Hide file tree
Showing 62 changed files with 1,127 additions and 780 deletions.
36 changes: 24 additions & 12 deletions packages/flutter/test/material/about_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ void main() {

await tester.pumpWidget(
MaterialApp(
theme: ThemeData(useMaterial3: false),
title: 'Pirate app',
home: Scaffold(
appBar: AppBar(
Expand Down Expand Up @@ -167,8 +168,9 @@ void main() {
});

await tester.pumpWidget(
const MaterialApp(
home: Center(
MaterialApp(
theme: ThemeData(useMaterial3: false),
home: const Center(
child: LicensePage(),
),
),
Expand Down Expand Up @@ -220,9 +222,10 @@ void main() {
});

await tester.pumpWidget(
const MaterialApp(
MaterialApp(
theme: ThemeData(useMaterial3: false),
title: 'Pirate app',
home: Center(
home: const Center(
child: LicensePage(
applicationName: 'LicensePage test app',
applicationVersion: '0.1.2',
Expand Down Expand Up @@ -298,6 +301,7 @@ void main() {
await tester.pumpWidget(
MaterialApp(
theme: ThemeData(
useMaterial3: false,
primaryTextTheme: const TextTheme(
titleLarge: titleTextStyle,
titleSmall: subtitleTextStyle,
Expand Down Expand Up @@ -384,8 +388,9 @@ void main() {
});

await tester.pumpWidget(
const MaterialApp(
home: MediaQuery(
MaterialApp(
theme: ThemeData(useMaterial3: false),
home: const MediaQuery(
data: MediaQueryData(
padding: EdgeInsets.all(safeareaPadding),
),
Expand Down Expand Up @@ -830,7 +835,7 @@ void main() {
const Color cardColor = Color(0xFF654321);

await tester.pumpWidget(MaterialApp(
theme: ThemeData.light().copyWith(
theme: ThemeData.light(useMaterial3: false).copyWith(
scaffoldBackgroundColor: scaffoldColor,
cardColor: cardColor,
),
Expand Down Expand Up @@ -1051,7 +1056,12 @@ void main() {

testWidgetsWithLeakTracking('Error handling test', (WidgetTester tester) async {
LicenseRegistry.addLicense(() => Stream<LicenseEntry>.error(Exception('Injected failure')));
await tester.pumpWidget(const MaterialApp(home: Material(child: AboutListTile())));
await tester.pumpWidget(
MaterialApp(
theme: ThemeData(useMaterial3: false),
home: const Material(child: AboutListTile())
)
);
await tester.tap(find.byType(ListTile));
await tester.pump();
await tester.pump(const Duration(seconds: 2));
Expand Down Expand Up @@ -1082,9 +1092,10 @@ void main() {
await tester.binding.setSurfaceSize(defaultSize);

await tester.pumpWidget(
const MaterialApp(
MaterialApp(
theme: ThemeData(useMaterial3: false),
title: title,
home: Scaffold(
home: const Scaffold(
body: Directionality(
textDirection: textDirection,
child: LicensePage(),
Expand Down Expand Up @@ -1145,9 +1156,10 @@ void main() {
await tester.binding.setSurfaceSize(defaultSize);

await tester.pumpWidget(
const MaterialApp(
MaterialApp(
theme: ThemeData(useMaterial3: false),
title: title,
home: Scaffold(
home: const Scaffold(
body: Directionality(
textDirection: textDirection,
child: LicensePage(),
Expand Down
2 changes: 2 additions & 0 deletions packages/flutter/test/material/app_builder_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ void main() {
final List<String> log = <String>[];
final Widget app = MaterialApp(
theme: ThemeData(
useMaterial3: false,
primarySwatch: Colors.green,
),
home: const Placeholder(),
Expand Down Expand Up @@ -42,6 +43,7 @@ void main() {
await tester.pumpWidget(
MaterialApp(
theme: ThemeData(
useMaterial3: false,
primarySwatch: Colors.yellow,
),
home: Builder(
Expand Down
2 changes: 2 additions & 0 deletions packages/flutter/test/material/app_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -995,6 +995,7 @@ void main() {
const Color secondaryColor = Color(0xff008800);
final Color glowSecondaryColor = secondaryColor.withOpacity(0.05);
final ThemeData theme = ThemeData.from(
useMaterial3: false,
colorScheme: const ColorScheme.light().copyWith(secondary: secondaryColor),
);
await tester.pumpWidget(
Expand Down Expand Up @@ -1264,6 +1265,7 @@ void main() {

testWidgets('ScrollBehavior default android overscroll indicator', (WidgetTester tester) async {
await tester.pumpWidget(MaterialApp(
theme: ThemeData(useMaterial3: false),
scrollBehavior: const MaterialScrollBehavior(),
home: ListView(
children: const <Widget>[
Expand Down
2 changes: 1 addition & 1 deletion packages/flutter/test/material/autocomplete_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -459,7 +459,7 @@ void main() {
const Color highlightColor = Color(0xFF112233);
await tester.pumpWidget(
MaterialApp(
theme: ThemeData.light().copyWith(
theme: ThemeData.light(useMaterial3: false).copyWith(
focusColor: highlightColor,
),
home: Scaffold(
Expand Down
2 changes: 2 additions & 0 deletions packages/flutter/test/material/banner_theme_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -457,6 +457,7 @@ void main() {
const String contentText = 'Content';

await tester.pumpWidget(MaterialApp(
theme: ThemeData(useMaterial3: false),
home: Scaffold(
body: MaterialBanner(
content: const Text(contentText),
Expand Down Expand Up @@ -503,6 +504,7 @@ void main() {
const Key tapTarget = Key('tap-target');

await tester.pumpWidget(MaterialApp(
theme: ThemeData(useMaterial3: false),
home: Scaffold(
body: Builder(
builder: (BuildContext context) {
Expand Down
16 changes: 11 additions & 5 deletions packages/flutter/test/material/bottom_app_bar_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ void main() {
child: RepaintBoundary(
key: key,
child: MaterialApp(
theme: ThemeData(useMaterial3: false),
home: Scaffold(
floatingActionButton: FloatingActionButton(
onPressed: () { },
Expand Down Expand Up @@ -217,9 +218,10 @@ void main() {
expect(babRect, const Rect.fromLTRB(240, 520, 560, 600));
});

testWidgets('color defaults to Theme.bottomAppBarColor', (WidgetTester tester) async {
testWidgets('color defaults to Theme.bottomAppBarColor in M2', (WidgetTester tester) async {
await tester.pumpWidget(
MaterialApp(
theme: ThemeData(useMaterial3: false),
home: Builder(
builder: (BuildContext context) {
return Theme(
Expand All @@ -245,6 +247,7 @@ void main() {
testWidgets('color overrides theme color', (WidgetTester tester) async {
await tester.pumpWidget(
MaterialApp(
theme: ThemeData(useMaterial3: false),
home: Builder(
builder: (BuildContext context) {
return Theme(
Expand Down Expand Up @@ -324,7 +327,7 @@ void main() {
testWidgets('dark theme applies an elevation overlay color', (WidgetTester tester) async {
await tester.pumpWidget(
MaterialApp(
theme: ThemeData.from(colorScheme: const ColorScheme.dark()),
theme: ThemeData.from(useMaterial3: false, colorScheme: const ColorScheme.dark()),
home: Scaffold(
bottomNavigationBar: BottomAppBar(
color: const ColorScheme.dark().surface,
Expand Down Expand Up @@ -508,8 +511,9 @@ void main() {

testWidgets('observes safe area', (WidgetTester tester) async {
await tester.pumpWidget(
const MaterialApp(
home: MediaQuery(
MaterialApp(
theme: ThemeData(useMaterial3: false),
home: const MediaQuery(
data: MediaQueryData(
padding: EdgeInsets.all(50.0),
),
Expand Down Expand Up @@ -566,8 +570,10 @@ void main() {

testWidgets('BottomAppBar with shape when Scaffold.bottomNavigationBar == null', (WidgetTester tester) async {
// Regression test for https://github.com/flutter/flutter/issues/80878
final ThemeData theme = ThemeData();
await tester.pumpWidget(
MaterialApp(
theme: theme,
home: Scaffold(
floatingActionButtonLocation: FloatingActionButtonLocation.centerFloat,
floatingActionButton: FloatingActionButton(
Expand Down Expand Up @@ -595,7 +601,7 @@ void main() {
);

expect(tester.getRect(find.byType(FloatingActionButton)), const Rect.fromLTRB(372, 528, 428, 584));
expect(tester.getSize(find.byType(BottomAppBar)), const Size(800, 50));
expect(tester.getSize(find.byType(BottomAppBar)), theme.useMaterial3 ? const Size(800, 80) : const Size(800, 50));
});

testWidgets('notch with margin and top padding, home safe area', (WidgetTester tester) async {
Expand Down
11 changes: 7 additions & 4 deletions packages/flutter/test/material/bottom_app_bar_theme_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ void main() {

await tester.pumpWidget(MaterialApp(
theme: ThemeData(
useMaterial3: false,
bottomAppBarTheme: theme,
bottomAppBarColor: themeColor
),
Expand All @@ -53,6 +54,7 @@ void main() {

await tester.pumpWidget(MaterialApp(
theme: ThemeData(
useMaterial3: false,
bottomAppBarTheme: theme,
bottomAppBarColor: themeColor
),
Expand All @@ -67,7 +69,7 @@ void main() {
const Color themeColor = Colors.white10;

await tester.pumpWidget(MaterialApp(
theme: ThemeData(bottomAppBarColor: themeColor),
theme: ThemeData(useMaterial3: false, bottomAppBarColor: themeColor),
home: const Scaffold(body: BottomAppBar()),
));

Expand All @@ -77,7 +79,7 @@ void main() {

testWidgets('BAB color - Default', (WidgetTester tester) async {
await tester.pumpWidget(MaterialApp(
theme: ThemeData(),
theme: ThemeData(useMaterial3: false),
home: const Scaffold(body: BottomAppBar()),
));

Expand All @@ -102,8 +104,9 @@ void main() {
});

testWidgets('BAB theme does not affect defaults', (WidgetTester tester) async {
await tester.pumpWidget(const MaterialApp(
home: Scaffold(body: BottomAppBar()),
await tester.pumpWidget(MaterialApp(
theme: ThemeData(useMaterial3: false),
home: const Scaffold(body: BottomAppBar()),
));

final PhysicalShape widget = _getBabRenderObject(tester);
Expand Down

0 comments on commit a5f8b64

Please sign in to comment.