-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #5647 from grzesiek2010/COLLECT-5148
Disable 'Save as draft' when 'Moving backwards' is disabled
- Loading branch information
Showing
8 changed files
with
262 additions
and
5 deletions.
There are no files selected for viewing
76 changes: 76 additions & 0 deletions
76
..._app/src/androidTest/java/org/odk/collect/android/feature/settings/MovingBackwardsTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
package org.odk.collect.android.feature.settings | ||
|
||
import androidx.test.ext.junit.runners.AndroidJUnit4 | ||
import org.junit.Rule | ||
import org.junit.Test | ||
import org.junit.rules.RuleChain | ||
import org.junit.runner.RunWith | ||
import org.odk.collect.android.R | ||
import org.odk.collect.android.support.rules.CollectTestRule | ||
import org.odk.collect.android.support.rules.TestRuleChain | ||
|
||
@RunWith(AndroidJUnit4::class) | ||
class MovingBackwardsTest { | ||
private val rule = CollectTestRule() | ||
|
||
@get:Rule | ||
var ruleChain: RuleChain = TestRuleChain.chain().around(rule) | ||
|
||
@Test | ||
fun whenMovingBackwardDisabledWithPreventingUsersFormBypassingIt_relatedOptionsShouldBeUpdated() { | ||
rule.startAtMainMenu() | ||
.openProjectSettingsDialog() | ||
.clickSettings() | ||
.clickAccessControl() | ||
.clickFormEntrySettings() | ||
.clickOnString(R.string.finalize) | ||
|
||
// before disabling moving backward | ||
.assertGoToPromptEnabled() | ||
.assertGoToPromptChecked() | ||
|
||
.assertSaveAsDraftInFormEntryEnabled() | ||
.assertSaveAsDraftInFormEntryChecked() | ||
|
||
.assertSaveAsDraftInFormEndDisabled() | ||
.assertSaveAsDraftInFormEndChecked() | ||
|
||
.assertFinalizeEnabled() | ||
.assertFinalizeUnchecked() | ||
|
||
.clickMovingBackwards() | ||
.clickOnString(R.string.yes) | ||
|
||
// after disabling moving backward - the state of the 4 related options is reversed | ||
.assertGoToPromptDisabled() | ||
.assertGoToPromptUnchecked() | ||
|
||
.assertSaveAsDraftInFormEntryDisabled() | ||
.assertSaveAsDraftInFormEntryUnchecked() | ||
|
||
.assertSaveAsDraftInFormEndDisabled() | ||
.assertSaveAsDraftInFormEndUnchecked() | ||
|
||
.assertFinalizeDisabled() | ||
.assertFinalizeChecked() | ||
} | ||
|
||
@Test | ||
fun whenMovingBackwardDisabledWithoutPreventingUsersFormBypassingIt_relatedOptionsShouldNotBeUpdated() { | ||
rule.startAtMainMenu() | ||
.openProjectSettingsDialog() | ||
.clickSettings() | ||
.clickAccessControl() | ||
.clickFormEntrySettings() | ||
.clickMovingBackwards() | ||
.clickOnString(R.string.no) | ||
.assertGoToPromptEnabled() | ||
.assertSaveAsDraftInFormEntryEnabled() | ||
.assertSaveAsDraftInFormEndEnabled() | ||
.assertFinalizeEnabled() | ||
.assertGoToPromptChecked() | ||
.assertSaveAsDraftInFormEntryChecked() | ||
.assertSaveAsDraftInFormEndChecked() | ||
.assertFinalizeChecked() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
48 changes: 48 additions & 0 deletions
48
settings/src/main/java/org/odk/collect/settings/migration/KeyUpdater.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
package org.odk.collect.settings.migration; | ||
|
||
import static org.odk.collect.settings.migration.MigrationUtils.asPairs; | ||
|
||
import org.odk.collect.shared.settings.Settings; | ||
|
||
import java.util.ArrayList; | ||
import java.util.Arrays; | ||
import java.util.List; | ||
import java.util.Map; | ||
|
||
public class KeyUpdater implements Migration { | ||
|
||
String[] oldKeys; | ||
Object[] tempOldValueArray; | ||
List<Object[]> oldValueArrays = new ArrayList<>(); | ||
List<KeyValuePair[]> newKeyValuePairArrays = new ArrayList<>(); | ||
|
||
KeyUpdater(String... oldKeys) { | ||
this.oldKeys = oldKeys; | ||
} | ||
|
||
public KeyUpdater withValues(Object... oldValues) { | ||
tempOldValueArray = oldValues; | ||
return this; | ||
} | ||
|
||
public KeyUpdater toPairs(Object... keysAndValues) { | ||
oldValueArrays.add(tempOldValueArray); | ||
newKeyValuePairArrays.add(asPairs(keysAndValues)); | ||
return this; | ||
} | ||
|
||
public void apply(Settings prefs) { | ||
Map<String, ?> prefMap = prefs.getAll(); | ||
Object[] oldValues = new Object[oldKeys.length]; | ||
for (int i = 0; i < oldKeys.length; i++) { | ||
oldValues[i] = prefMap.get(oldKeys[i]); | ||
} | ||
for (int i = 0; i < oldValueArrays.size(); i++) { | ||
if (Arrays.equals(oldValues, oldValueArrays.get(i))) { | ||
for (KeyValuePair keyValuePair : newKeyValuePairArrays.get(i)) { | ||
prefs.save(keyValuePair.key, keyValuePair.value); | ||
} | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters