Skip to content

Commit

Permalink
Merge pull request #6108 from seadowg/entity-lists
Browse files Browse the repository at this point in the history
Store shared entities for follow up forms
  • Loading branch information
grzesiek2010 authored May 8, 2024
2 parents df5c2b0 + a9f9e50 commit 916629c
Show file tree
Hide file tree
Showing 53 changed files with 1,139 additions and 709 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import android.os.Bundle
import androidx.fragment.app.DialogFragment
import androidx.fragment.app.FragmentManager
import timber.log.Timber
import kotlin.reflect.KClass

object DialogFragmentUtils {

Expand Down Expand Up @@ -86,4 +87,8 @@ object DialogFragmentUtils {
}
}
}

fun <T : DialogFragment> FragmentManager.showIfNotShowing(dialogClass: KClass<T>) {
showIfNotShowing(dialogClass.java, this)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
package org.odk.collect.android.feature.entitymanagement

import org.junit.Rule
import org.junit.Test
import org.junit.rules.RuleChain
import org.odk.collect.android.support.StubOpenRosaServer
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

class ViewEntitiesTest {

private val rule = CollectTestRule(useDemoProject = false)
private val testDependencies = TestDependencies()

@get:Rule
val ruleChain: RuleChain = TestRuleChain.chain(testDependencies)
.around(rule)

@Test
fun canViewLocallyCreatedEntitiesInBrowser() {
testDependencies.server.addForm("one-question-entity-registration.xml")

rule.withMatchExactlyProject(testDependencies.server.url)
.addEntityListInBrowser("people")
.startBlankForm("One Question Entity Registration")
.fillOutAndFinalize(FormEntryPage.QuestionAndAnswer("Name", "Logan Roy"))
.openEntityBrowser()
.clickOnDataset("people")
.assertEntity("Logan Roy", "full_name: Logan Roy")
}

@Test
fun canViewListEntitiesInBrowser() {
testDependencies.server.addForm(
"one-question-entity-follow-up.xml",
listOf(StubOpenRosaServer.EntityListItem("people.csv"))
)

rule.withMatchExactlyProject(testDependencies.server.url)
.addEntityListInBrowser("people")
.refreshForms()
.openEntityBrowser()
.clickOnDataset("people")
.assertEntity("Roman Roy", "full_name: Roman Roy")
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,10 @@ import org.junit.Rule
import org.junit.Test
import org.junit.rules.RuleChain
import org.junit.runner.RunWith
import org.odk.collect.android.support.StubOpenRosaServer.EntityListItem
import org.odk.collect.android.support.TestDependencies
import org.odk.collect.android.support.pages.FormEntryPage
import org.odk.collect.android.support.pages.MainMenuPage
import org.odk.collect.android.support.rules.CollectTestRule
import org.odk.collect.android.support.rules.TestRuleChain

Expand All @@ -21,24 +23,35 @@ class EntityFormTest {
.around(rule)

@Test
fun fillingEntityRegistrationForm_createsEntityInTheBrowser() {
fun fillingEntityRegistrationForm_beforeCreatingEntityList_doesNotCreateEntityForFollowUpForms() {
testDependencies.server.addForm("one-question-entity-registration.xml")
testDependencies.server.addForm(
"one-question-entity-update.xml",
listOf(EntityListItem("people.csv"))
)

rule.withMatchExactlyProject(testDependencies.server.url)
.enableLocalEntitiesInForms()

.startBlankForm("One Question Entity Registration")
.fillOutAndFinalize(FormEntryPage.QuestionAndAnswer("Name", "Logan Roy"))
.openEntityBrowser()
.clickOnDataset("people")
.assertEntity("Logan Roy", "full_name: Logan Roy")

.startBlankForm("One Question Entity Update")
.assertQuestion("Select person")
.assertText("Roman Roy")
.assertTextDoesNotExist("Logan Roy")
}

@Test
fun fillingEntityRegistrationForm_createsEntityForFollowUpForms() {
testDependencies.server.addForm("one-question-entity-registration.xml")
testDependencies.server.addForm("one-question-entity-update.xml", listOf("people.csv"))
testDependencies.server.addForm(
"one-question-entity-update.xml",
listOf(EntityListItem("people.csv"))
)

rule.withMatchExactlyProject(testDependencies.server.url)
.enableLocalEntitiesInForms()
.setupEntities("people")

.startBlankForm("One Question Entity Registration")
.fillOutAndFinalize(FormEntryPage.QuestionAndAnswer("Name", "Logan Roy"))
Expand All @@ -52,10 +65,13 @@ class EntityFormTest {
@Test
fun fillingEntityRegistrationForm_createsEntityForFollowUpFormsWithCachedFormDefs() {
testDependencies.server.addForm("one-question-entity-registration.xml")
testDependencies.server.addForm("one-question-entity-update.xml", listOf("people.csv"))
testDependencies.server.addForm(
"one-question-entity-update.xml",
listOf(EntityListItem("people.csv"))
)

rule.withMatchExactlyProject(testDependencies.server.url)
.enableLocalEntitiesInForms()
.setupEntities("people")

.startBlankForm("One Question Entity Update") // Open to create cached form def
.pressBackAndDiscardForm()
Expand All @@ -71,10 +87,13 @@ class EntityFormTest {

@Test
fun fillingEntityUpdateForm_updatesEntityForFollowUpForms() {
testDependencies.server.addForm("one-question-entity-update.xml", listOf("people.csv"))
testDependencies.server.addForm(
"one-question-entity-update.xml",
listOf(EntityListItem("people.csv"))
)

rule.withMatchExactlyProject(testDependencies.server.url)
.enableLocalEntitiesInForms()
.setupEntities("people")

.startBlankForm("One Question Entity Update")
.assertQuestion("Select person")
Expand All @@ -90,54 +109,37 @@ class EntityFormTest {
}

@Test
fun fillingEntityFollowUpForm_whenOnlineDuplicateHasHigherVersion_showsOnlineVersion() {
testDependencies.server.addForm("one-question-entity-update.xml", listOf("people.csv"))

val mainMenuPage = rule.withMatchExactlyProject(testDependencies.server.url)
fun entityListSecondaryInstancesAreConsistentBetweenFollowUpForms() {
testDependencies.server.apply {
addForm(
"one-question-entity-update.xml",
listOf(EntityListItem("people.csv"))
)

addForm(
"one-question-entity-follow-up.xml",
listOf(EntityListItem("people.csv", "updated-people.csv"))
)
}

rule.withProject(testDependencies.server)
.enableLocalEntitiesInForms()
.addEntityListInBrowser("people")

.clickGetBlankForm()
.clickClearAll()
.clickForm("One Question Entity Update")
.clickGetSelected()
.clickOK(MainMenuPage())
.startBlankForm("One Question Entity Update")
.assertQuestion("Select person")
.clickOnText("Roman Roy")
.swipeToNextQuestion("Name")
.answerQuestion("Name", "Romulus Roy")
.swipeToEndScreen()
.clickFinalize()

testDependencies.server.updateMediaFile(
"one-question-entity-update.xml",
"people.csv",
"updated-people.csv"
)
.assertText("Roman Roy")
.pressBackAndDiscardForm()

mainMenuPage.clickFillBlankForm()
.clickRefresh()
.clickOnForm("One Question Entity Update")
.clickGetBlankForm()
.clickGetSelected() // Collect automatically only selects the un-downloaded forms
.clickOK(MainMenuPage())
.startBlankForm("One Question Entity Update")
.assertText("Ro-Ro Roy")
.assertTextDoesNotExist("Romulus Roy")
.assertTextDoesNotExist("Roman Roy")
}

@Test
fun fillingEntityFollowUpForm_whenOfflineDuplicateHasHigherVersion_showsOfflineVersion() {
testDependencies.server.addForm(
"one-question-entity-update.xml",
mapOf("people.csv" to "updated-people.csv")
)

rule.withMatchExactlyProject(testDependencies.server.url)
.enableLocalEntitiesInForms()

.startBlankForm("One Question Entity Update")
.assertQuestion("Select person")
.clickOnText("Ro-Ro Roy")
.swipeToNextQuestion("Name")
.answerQuestion("Name", "Romulus Roy")
.swipeToEndScreen()
.clickFinalize()

.startBlankForm("One Question Entity Update")
.assertText("Romulus Roy")
.assertTextDoesNotExist("Ro-Ro Roy")
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ class SwitchProjectTest {
.clickOKOnDialog(MainMenuPage())

// Fill form
.addEntityListInBrowser("people")
.startBlankForm("One Question Entity Registration")
.fillOutAndFinalize(FormEntryPage.QuestionAndAnswer("Name", "Alice"))
.clickSendFinalizedForm(1)
Expand Down
Loading

0 comments on commit 916629c

Please sign in to comment.