-
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 #5734 from seadowg/bulk-finalization
Add bulk finalization
- Loading branch information
Showing
57 changed files
with
1,360 additions
and
297 deletions.
There are no files selected for viewing
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
106 changes: 106 additions & 0 deletions
106
...c/androidTest/java/org/odk/collect/android/feature/formmanagement/BulkFinalizationTest.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,106 @@ | ||
package org.odk.collect.android.feature.formmanagement | ||
|
||
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.support.pages.FormEntryPage.QuestionAndAnswer | ||
import org.odk.collect.android.support.pages.MainMenuPage | ||
import org.odk.collect.android.support.pages.SaveOrDiscardFormDialog | ||
import org.odk.collect.android.support.rules.CollectTestRule | ||
import org.odk.collect.android.support.rules.TestRuleChain | ||
import org.odk.collect.strings.R.plurals | ||
import org.odk.collect.strings.R.string | ||
|
||
@RunWith(AndroidJUnit4::class) | ||
class BulkFinalizationTest { | ||
|
||
val rule = CollectTestRule() | ||
|
||
@get:Rule | ||
val chain: RuleChain = TestRuleChain.chain().around(rule) | ||
|
||
@Test | ||
fun canBulkFinalizeDrafts() { | ||
rule.startAtMainMenu() | ||
.copyForm("one-question.xml") | ||
.startBlankForm("One Question") | ||
.fillOutAndSave(QuestionAndAnswer("what is your age", "97")) | ||
.startBlankForm("One Question") | ||
.fillOutAndSave(QuestionAndAnswer("what is your age", "98")) | ||
|
||
.clickEditSavedForm(2) | ||
.clickOptionsIcon(string.finalize_all_forms) | ||
.clickOnString(string.finalize_all_forms) | ||
.checkIsSnackbarWithQuantityDisplayed(plurals.bulk_finalize_success, 2) | ||
.assertTextDoesNotExist("One Question") | ||
.pressBack(MainMenuPage()) | ||
|
||
.assertNumberOfFinalizedForms(2) | ||
} | ||
|
||
@Test | ||
fun whenThereAreDraftsWithConstraintViolations_marksFormsAsHavingErrors() { | ||
rule.startAtMainMenu() | ||
.copyForm("two-question-required.xml") | ||
.startBlankForm("Two Question Required") | ||
.fillOut(QuestionAndAnswer("What is your name?", "Dan")) | ||
.pressBack(SaveOrDiscardFormDialog(MainMenuPage())) | ||
.clickSaveChanges() | ||
|
||
.startBlankForm("Two Question Required") | ||
.fillOutAndSave( | ||
QuestionAndAnswer("What is your name?", "Tim"), | ||
QuestionAndAnswer("What is your age?", "45", true) | ||
) | ||
|
||
.clickEditSavedForm(2) | ||
.clickOptionsIcon(string.finalize_all_forms) | ||
.clickOnString(string.finalize_all_forms) | ||
.checkIsSnackbarWithMessageDisplayed(string.bulk_finalize_partial_success, 1, 1) | ||
.assertText("Two Question Required") | ||
.pressBack(MainMenuPage()) | ||
|
||
.assertNumberOfEditableForms(1) | ||
.assertNumberOfFinalizedForms(1) | ||
} | ||
|
||
@Test | ||
fun whenADraftPreviouslyHadConstraintViolations_marksFormsAsHavingErrors() { | ||
rule.startAtMainMenu() | ||
.copyForm("two-question-required.xml") | ||
.startBlankForm("Two Question Required") | ||
.fillOut(QuestionAndAnswer("What is your name?", "Dan")) | ||
.pressBack(SaveOrDiscardFormDialog(MainMenuPage())) | ||
.clickSaveChanges() | ||
|
||
.clickEditSavedForm(1) | ||
.clickOptionsIcon(string.finalize_all_forms) | ||
.clickOnString(string.finalize_all_forms) | ||
.checkIsSnackbarWithQuantityDisplayed(plurals.bulk_finalize_failure, 1) | ||
|
||
.clickOptionsIcon(string.finalize_all_forms) | ||
.clickOnString(string.finalize_all_forms) | ||
.checkIsSnackbarWithQuantityDisplayed(plurals.bulk_finalize_failure, 1) | ||
} | ||
|
||
@Test | ||
fun doesNotFinalizeOtherTypesOfInstance() { | ||
rule.startAtMainMenu() | ||
.copyForm("one-question.xml") | ||
.startBlankForm("One Question") | ||
.fillOutAndSave(QuestionAndAnswer("what is your age", "97")) | ||
.startBlankForm("One Question") | ||
.fillOutAndFinalize(QuestionAndAnswer("what is your age", "98")) | ||
|
||
.clickEditSavedForm(1) | ||
.clickOptionsIcon(string.finalize_all_forms) | ||
.clickOnString(string.finalize_all_forms) | ||
.checkIsSnackbarWithQuantityDisplayed(plurals.bulk_finalize_success, 1) | ||
.assertTextDoesNotExist("One Question") | ||
.pressBack(MainMenuPage()) | ||
|
||
.assertNumberOfFinalizedForms(2) | ||
} | ||
} |
56 changes: 56 additions & 0 deletions
56
...droidTest/java/org/odk/collect/android/feature/instancemanagement/PartialSubmissionTet.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,56 @@ | ||
package org.odk.collect.android.feature.instancemanagement | ||
|
||
import androidx.test.ext.junit.runners.AndroidJUnit4 | ||
import org.hamcrest.MatcherAssert.assertThat | ||
import org.hamcrest.Matchers.equalTo | ||
import org.junit.Rule | ||
import org.junit.Test | ||
import org.junit.rules.RuleChain | ||
import org.junit.runner.RunWith | ||
import org.kxml2.io.KXmlParser | ||
import org.kxml2.kdom.Document | ||
import org.odk.collect.android.support.TestDependencies | ||
import org.odk.collect.android.support.pages.FormEntryPage | ||
import org.odk.collect.android.support.rules.CollectTestRule | ||
import org.odk.collect.android.support.rules.TestRuleChain | ||
import java.io.File | ||
import java.io.StringReader | ||
|
||
@RunWith(AndroidJUnit4::class) | ||
class PartialSubmissionTet { | ||
|
||
private val testDependencies = TestDependencies() | ||
private val rule = CollectTestRule(useDemoProject = false) | ||
|
||
@get:Rule | ||
val chain: RuleChain = TestRuleChain.chain(testDependencies) | ||
.around(rule) | ||
|
||
@Test | ||
fun canFillAndSubmitAFormWithPartialSubmission() { | ||
rule.withProject(testDependencies.server.url) | ||
.copyForm("one-question-partial.xml", testDependencies.server.hostName) | ||
.startBlankForm("One Question") | ||
.fillOutAndFinalize(FormEntryPage.QuestionAndAnswer("what is your age", "123")) | ||
|
||
.clickSendFinalizedForm(1) | ||
.clickSelectAll() | ||
.clickSendSelected() | ||
|
||
val submissions = testDependencies.server.submissions | ||
assertThat(submissions.size, equalTo(1)) | ||
|
||
val root = parseXml(submissions[0]).rootElement | ||
assertThat(root.name, equalTo("age")) | ||
assertThat(root.childCount, equalTo(1)) | ||
assertThat(root.getChild(0), equalTo("123")) | ||
} | ||
|
||
private fun parseXml(file: File): Document { | ||
return StringReader(String(file.readBytes())).use { reader -> | ||
val parser = KXmlParser() | ||
parser.setInput(reader) | ||
Document().also { it.parse(parser) } | ||
} | ||
} | ||
} |
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
Oops, something went wrong.