Skip to content

Commit

Permalink
Merge pull request getodk#5760 from seadowg/validation-feedback
Browse files Browse the repository at this point in the history
Validate drafts when saved from end screen
  • Loading branch information
seadowg committed Oct 24, 2023
1 parent 5aa4b87 commit 5ada606
Show file tree
Hide file tree
Showing 28 changed files with 162 additions and 91 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ public void instanceOfEncryptedFormWithoutInstanceID_failsFinalizationWithMessag
.swipeToEndScreen()
.clickFinalize()
.checkIsToastWithMessageDisplayed("This form does not specify an instanceID. You must specify one to enable encryption. Form has not been saved as finalized.")
.clickEditSavedForm()
.clickDrafts()
.checkInstanceState("encrypted-no-instanceID", Instance.STATUS_INCOMPLETE);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,16 @@ 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.pages.AccessControlPage
import org.odk.collect.android.support.pages.FormEntryPage
import org.odk.collect.android.support.pages.MainMenuPage
import org.odk.collect.android.support.pages.ProjectSettingsPage
import org.odk.collect.android.support.pages.SaveOrDiscardFormDialog
import org.odk.collect.android.support.rules.CollectTestRule
import org.odk.collect.android.support.rules.TestRuleChain.chain
import org.odk.collect.strings.R.string

@RunWith(AndroidJUnit4::class)
class FormFinalizingTest {
class FormEndTest {
private val rule = CollectTestRule()

@get:Rule
Expand All @@ -33,28 +32,34 @@ class FormFinalizingTest {
}

@Test
fun fillingForm_andPressingSaveAsDraft_doesNotFinalizesForm() {
fun fillingForm_andPressingSaveAsDraft_savesACompleteDraft() {
rule.startAtMainMenu()
.copyForm(FORM)
.assertNumberOfFinalizedForms(0)
.startBlankForm("One Question")
.swipeToEndScreen()
.clickSaveAsDraft()
.assertNumberOfEditableForms(1)
.assertNumberOfFinalizedForms(0)

.clickDrafts(1)
.assertText(string.complete)
.assertTextDoesNotExist(string.incomplete)
}

@Test
fun fillingForm_andPressingBack_andPressingSave_doesNotFinalizesForm() {
fun fillingForm_andPressingSaveAsDraft_whenThereAreViolatedConstraints_savesAIncompleteDraft() {
rule.startAtMainMenu()
.copyForm(FORM)
.copyForm("two-question-required.xml")
.assertNumberOfFinalizedForms(0)
.startBlankForm("One Question")
.closeSoftKeyboard()
.pressBack(SaveOrDiscardFormDialog(MainMenuPage()))
.clickSaveChanges()
.assertNumberOfEditableForms(1)
.startBlankForm("Two Question Required")
.clickGoToArrow()
.clickGoToEnd()
.clickSaveAsDraft()
.assertNumberOfFinalizedForms(0)

.clickDrafts(1)
.assertText(string.incomplete)
.assertTextDoesNotExist(string.complete)
}

@Test
Expand All @@ -71,7 +76,7 @@ class FormFinalizingTest {
.copyForm(FORM)
.startBlankForm("One Question")
.swipeToEndScreen()
.assertTextDoesNotExist(org.odk.collect.strings.R.string.save_as_draft)
.assertTextDoesNotExist(string.save_as_draft)
}

@Test
Expand All @@ -81,14 +86,14 @@ class FormFinalizingTest {
.clickSettings()
.clickAccessControl()
.clickFormEntrySettings()
.clickOnString(org.odk.collect.strings.R.string.finalize)
.clickOnString(string.finalize)
.pressBack(AccessControlPage())
.pressBack(ProjectSettingsPage())
.pressBack(MainMenuPage())
.copyForm(FORM)
.startBlankForm("One Question")
.swipeToEndScreen()
.assertTextDoesNotExist(org.odk.collect.strings.R.string.finalize)
.assertTextDoesNotExist(string.finalize)
}

companion object {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ class FormSavedSnackbarTest {
.answerQuestion(0, "25")
.swipeToEndScreen()
.clickSaveAsDraft()
.clickEditSavedForm()
.clickDrafts()
.clickOnForm("One Question")
.clickGoToEnd()
.clickFinalize()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public void whenFillingForm_clickingSaveIcon_savesCurrentAnswers() {
.clickSave()
.pressBackAndDiscardChanges()

.clickEditSavedForm(1)
.clickDrafts(1)
.clickOnForm("Two Question")
.assertText("Reuben")
.assertText("32");
Expand All @@ -47,7 +47,7 @@ public void whenFillingForm_withViolatedConstraintsOnCurrentScreen_clickingSaveI
.clickSave()
.pressBackAndDiscardChanges()

.clickEditSavedForm(1)
.clickDrafts(1)
.clickOnForm("Two Question Required")
.assertText("Reuben");
}
Expand All @@ -61,15 +61,15 @@ public void whenEditingANonFinalizedForm_withViolatedConstraintsOnCurrentScreen_
.clickSave()
.pressBackAndDiscardChanges()

.clickEditSavedForm(1)
.clickDrafts(1)
.clickOnForm("Two Question Required")
.clickGoToStart()
.answerQuestion("What is your name?", "Another Reuben")
.swipeToNextQuestion("What is your age?", true)
.clickSave()
.pressBackAndDiscardChanges()

.clickEditSavedForm(1)
.clickDrafts(1)
.clickOnForm("Two Question Required")
.assertText("Another Reuben");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ public void whenFillingForm_pressingBack_andClickingSaveChanges_savesCurrentAnsw
.pressBack(new SaveOrDiscardFormDialog<>(new MainMenuPage()))
.clickSaveChanges()

.clickEditSavedForm(1)
.assertNumberOfFinalizedForms(0)
.clickDrafts(1)
.clickOnForm("Two Question")
.assertText("Reuben")
.assertText("10");
Expand Down Expand Up @@ -63,7 +64,7 @@ public void whenFillingForm_saving_andPressingBack_andClickingIgnoreChanges_save
.answerQuestion("What is your age?", "10")
.pressBackAndDiscardChanges()

.clickEditSavedForm(1)
.clickDrafts(1)
.clickOnForm("Two Question")
.assertText("Reuben")
.assertTextDoesNotExist("10");
Expand All @@ -80,7 +81,7 @@ public void whenFillingForm_withViolatedConstraintsOnCurrentScreen_pressingBack_
.pressBack(new SaveOrDiscardFormDialog<>(new MainMenuPage()))
.clickSaveChanges()

.clickEditSavedForm(1)
.clickDrafts(1)
.clickOnForm("Two Question Required")
.assertText("Reuben");
}
Expand All @@ -94,7 +95,7 @@ public void whenEditingANonFinalizedForm_withViolatedConstraintsOnCurrentScreen_
.pressBack(new SaveOrDiscardFormDialog<>(new MainMenuPage()))
.clickSaveChanges()

.clickEditSavedForm(1)
.clickDrafts(1)
.clickOnForm("Two Question Required")
.clickGoToStart()
.answerQuestion("What is your name?", "Another Reuben")
Expand All @@ -103,7 +104,7 @@ public void whenEditingANonFinalizedForm_withViolatedConstraintsOnCurrentScreen_
.pressBack(new SaveOrDiscardFormDialog<>(new MainMenuPage()))
.clickSaveChanges()

.clickEditSavedForm(1)
.clickDrafts(1)
.clickOnForm("Two Question Required")
.assertText("Another Reuben");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class SaveIncompleteTest {
.swipeToNextQuestion("[saveIncomplete] What is your age?")
.pressBackAndDiscardChanges()

.clickEditSavedForm(1)
.clickDrafts(1)
.clickOnForm("Two Question Save Incomplete")
.assertText("Dez")
}
Expand All @@ -40,7 +40,7 @@ class SaveIncompleteTest {
.swipeToNextQuestion("[saveIncomplete] What is your age?", true)
.pressBackAndDiscardChanges()

.clickEditSavedForm(1)
.clickDrafts(1)
.clickOnForm("Two Question Save Incomplete Required")
.assertText("Dez")
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ class AuditTest {
)
.swipeToEndScreen()
.clickSaveAsDraft()
.clickEditSavedForm(1)
.clickDrafts(1)
.clickOnForm("One Question Audit")
.clickGoToStart()
.fillOutAndFinalize(
Expand Down Expand Up @@ -122,7 +122,7 @@ class AuditTest {
.copyForm("location-audit.xml")
.startBlankForm("Audit with Location")
.pressBackAndSaveAsDraft()
.clickEditSavedForm()
.clickDrafts()
.clickOnForm("Audit with Location")
.clickGoToStart()
.pressBackAndSaveAsDraft()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public void openingSavedForm_andThenEnteringIdentity_andThenFillingForm_logsUser
.swipeToEndScreen()
.clickSaveAsDraft()

.clickEditSavedForm()
.clickDrafts()
.clickOnFormWithIdentityPrompt("Identify User")
.enterIdentity("Jack")
.clickKeyboardEnter(new FormHierarchyPage("Identify User"))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ class TrackChangesReasonTest {
.swipeToEndScreen()
.clickSaveAsDraft()

.clickEditSavedForm()
.clickDrafts()
.clickOnForm("Track Changes Reason")
.clickGoToEnd()
.clickSaveAndExitWithChangesReasonPrompt()
Expand All @@ -56,7 +56,7 @@ class TrackChangesReasonTest {
.inputText("Nothing much...")
.swipeToEndScreen()
.clickSaveAsDraft()
.clickEditSavedForm()
.clickDrafts()

.clickOnForm("Track Changes Reason")
.clickGoToEnd()
Expand All @@ -74,7 +74,7 @@ class TrackChangesReasonTest {
.swipeToEndScreen()
.clickSaveAsDraft()

.clickEditSavedForm()
.clickDrafts()
.clickOnForm("Track Changes Reason")
.clickGoToEnd()
.clickSaveAndExitWithChangesReasonPrompt()
Expand All @@ -91,7 +91,7 @@ class TrackChangesReasonTest {
.swipeToEndScreen()
.clickSaveAsDraft()

.clickEditSavedForm()
.clickDrafts()
.clickOnForm("Track Changes Reason")
.clickGoToEnd()
.clickSaveAndExitWithChangesReasonPrompt()
Expand All @@ -111,7 +111,7 @@ class TrackChangesReasonTest {
.swipeToEndScreen()
.clickSaveAsDraft()

.clickEditSavedForm()
.clickDrafts()
.clickOnForm("Track Changes Reason")
.clickGoToStart()
.closeSoftKeyboard()
Expand All @@ -132,7 +132,7 @@ class TrackChangesReasonTest {
.swipeToEndScreen()
.clickSaveAsDraft()

.clickEditSavedForm()
.clickDrafts()
.clickOnForm("Track Changes Reason")
.clickGoToStart()
.closeSoftKeyboard()
Expand All @@ -149,7 +149,7 @@ class TrackChangesReasonTest {
.swipeToEndScreen()
.clickSaveAsDraft()

.clickEditSavedForm()
.clickDrafts()
.clickOnForm("Track Changes Reason")
.clickGoToStart()
.clickSaveWithChangesReasonPrompt()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class BulkFinalizationTest {
.startBlankForm("One Question")
.fillOutAndSave(QuestionAndAnswer("what is your age", "98"))

.clickEditSavedForm(2)
.clickDrafts(2)
.clickOptionsIcon(string.finalize_all_drafts)
.clickOnString(string.finalize_all_drafts)
.checkIsSnackbarWithQuantityDisplayed(plurals.bulk_finalize_success, 2)
Expand All @@ -55,7 +55,7 @@ class BulkFinalizationTest {
QuestionAndAnswer("What is your age?", "45", true)
)

.clickEditSavedForm(2)
.clickDrafts(2)
.clickOptionsIcon(string.finalize_all_drafts)
.clickOnString(string.finalize_all_drafts)
.checkIsSnackbarWithMessageDisplayed(string.bulk_finalize_partial_success, 1, 1)
Expand All @@ -75,7 +75,7 @@ class BulkFinalizationTest {
.pressBack(SaveOrDiscardFormDialog(MainMenuPage()))
.clickSaveChanges()

.clickEditSavedForm(1)
.clickDrafts(1)
.clickOptionsIcon(string.finalize_all_drafts)
.clickOnString(string.finalize_all_drafts)
.checkIsSnackbarWithQuantityDisplayed(plurals.bulk_finalize_failure, 1)
Expand All @@ -94,7 +94,7 @@ class BulkFinalizationTest {
.startBlankForm("One Question")
.fillOutAndFinalize(QuestionAndAnswer("what is your age", "98"))

.clickEditSavedForm(1)
.clickDrafts(1)
.clickOptionsIcon(string.finalize_all_drafts)
.clickOnString(string.finalize_all_drafts)
.checkIsSnackbarWithQuantityDisplayed(plurals.bulk_finalize_success, 1)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public void deletingAForm_whenThereFilledForms_removesFormFromBlankFormList_butA
.assertNoForms()
.pressBack(new MainMenuPage())

.clickEditSavedForm()
.clickDrafts()
.clickOnForm("One Question")
.clickOnQuestion("what is your age")
.answerQuestion("what is your age", "30")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public void whenSubmissionSucceeds_instanceNotEditable() {
.pressBack(new MainMenuPage())

.assertNumberOfEditableForms(0)
.clickEditSavedForm()
.clickDrafts()
.assertTextDoesNotExist("One Question")

// Tests that search doesn't change visibility. Move down to lower testing level.
Expand Down Expand Up @@ -68,7 +68,7 @@ public void whenSubmissionFails_instanceNotEditable() {
.pressBack(new MainMenuPage())

.assertNumberOfEditableForms(0)
.clickEditSavedForm()
.clickDrafts()
.assertTextDoesNotExist("One Question")

// Tests that search doesn't change visibility. Move down to lower testing level
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ 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.storage.StorageSubdirectory
import org.odk.collect.android.support.TestDependencies
import org.odk.collect.android.support.pages.MainMenuPage
Expand Down Expand Up @@ -48,7 +47,7 @@ class InstancesAdbTest {
Assert.assertTrue(instanceDeleted)

mainMenuPage
.clickEditSavedForm(1)
.clickDrafts(1)
.clickOnFormWithDialog("One Question")
.assertText(org.odk.collect.strings.R.string.instance_deleted_message)
.clickOK(MainMenuPage())
Expand Down
Loading

0 comments on commit 5ada606

Please sign in to comment.