Skip to content

Commit

Permalink
Improved tests
Browse files Browse the repository at this point in the history
  • Loading branch information
grzesiek2010 committed Feb 18, 2025
1 parent 6216dd6 commit 8681d28
Show file tree
Hide file tree
Showing 2 changed files with 89 additions and 38 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import org.junit.Test
import org.odk.collect.android.entities.support.EntitySameAsMatcher.Companion.sameEntityAs
import org.odk.collect.entities.storage.EntitiesRepository
import org.odk.collect.entities.storage.Entity
import org.odk.collect.entities.storage.QueryException
import org.odk.collect.shared.Query

abstract class EntitiesRepositoryTest {
Expand Down Expand Up @@ -872,4 +873,12 @@ abstract class EntitiesRepositoryTest {
val queriedCanet = repository.query("other.favourite.wines", Query.Eq("label", "Pontet-Canet 2014"))
assertThat(queriedCanet, containsInAnyOrder(sameEntityAs(canet)))
}

@Test(expected = QueryException::class)
fun `#query throws an exception when not existing property is used`() {
val repository = buildSubject()
repository.save("wines", Entity.New("1", "Léoville Barton 2008",))

repository.query("wines", Query.Eq("score", "92"))
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -543,7 +543,7 @@ class LocalEntitiesFilterStrategyTest {
}

@Test
fun `works correctly but not in the optimized way with question = expressions`() {
fun `works correctly but not in the optimized way with question = ''`() {
entitiesRepository.save("things", Entity.New("thing1", "Thing1"))

val scenario = Scenario.init(
Expand All @@ -556,63 +556,78 @@ class LocalEntitiesFilterStrategyTest {
t(
"data id=\"create-entity-form\"",
t("ref_question"),
t("question1"),
t("question2"),
t("question3"),
t("question")
)
),
t("instance id=\"things\" src=\"jr://file-csv/things.csv\""),
bind("/data/ref_question").type("string"),
bind("/data/question1").type("string"),
bind("/data/question2").type("string"),
bind("/data/question3").type("string")
bind("/data/question").type("string")
)
),
body(
input("/data/ref_question"),
select1Dynamic(
"/data/question1",
"/data/question",
"instance('things')/root/item[/data/ref_question='']",
"name",
"label"
),
select1Dynamic(
"/data/question2",
"instance('things')/root/item[/data/ref_question=undefined]",
"name",
"label"
),
select1Dynamic(
"/data/question3",
"instance('things')/root/item[/data/ref_question=null]",
"name",
"label"
)
)
),
controllerSupplier
)

var choices = scenario.choicesOf("/data/question1").map { it.value }
val choices = scenario.choicesOf("/data/question").map { it.value }
assertThat(choices, containsInAnyOrder("thing1"))

choices = scenario.choicesOf("/data/question2").map { it.value }
assertThat(choices, containsInAnyOrder("thing1"))
assertThat(fallthroughFilterStrategy.fellThrough, equalTo(true))
}

choices = scenario.choicesOf("/data/question3").map { it.value }
assertThat(choices, containsInAnyOrder("thing1"))
@Test
fun `works correctly but not in the optimized way with question = value`() {
entitiesRepository.save("things", Entity.New("thing1", "Thing1"))

val scenario = Scenario.init(
"Secondary instance form",
html(
head(
title("Secondary instance form"),
model(
mainInstance(
t(
"data id=\"create-entity-form\"",
t("ref_question"),
t("question")
)
),
t("instance id=\"things\" src=\"jr://file-csv/things.csv\""),
bind("/data/ref_question").type("string"),
bind("/data/question").type("string")
)
),
body(
input("/data/ref_question"),
select1Dynamic(
"/data/question",
"instance('things')/root/item[/data/ref_question='']",
"name",
"label"
)
)
),
controllerSupplier
)
scenario.next()
scenario.answer("blah")

choices = scenario.choicesOf("/data/question1").map { it.value }
val choices = scenario.choicesOf("/data/question").map { it.value }
assertThat(choices.isEmpty(), equalTo(true))

assertThat(fallthroughFilterStrategy.fellThrough, equalTo(true))
}

@Test
fun `works correctly but not in the optimized way with non existing property = expressions`() {
fun `works correctly but not in the optimized way with non existing property = ''`() {
entitiesRepository.save("things", Entity.New("thing1", "Thing1"))

val scenario = Scenario.init(
Expand All @@ -624,24 +639,54 @@ class LocalEntitiesFilterStrategyTest {
mainInstance(
t(
"data id=\"create-entity-form\"",
t("question1"),
t("question2"),
t("question")
)
),
t("instance id=\"things\" src=\"jr://file-csv/things.csv\""),
bind("/data/question1").type("string"),
bind("/data/question2").type("string")
bind("/data/question").type("string")
)
),
body(
select1Dynamic(
"/data/question1",
"/data/question",
"instance('things')/root/item[not_existing_property='']",
"name",
"label"
),
)
)
),
controllerSupplier
)

val choices = scenario.choicesOf("/data/question").map { it.value }
assertThat(choices, containsInAnyOrder("thing1"))

assertThat(fallthroughFilterStrategy.fellThrough, equalTo(true))
}

@Test
fun `works correctly but not in the optimized way with non existing property = value`() {
entitiesRepository.save("things", Entity.New("thing1", "Thing1"))

val scenario = Scenario.init(
"Secondary instance form",
html(
head(
title("Secondary instance form"),
model(
mainInstance(
t(
"data id=\"create-entity-form\"",
t("question")
)
),
t("instance id=\"things\" src=\"jr://file-csv/things.csv\""),
bind("/data/question").type("string")
)
),
body(
select1Dynamic(
"/data/question2",
"/data/question",
"instance('things')/root/item[not_existing_property='value']",
"name",
"label"
Expand All @@ -651,10 +696,7 @@ class LocalEntitiesFilterStrategyTest {
controllerSupplier
)

var choices = scenario.choicesOf("/data/question1").map { it.value }
assertThat(choices, containsInAnyOrder("thing1"))

choices = scenario.choicesOf("/data/question2").map { it.value }
val choices = scenario.choicesOf("/data/question").map { it.value }
assertThat(choices.isEmpty(), equalTo(true))

assertThat(fallthroughFilterStrategy.fellThrough, equalTo(true))
Expand Down

0 comments on commit 8681d28

Please sign in to comment.