Test case for CompatV32

This commit is contained in:
Ming Ming 2021-10-20 17:31:47 +08:00
parent 52e26057d3
commit 3bc22f285d

View file

@ -0,0 +1,39 @@
import 'package:nc_photos/use_case/compat/v32.dart';
import 'package:shared_preferences/shared_preferences.dart';
import 'package:test/test.dart';
void main() {
group("CompatV32", () {
group("isPrefNeedMigration", () {
test("w/ accounts", () async {
SharedPreferences.setMockInitialValues({
"accounts": [
"""{"scheme":"http","address":"example.com","username":"admin","password":"123456","roots":["dir","dir2"]}""",
],
});
expect(await CompatV32.isPrefNeedMigration(), true);
});
test("w/o accounts", () async {
SharedPreferences.setMockInitialValues({
"hello": "world",
});
expect(await CompatV32.isPrefNeedMigration(), false);
});
});
test("migratePref", () async {
SharedPreferences.setMockInitialValues({
"accounts": [
"""{"scheme":"http","address":"example.com","username":"admin","password":"123456","roots":["dir","dir2"]}""",
],
});
await CompatV32.migratePref();
final pref = await SharedPreferences.getInstance();
expect(pref.getStringList("accounts2"), [
"""{"account":{"scheme":"http","address":"example.com","username":"admin","password":"123456","roots":["dir","dir2"]},"settings":{"isEnableFaceRecognitionApp":true}}""",
]);
expect(pref.containsKey("accounts"), false);
});
});
}