-
Notifications
You must be signed in to change notification settings - Fork 1.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Disable 'Save as draft' when 'Moving backwards' is disabled #5647
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What's the thinking around adding this instead of adding tests to
FormEntryAccessPreferencesFragmentTest
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can't test disabling moving backwards in isolation (using fragment-scenario like in
FormEntryAccessPreferencesFragmentTest
) because that fragment displaysMovingBackwardsDialog
which calls a listener fromProjectPreferencesActivity
and then it calls a method fromFormEntryAccessPreferencesFragment
, so there is that activity involved.