-
-
Notifications
You must be signed in to change notification settings - Fork 287
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: #217 - onboarding screenshot generation. #1529
Changes from all commits
8a9b4de
ea99b2f
f27c45b
7a46adb
8fcb62a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
import 'dart:io'; | ||
|
||
import 'package:flutter/foundation.dart'; | ||
import 'package:flutter_test/flutter_test.dart'; | ||
import 'package:integration_test/integration_test.dart'; | ||
import 'package:shared_preferences/shared_preferences.dart'; | ||
import 'package:smooth_app/main.dart' as app; | ||
|
||
Future<void> _initScreenshot( | ||
final IntegrationTestWidgetsFlutterBinding binding, | ||
) async { | ||
if ((!kIsWeb) && Platform.isAndroid) { | ||
await binding.convertFlutterSurfaceToImage(); | ||
} | ||
} | ||
|
||
Future<void> _takeScreenshot( | ||
final WidgetTester tester, | ||
final IntegrationTestWidgetsFlutterBinding binding, | ||
final String screenshotName, | ||
) async { | ||
if ((!kIsWeb) && Platform.isAndroid) { | ||
await tester.pumpAndSettle(); | ||
} | ||
await binding.takeScreenshot(screenshotName); | ||
} | ||
|
||
// flutter drive --driver=test_driver/screenshot_driver.dart --target=integration_test/app_test.dart | ||
|
||
/// Onboarding screenshots. | ||
void main() { | ||
final IntegrationTestWidgetsFlutterBinding binding = | ||
IntegrationTestWidgetsFlutterBinding.ensureInitialized() | ||
as IntegrationTestWidgetsFlutterBinding; | ||
|
||
setUpAll( | ||
() => SharedPreferences.setMockInitialValues( | ||
const <String, Object>{ | ||
'IMPORTANCE_AS_STRINGnutriscore': 'important', | ||
'IMPORTANCE_AS_STRINGnova': 'important', | ||
'IMPORTANCE_AS_STRINGecoscore': 'important', | ||
}, | ||
), | ||
); | ||
|
||
group('end-to-end test', () { | ||
testWidgets('just a single screenshot', (WidgetTester tester) async { | ||
await tester.runAsync(() async { | ||
await _initScreenshot(binding); | ||
|
||
await app.main(screenshots: true); | ||
await tester.pumpAndSettle(); | ||
|
||
sleep(const Duration(seconds: 30)); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm not sure of anything anymore. Especially when there's async load: ok the |
||
await _takeScreenshot( | ||
tester, binding, 'test-screenshot-onboarding-home'); | ||
sleep(const Duration(seconds: 10)); | ||
|
||
await tester.tap(find.byKey(const Key('next'))); | ||
await tester.pumpAndSettle(); | ||
|
||
await _takeScreenshot( | ||
tester, binding, 'test-screenshot-onboarding-scan'); | ||
sleep(const Duration(seconds: 10)); | ||
|
||
await tester.tap(find.byKey(const Key('next'))); | ||
await tester.pumpAndSettle(); | ||
|
||
await _takeScreenshot( | ||
tester, binding, 'test-screenshot-onboarding-health'); | ||
sleep(const Duration(seconds: 10)); | ||
|
||
await tester.tap(find.byKey(const Key('next'))); | ||
await tester.pumpAndSettle(); | ||
|
||
await _takeScreenshot( | ||
tester, binding, 'test-screenshot-onboarding-eco'); | ||
sleep(const Duration(seconds: 10)); | ||
|
||
await tester.tap(find.byKey(const Key('next'))); | ||
await tester.pumpAndSettle(); | ||
|
||
await _takeScreenshot( | ||
tester, binding, 'test-screenshot-onboarding-prefs'); | ||
sleep(const Duration(seconds: 10)); | ||
}); | ||
}); | ||
}); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -79,7 +79,15 @@ class AnalyticsHelper { | |
return event; | ||
} | ||
|
||
static void initMatomo(final BuildContext context) { | ||
static void initMatomo( | ||
final BuildContext context, | ||
final bool screenshotMode, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We don't need this parameter as it's a global value |
||
) { | ||
if (screenshotMode) { | ||
setCrashReports(false); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What about putting the same logic in initSentry There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's not that I particulary care about Matomo rather than Sentry; it's just that |
||
setAnalyticsReports(false); | ||
return; | ||
} | ||
MatomoForever.init( | ||
'https://analytics.openfoodfacts.org/matomo.php', | ||
2, | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -23,7 +23,15 @@ import 'package:smooth_app/themes/theme_provider.dart'; | |
|
||
List<CameraDescription> cameras = <CameraDescription>[]; | ||
|
||
Future<void> main() async { | ||
late bool _screenshots; | ||
|
||
Future<void> main({final bool screenshots = false}) async { | ||
_screenshots = screenshots; | ||
if (_screenshots) { | ||
await _init1(); | ||
runApp(const SmoothApp()); | ||
return; | ||
} | ||
final WidgetsBinding widgetsBinding = | ||
WidgetsFlutterBinding.ensureInitialized(); | ||
FlutterNativeSplash.preserve(widgetsBinding: widgetsBinding); | ||
|
@@ -48,17 +56,50 @@ class SmoothApp extends StatefulWidget { | |
State<SmoothApp> createState() => _SmoothAppState(); | ||
} | ||
|
||
late UserPreferences _userPreferences; | ||
late ProductPreferences _productPreferences; | ||
late LocalDatabase _localDatabase; | ||
late ThemeProvider _themeProvider; | ||
bool _init1done = false; | ||
|
||
// Had to split init in 2 methods, for test/screenshots reasons. | ||
// Don't know why, but some init codes seem to freeze the test. | ||
// Now we run them before running the app, during the tests. | ||
Future<bool> _init1() async { | ||
if (_init1done) { | ||
return false; | ||
} | ||
_userPreferences = await UserPreferences.getUserPreferences(); | ||
_localDatabase = await LocalDatabase.getLocalDatabase(); | ||
_productPreferences = ProductPreferences( | ||
ProductPreferencesSelection( | ||
setImportance: _userPreferences.setImportance, | ||
getImportance: _userPreferences.getImportance, | ||
notify: () => _productPreferences.notifyListeners(), | ||
), | ||
daoString: DaoString(_localDatabase), | ||
); | ||
|
||
AnalyticsHelper.setCrashReports(_userPreferences.crashReports); | ||
AnalyticsHelper.setAnalyticsReports(_userPreferences.analyticsReports); | ||
ProductQuery.setCountry(_userPreferences.userCountryCode); | ||
_themeProvider = ThemeProvider(_userPreferences); | ||
ProductQuery.setQueryType(_userPreferences); | ||
|
||
cameras = await availableCameras(); | ||
|
||
await ProductQuery.setUuid(_localDatabase); | ||
_init1done = true; | ||
return true; | ||
} | ||
|
||
class _SmoothAppState extends State<SmoothApp> { | ||
late UserPreferences _userPreferences; | ||
late ProductPreferences _productPreferences; | ||
late LocalDatabase _localDatabase; | ||
late ThemeProvider _themeProvider; | ||
final UserManagementProvider _userManagementProvider = | ||
UserManagementProvider(); | ||
|
||
bool systemDarkmodeOn = false; | ||
final Brightness brightness = | ||
SchedulerBinding.instance?.window.platformBrightness ?? Brightness.light; | ||
bool systemDarkmodeOn = false; | ||
|
||
// We store the argument of FutureBuilder to avoid re-initialization on | ||
// subsequent builds. This enables hot reloading. See | ||
|
@@ -68,35 +109,18 @@ class _SmoothAppState extends State<SmoothApp> { | |
@override | ||
void initState() { | ||
super.initState(); | ||
_initFuture = _init(); | ||
_initFuture = _init2(); | ||
} | ||
|
||
Future<void> _init() async { | ||
Future<bool> _init2() async { | ||
await _init1(); | ||
systemDarkmodeOn = brightness == Brightness.dark; | ||
_userPreferences = await UserPreferences.getUserPreferences(); | ||
_localDatabase = await LocalDatabase.getLocalDatabase(); | ||
_productPreferences = ProductPreferences( | ||
ProductPreferencesSelection( | ||
setImportance: _userPreferences.setImportance, | ||
getImportance: _userPreferences.getImportance, | ||
notify: () => _productPreferences.notifyListeners(), | ||
), | ||
daoString: DaoString(_localDatabase), | ||
); | ||
|
||
await _productPreferences.init(DefaultAssetBundle.of(context)); | ||
await _userPreferences.init(_productPreferences); | ||
|
||
AnalyticsHelper.setCrashReports(_userPreferences.crashReports); | ||
AnalyticsHelper.setAnalyticsReports(_userPreferences.analyticsReports); | ||
ProductQuery.setCountry(_userPreferences.userCountryCode); | ||
_themeProvider = ThemeProvider(_userPreferences); | ||
ProductQuery.setQueryType(_userPreferences); | ||
|
||
cameras = await availableCameras(); | ||
|
||
await ProductQuery.setUuid(_localDatabase); | ||
AnalyticsHelper.initMatomo(context); | ||
if (!_screenshots) { | ||
await _userPreferences.init(_productPreferences); | ||
} | ||
AnalyticsHelper.initMatomo(context, _screenshots); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You can just put it in the if statement above There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No I can't: I do things in There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We don't need _screenshots as argument as it's a global variable There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't think it is: it's private. |
||
return true; | ||
} | ||
|
||
@override | ||
|
@@ -118,7 +142,11 @@ class _SmoothAppState extends State<SmoothApp> { | |
ChangeNotifierProvider<T> provide<T extends ChangeNotifier>(T value) => | ||
ChangeNotifierProvider<T>(create: (BuildContext context) => value); | ||
|
||
FlutterNativeSplash.remove(); | ||
if (!_screenshots) { | ||
// ending FlutterNativeSplash.preserve() | ||
FlutterNativeSplash.remove(); | ||
} | ||
|
||
return MultiProvider( | ||
providers: <ChangeNotifierProvider<ChangeNotifier>>[ | ||
provide<UserPreferences>(_userPreferences), | ||
|
@@ -140,6 +168,7 @@ class _SmoothAppState extends State<SmoothApp> { | |
return MaterialApp( | ||
localizationsDelegates: AppLocalizations.localizationsDelegates, | ||
supportedLocales: AppLocalizations.supportedLocales, | ||
debugShowCheckedModeBanner: !(kReleaseMode || _screenshots), | ||
navigatorObservers: <NavigatorObserver>[ | ||
SentryNavigatorObserver(), | ||
], | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It can't be Web when it's android or am I missing something
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You're right, but I explicitly say that I handle the
kIsWeb
case - which wouldn't be obvious without that additional test. Or it would be a comment: I prefer code to comment.