From 1ce3ef4ea3c55d4a6c4a79f8a6cca58387b240df Mon Sep 17 00:00:00 2001 From: Harsh Shandilya Date: Thu, 27 Aug 2020 14:27:55 +0530 Subject: Expand show hidden folders to also cover files (#1059) * PasswordItem: only strip .gpg suffixes Signed-off-by: Harsh Shandilya * Add preference key and migration for showing all hidden contents Signed-off-by: Harsh Shandilya * Allow showing both hidden files and directories Signed-off-by: Harsh Shandilya * Add tests for hidden folder setting migration Signed-off-by: Harsh Shandilya * Add changelog entry Signed-off-by: Harsh Shandilya * Slightly improve migration logic Skip migration if old key is not found and always delete the previous key even if its set to false. Signed-off-by: Harsh Shandilya * Tweak wording Suggested-by: Fabian Henneke Signed-off-by: Harsh Shandilya * Assert previous key's removal in tests Signed-off-by: Harsh Shandilya --- .../java/com/zeapo/pwdstore/MigrationsTest.kt | 26 ++++++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) (limited to 'app/src/androidTest') diff --git a/app/src/androidTest/java/com/zeapo/pwdstore/MigrationsTest.kt b/app/src/androidTest/java/com/zeapo/pwdstore/MigrationsTest.kt index c66bb215..5ba1b307 100644 --- a/app/src/androidTest/java/com/zeapo/pwdstore/MigrationsTest.kt +++ b/app/src/androidTest/java/com/zeapo/pwdstore/MigrationsTest.kt @@ -4,6 +4,7 @@ */ @file:Suppress("DEPRECATION") + package com.zeapo.pwdstore import android.content.Context @@ -13,10 +14,10 @@ import com.zeapo.pwdstore.git.config.Protocol import com.zeapo.pwdstore.utils.PreferenceKeys import com.zeapo.pwdstore.utils.getString import com.zeapo.pwdstore.utils.sharedPrefs +import org.junit.Assert.assertEquals +import org.junit.Assert.assertNull import org.junit.Test -import org.junit.Assert.* - class MigrationsTest { private fun checkOldKeysAreRemoved(context: Context) = with(context.sharedPrefs) { @@ -84,4 +85,25 @@ class MigrationsTest { "https://github.com/Android-Password-Store/pass-test" ) } + + @Test + fun verifyHiddenFoldersMigrationIfDisabled() { + val context = Application.instance.applicationContext + context.sharedPrefs.edit { clear() } + runMigrations(context) + assertEquals(true, context.sharedPrefs.getBoolean(PreferenceKeys.SHOW_HIDDEN_FOLDERS, true)) + assertEquals(false, context.sharedPrefs.getBoolean(PreferenceKeys.SHOW_HIDDEN_CONTENTS, false)) + } + + @Test + fun verifyHiddenFoldersMigrationIfEnabled() { + val context = Application.instance.applicationContext + context.sharedPrefs.edit { + clear() + putBoolean(PreferenceKeys.SHOW_HIDDEN_FOLDERS, true) + } + runMigrations(context) + assertEquals(false, context.sharedPrefs.getBoolean(PreferenceKeys.SHOW_HIDDEN_FOLDERS, false)) + assertEquals(true, context.sharedPrefs.getBoolean(PreferenceKeys.SHOW_HIDDEN_CONTENTS, false)) + } } -- cgit v1.2.3