From b222eb08d6c4a0ab6eb42b25506e344437bb748c Mon Sep 17 00:00:00 2001 From: jld3103 Date: Sat, 26 Aug 2023 19:40:17 +0200 Subject: [PATCH] refactor(neon,app): Use existing mock shared preferences Signed-off-by: jld3103 --- .../app/integration_test/screenshot_test.dart | 81 +------------------ packages/neon/neon/lib/neon.dart | 11 ++- 2 files changed, 9 insertions(+), 83 deletions(-) diff --git a/packages/app/integration_test/screenshot_test.dart b/packages/app/integration_test/screenshot_test.dart index 14bec1f1..d60f115c 100644 --- a/packages/app/integration_test/screenshot_test.dart +++ b/packages/app/integration_test/screenshot_test.dart @@ -12,82 +12,6 @@ import 'package:neon/neon.dart'; import 'package:neon_files/widgets/actions.dart'; import 'package:shared_preferences/shared_preferences.dart'; -class MemorySharedPreferences implements SharedPreferences { - final _data = {}; - - @override - Future clear() async { - _data.clear(); - return true; - } - - @override - Future commit() async => true; - - @override - Future reload() async {} - - @override - Future remove(final String key) async { - _data.remove(key); - return true; - } - - @override - Set getKeys() => _data.keys.toSet(); - - @override - bool containsKey(final String key) => _data.keys.contains(key); - - @override - Object? get(final String key) => _data[key]; - - @override - bool? getBool(final String key) => _data[key] as bool?; - - @override - double? getDouble(final String key) => _data[key] as double?; - - @override - int? getInt(final String key) => _data[key] as int?; - - @override - String? getString(final String key) => _data[key] as String?; - - @override - List? getStringList(final String key) => (_data[key] as List).cast(); - - @override - Future setBool(final String key, final bool value) async { - _data[key] = value; - return true; - } - - @override - Future setDouble(final String key, final double value) async { - _data[key] = value; - return true; - } - - @override - Future setInt(final String key, final int value) async { - _data[key] = value; - return true; - } - - @override - Future setString(final String key, final String value) async { - _data[key] = value; - return true; - } - - @override - Future setStringList(final String key, final List value) async { - _data[key] = value; - return true; - } -} - Future runTestApp( final WidgetTester tester, final IntegrationTestWidgetsFlutterBinding binding, { @@ -97,7 +21,6 @@ Future runTestApp( getAppImplementations: getAppImplementations, theme: neonTheme, bindingOverride: binding, - sharedPreferencesOverride: MemorySharedPreferences(), account: account, firstLaunchDisabled: true, nextPushDisabled: true, @@ -137,6 +60,10 @@ Future main() async { await SystemChrome.setEnabledSystemUIMode(SystemUiMode.manual, overlays: []); }); + setUp(() { + SharedPreferences.setMockInitialValues({}); + }); + testWidgets('login', (final tester) async { await runTestApp( tester, diff --git a/packages/neon/neon/lib/neon.dart b/packages/neon/neon/lib/neon.dart index de2bc329..9d01e322 100644 --- a/packages/neon/neon/lib/neon.dart +++ b/packages/neon/neon/lib/neon.dart @@ -22,16 +22,15 @@ Future runNeon({ required final Iterable Function(SharedPreferences, RequestManager, NeonPlatform) getAppImplementations, required final NeonTheme theme, - final WidgetsBinding? bindingOverride, - final SharedPreferences? sharedPreferencesOverride, - final Account? account, - final bool firstLaunchDisabled = false, - final bool nextPushDisabled = false, + @visibleForTesting final WidgetsBinding? bindingOverride, + @visibleForTesting final Account? account, + @visibleForTesting final bool firstLaunchDisabled = false, + @visibleForTesting final bool nextPushDisabled = false, }) async { final binding = bindingOverride ?? WidgetsFlutterBinding.ensureInitialized(); FlutterNativeSplash.preserve(widgetsBinding: binding); - final sharedPreferences = sharedPreferencesOverride ?? await SharedPreferences.getInstance(); + final sharedPreferences = await SharedPreferences.getInstance(); final platform = await getNeonPlatform(); final cache = Cache(platform);