Skip to content

Commit

Permalink
Convert lightTheme and darkTheme to methods (#1234)
Browse files Browse the repository at this point in the history
This PR converts the variables `lightTheme` and `darkTheme` to the
methods `getLightTheme()` and `getDarkTheme()`. The reason for this is
that in golden tests outside of `/app`, the `golden_toolkit` package is
unable to load our "Rubik" font (see
eBay/flutter_glove_box#158). With this method,
the golden tests can override the font family with a font like "Roboto".
  • Loading branch information
nilsreichardt authored Jan 6, 2024
1 parent 75cb922 commit e22d4b6
Show file tree
Hide file tree
Showing 23 changed files with 253 additions and 248 deletions.
4 changes: 2 additions & 2 deletions app/lib/main/sharezone_material_app.dart
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,9 @@ class SharezoneMaterialApp extends StatelessWidget {
debugShowCheckedModeBanner: false,
title: PlatformCheck.isWeb ? "Sharezone Web-App" : "Sharezone",
color: primaryColor,
darkTheme: darkTheme.copyWith(
darkTheme: getDarkTheme().copyWith(
visualDensity: themeSettings.visualDensitySetting.visualDensity),
theme: lightTheme.copyWith(
theme: getLightTheme().copyWith(
visualDensity: themeSettings.visualDensitySetting.visualDensity),
themeMode: _getThemeMode(themeSettings.themeBrightness),
localizationsDelegates: const [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ class DeleteConfirmationCheckbox extends StatelessWidget {
Material(
color: Colors.transparent,
child: Theme(
data: darkTheme,
data: getDarkTheme(),
child: Checkbox(
value: confirm,
onChanged: onChanged,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ void main() {
});

testGoldens('(light mode)', (tester) async {
await pumpPage(tester, theme: lightTheme);
await pumpPage(tester, theme: getLightTheme());

await multiScreenGolden(
tester,
Expand All @@ -89,7 +89,7 @@ void main() {
});

testGoldens('(dark mode)', (tester) async {
await pumpPage(tester, theme: darkTheme);
await pumpPage(tester, theme: getDarkTheme());

await multiScreenGolden(
tester,
Expand All @@ -106,7 +106,7 @@ void main() {
});

testGoldens('(light mode)', (tester) async {
await pumpPage(tester, theme: lightTheme);
await pumpPage(tester, theme: getLightTheme());

await multiScreenGolden(
tester,
Expand All @@ -115,7 +115,7 @@ void main() {
});

testGoldens('(dark mode)', (tester) async {
await pumpPage(tester, theme: darkTheme);
await pumpPage(tester, theme: getDarkTheme());

await multiScreenGolden(
tester,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ void main() {
});

testGoldens('renders correctly (light theme)', (tester) async {
await pumpPage(tester, theme: lightTheme);
await pumpPage(tester, theme: getLightTheme());

await multiScreenGolden(
tester,
Expand All @@ -93,7 +93,7 @@ void main() {
});

testGoldens('renders correctly (dark theme)', (tester) async {
await pumpPage(tester, theme: darkTheme);
await pumpPage(tester, theme: getDarkTheme());

await multiScreenGolden(
tester,
Expand All @@ -112,7 +112,7 @@ void main() {
});

testGoldens('renders correctly (light theme)', (tester) async {
await pumpPage(tester, theme: lightTheme);
await pumpPage(tester, theme: getLightTheme());

await multiScreenGolden(
tester,
Expand All @@ -121,7 +121,7 @@ void main() {
});

testGoldens('renders correctly (dark theme)', (tester) async {
await pumpPage(tester, theme: darkTheme);
await pumpPage(tester, theme: getDarkTheme());

await multiScreenGolden(
tester,
Expand Down
2 changes: 1 addition & 1 deletion app/test_goldens/dashboard/dashboard_page_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ void main() {
BlocProvider<HolidayBloc>(
bloc: holidayBloc,
child: MaterialApp(
theme: lightTheme,
theme: getLightTheme(),
home: const Scaffold(
body: Center(
child: HolidayCountdownSection(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,22 +67,22 @@ void main() {

testGoldens('displays select base color dialog as expected (light mode)',
(tester) async {
await pumpSelectDesignDialog(tester, theme: lightTheme);
await pumpSelectDesignDialog(tester, theme: getLightTheme());

await multiScreenGolden(tester, 'select_base_color_dialog_light');
});

testGoldens('displays select base color dialog as expected (dark mode)',
(tester) async {
await pumpSelectDesignDialog(tester, theme: darkTheme);
await pumpSelectDesignDialog(tester, theme: getDarkTheme());

await multiScreenGolden(tester, 'select_base_color_dialog_dark');
});

testGoldens(
'displays select a color shade dialog as expected (light mode)',
(tester) async {
await pumpSelectDesignDialog(tester, theme: lightTheme);
await pumpSelectDesignDialog(tester, theme: getLightTheme());

await tester
.tap(find.byKey(Key('color-circle-${Colors.blue.value}')).last);
Expand All @@ -94,7 +94,7 @@ void main() {
testGoldens(
'displays select a color shade dialog as expected (dark mode)',
(tester) async {
await pumpSelectDesignDialog(tester, theme: darkTheme);
await pumpSelectDesignDialog(tester, theme: getDarkTheme());

await tester
.tap(find.byKey(Key('color-circle-${Colors.blue.value}')).last);
Expand All @@ -113,14 +113,14 @@ void main() {

testGoldens('displays select design dialog as expected (light mode)',
(tester) async {
await pumpSelectDesignDialog(tester, theme: lightTheme);
await pumpSelectDesignDialog(tester, theme: getLightTheme());

await multiScreenGolden(tester, 'select_free_design_dialog_light');
});

testGoldens('displays select design dialog as expected (dark mode)',
(tester) async {
await pumpSelectDesignDialog(tester, theme: darkTheme);
await pumpSelectDesignDialog(tester, theme: getDarkTheme());

await multiScreenGolden(tester, 'select_free_design_dialog_dark');
});
Expand Down
24 changes: 12 additions & 12 deletions app/test_goldens/homework/homework_dialog/homework_dialog_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -65,15 +65,15 @@ void main() {
);

await pumpAndSettleHomeworkDialog(tester,
isEditing: false, theme: lightTheme);
isEditing: false, theme: getLightTheme());

await multiScreenGolden(
tester,
'homework_dialog_add_empty_light',
);

await pumpAndSettleHomeworkDialog(tester,
isEditing: false, theme: darkTheme);
isEditing: false, theme: getDarkTheme());

await multiScreenGolden(
tester,
Expand Down Expand Up @@ -131,15 +131,15 @@ void main() {
);

await pumpAndSettleHomeworkDialog(tester,
isEditing: false, theme: lightTheme);
isEditing: false, theme: getLightTheme());

await multiScreenGolden(
tester,
'homework_dialog_add_filled_1_light',
);

await pumpAndSettleHomeworkDialog(tester,
isEditing: false, theme: darkTheme);
isEditing: false, theme: getDarkTheme());

await multiScreenGolden(
tester,
Expand Down Expand Up @@ -200,7 +200,7 @@ void main() {
whenListenPresentation(homeworkDialogBloc,
initialEvents: [const StartedUploadingAttachments()]);
await pumpAndSettleHomeworkDialog(tester,
isEditing: false, theme: lightTheme);
isEditing: false, theme: getLightTheme());

// Wait for the SnackBar to appear.
await tester.pump(const Duration(milliseconds: 500));
Expand All @@ -223,7 +223,7 @@ void main() {
await pumpAndSettleHomeworkDialog(
tester,
isEditing: false,
theme: darkTheme,
theme: getDarkTheme(),
);
// Otherwise the theme is not completly applied (some text is still black
// instead of white).
Expand Down Expand Up @@ -293,7 +293,7 @@ void main() {
SavingFailed(Exception('Test Exception Message'), null)
]);
await pumpAndSettleHomeworkDialog(tester,
isEditing: false, theme: lightTheme);
isEditing: false, theme: getLightTheme());

// Wait for the SnackBar to appear.
await tester.pump(const Duration(milliseconds: 500));
Expand All @@ -318,7 +318,7 @@ void main() {
await pumpAndSettleHomeworkDialog(
tester,
isEditing: false,
theme: darkTheme,
theme: getDarkTheme(),
);
// Otherwise the theme is not completly applied (some text is still black
// instead of white).
Expand Down Expand Up @@ -357,15 +357,15 @@ void main() {
initialEvents: [const RequiredFieldsNotFilledOut()]);

await pumpAndSettleHomeworkDialog(tester,
isEditing: false, theme: lightTheme);
isEditing: false, theme: getLightTheme());

await multiScreenGolden(
tester,
'homework_dialog_with_error_light',
);

await pumpAndSettleHomeworkDialog(tester,
isEditing: false, theme: darkTheme);
isEditing: false, theme: getDarkTheme());

await multiScreenGolden(
tester,
Expand Down Expand Up @@ -415,15 +415,15 @@ void main() {
);

await pumpAndSettleHomeworkDialog(tester,
isEditing: false, theme: lightTheme);
isEditing: false, theme: getLightTheme());

await multiScreenGolden(
tester,
'homework_dialog_edit_filled_1_light',
);

await pumpAndSettleHomeworkDialog(tester,
isEditing: false, theme: darkTheme);
isEditing: false, theme: getDarkTheme());

await multiScreenGolden(
tester,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ void main() {
});

testGoldens('(light mode)', (tester) async {
await pumpPage(tester, theme: lightTheme);
await pumpPage(tester, theme: getLightTheme());

await multiScreenGolden(
tester,
Expand All @@ -93,7 +93,7 @@ void main() {
});

testGoldens('(dark mode)', (tester) async {
await pumpPage(tester, theme: darkTheme);
await pumpPage(tester, theme: getDarkTheme());

await multiScreenGolden(
tester,
Expand All @@ -110,7 +110,7 @@ void main() {
});

testGoldens('(light mode)', (tester) async {
await pumpPage(tester, theme: lightTheme);
await pumpPage(tester, theme: getLightTheme());

await multiScreenGolden(
tester,
Expand All @@ -119,7 +119,7 @@ void main() {
});

testGoldens('(dark mode)', (tester) async {
await pumpPage(tester, theme: darkTheme);
await pumpPage(tester, theme: getDarkTheme());

await multiScreenGolden(
tester,
Expand Down
4 changes: 2 additions & 2 deletions app/test_goldens/onboarding/mobile_welcome_page_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ void main() {
}

testGoldens('renders as expected (light theme)', (tester) async {
await pumpPage(tester, theme: lightTheme);
await pumpPage(tester, theme: getLightTheme());

await multiScreenGolden(tester, 'mobile_welcome_page_light');
});
Expand All @@ -32,7 +32,7 @@ void main() {
//
// Ticket: https://github.com/SharezoneApp/sharezone-app/issues/916
testGoldens('renders as expected (dark theme)', (tester) async {
await pumpPage(tester, theme: darkTheme);
await pumpPage(tester, theme: getDarkTheme());

await multiScreenGolden(tester, 'mobile_welcome_page_dark');
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ void main() {
testGoldens('displays as expected', (tester) async {
await tester.pumpWidget(
MaterialApp(
theme: lightTheme,
theme: getLightTheme(),
home: Scaffold(
body: ChangeNotifierProvider<PrivacyPolicyThemeSettings>(
create: (context) {
Expand Down
6 changes: 3 additions & 3 deletions app/test_goldens/settings/notification_page_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -66,13 +66,13 @@ void main() {
}

testGoldens('renders as expected (light mode)', (tester) async {
await pumpNotificationPage(tester, themeData: lightTheme);
await pumpNotificationPage(tester, themeData: getLightTheme());

await multiScreenGolden(tester, 'notification_page_light');
});

testGoldens('renders as expected (dark mode)', (tester) async {
await pumpNotificationPage(tester, themeData: darkTheme);
await pumpNotificationPage(tester, themeData: getDarkTheme());

await multiScreenGolden(tester, 'notification_page_dark');
});
Expand All @@ -82,7 +82,7 @@ void main() {
SharezonePlusFeature.changeHomeworkReminderTime))
.thenReturn(false);

await pumpNotificationPage(tester, themeData: lightTheme);
await pumpNotificationPage(tester, themeData: getLightTheme());

await tester
.tap(find.byKey(const Key('homework-notifications-time-tile')));
Expand Down
8 changes: 4 additions & 4 deletions app/test_goldens/settings/support/support_page_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -60,13 +60,13 @@ void main() {
});

testGoldens('renders as expected (light mode)', (tester) async {
await pumpSupportPage(tester, theme: lightTheme);
await pumpSupportPage(tester, theme: getLightTheme());

await multiScreenGolden(tester, 'support_page_with_plus_light');
});

testGoldens('renders as expected (dark mode)', (tester) async {
await pumpSupportPage(tester, theme: darkTheme);
await pumpSupportPage(tester, theme: getDarkTheme());

await multiScreenGolden(tester, 'support_page_with_plus_dark');
});
Expand All @@ -78,13 +78,13 @@ void main() {
});

testGoldens('renders as expected (light mode)', (tester) async {
await pumpSupportPage(tester, theme: lightTheme);
await pumpSupportPage(tester, theme: getLightTheme());

await multiScreenGolden(tester, 'support_page_without_plus_light');
});

testGoldens('renders as expected (dark mode)', (tester) async {
await pumpSupportPage(tester, theme: darkTheme);
await pumpSupportPage(tester, theme: getDarkTheme());

await multiScreenGolden(tester, 'support_page_without_plus_dark');
});
Expand Down
Loading

0 comments on commit e22d4b6

Please sign in to comment.