Browse Source

refactor(neon,app): Use existing mock shared preferences

Signed-off-by: jld3103 <jld3103yt@gmail.com>
pull/538/head
jld3103 1 year ago
parent
commit
b222eb08d6
No known key found for this signature in database
GPG Key ID: 9062417B9E8EB7B3
  1. 81
      packages/app/integration_test/screenshot_test.dart
  2. 11
      packages/neon/neon/lib/neon.dart

81
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 = <String, dynamic>{};
@override
Future<bool> clear() async {
_data.clear();
return true;
}
@override
Future<bool> commit() async => true;
@override
Future reload() async {}
@override
Future<bool> remove(final String key) async {
_data.remove(key);
return true;
}
@override
Set<String> 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<String>? getStringList(final String key) => (_data[key] as List).cast<String>();
@override
Future<bool> setBool(final String key, final bool value) async {
_data[key] = value;
return true;
}
@override
Future<bool> setDouble(final String key, final double value) async {
_data[key] = value;
return true;
}
@override
Future<bool> setInt(final String key, final int value) async {
_data[key] = value;
return true;
}
@override
Future<bool> setString(final String key, final String value) async {
_data[key] = value;
return true;
}
@override
Future<bool> setStringList(final String key, final List<String> 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,

11
packages/neon/neon/lib/neon.dart

@ -22,16 +22,15 @@ Future runNeon({
required final Iterable<AppImplementation> 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);

Loading…
Cancel
Save