Skip to content

Commit

Permalink
Merge branch 'master' into ashobhit/2832/draft-position
Browse files Browse the repository at this point in the history
  • Loading branch information
shobhitagarwal1612 authored Nov 28, 2024
2 parents af2026a + f2441dd commit 0e46c8b
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 4 deletions.
2 changes: 1 addition & 1 deletion ground/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -362,7 +362,7 @@ dependencies {
api("com.google.protobuf:protobuf-kotlin-lite:4.26.1")

// Pulls protodefs from the specified commit in the ground-platform repo.
groundProtoJar "com.github.google:ground-platform:e0cc72b@jar"
groundProtoJar "com.github.google:ground-platform:125cf86@jar"
}

protobuf {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class MultipleChoiceTaskData(
fun getSelectedOptionsIdsExceptOther(): List<String> =
selectedOptionIds.filterNot { it.isOtherText() }

fun hasOtherText(): Boolean = selectedOptionIds.any { it.isOtherText() }
fun isOtherTextSelected(): Boolean = selectedOptionIds.any { it.isOtherText() }

fun getOtherText(): String =
selectedOptionIds
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,8 @@ private fun toTaskData(id: String, newTaskData: TaskData) = taskData {
}
is MultipleChoiceTaskData -> multipleChoiceResponses = multipleChoiceResponses {
newTaskData.getSelectedOptionsIdsExceptOther().forEach { selectedOptionIds.add(it) }
if (newTaskData.hasOtherText()) {
if (newTaskData.isOtherTextSelected()) {
otherSelected = true
otherText = newTaskData.getOtherText()
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ import com.google.android.ground.proto.TaskData.DRAW_GEOMETRY_RESULT_FIELD_NUMBE
import com.google.android.ground.proto.TaskData.DateTimeResponse.DATE_TIME_FIELD_NUMBER
import com.google.android.ground.proto.TaskData.DrawGeometryResult.GEOMETRY_FIELD_NUMBER
import com.google.android.ground.proto.TaskData.MULTIPLE_CHOICE_RESPONSES_FIELD_NUMBER
import com.google.android.ground.proto.TaskData.MultipleChoiceResponses.OTHER_SELECTED_FIELD_NUMBER
import com.google.android.ground.proto.TaskData.MultipleChoiceResponses.OTHER_TEXT_FIELD_NUMBER
import com.google.android.ground.proto.TaskData.MultipleChoiceResponses.SELECTED_OPTION_IDS_FIELD_NUMBER
import com.google.android.ground.proto.TaskData.NUMBER_RESPONSE_FIELD_NUMBER
Expand Down Expand Up @@ -136,6 +137,18 @@ class SubmissionMutationConverterTest {
ids = listOf("option id 1", "option id 2", "[ other value ]"),
)

private val multipleChoiceTaskDataOtherEmpty =
MultipleChoiceTaskData.fromList(
MultipleChoice(
persistentListOf(
Option("option id 1", "code1", "Option 1"),
Option("option id 2", "code2", "Option 2"),
),
MultipleChoice.Cardinality.SELECT_MULTIPLE,
),
ids = listOf("[ ]"),
)

private val numberTaskData = NumberTaskData.fromNumber("123")

private val dropPinTaskResult = DropPinTaskData(Point(Coordinates(10.0, 20.0)))
Expand Down Expand Up @@ -196,6 +209,11 @@ class SubmissionMutationConverterTest {
taskType = Task.Type.MULTIPLE_CHOICE,
newTaskData = multipleChoiceTaskDataOther,
),
ValueDelta(
taskId = "multiple_choice_task_other_empty_value",
taskType = Task.Type.MULTIPLE_CHOICE,
newTaskData = multipleChoiceTaskDataOtherEmpty,
),
ValueDelta(
taskId = "number_task",
taskType = Task.Type.NUMBER,
Expand Down Expand Up @@ -234,7 +252,10 @@ class SubmissionMutationConverterTest {
),
mapOf(
MULTIPLE_CHOICE_RESPONSES_FIELD_NUMBER.toString() to
mapOf(OTHER_TEXT_FIELD_NUMBER.toString() to "other value"),
mapOf(
OTHER_TEXT_FIELD_NUMBER.toString() to "other value",
OTHER_SELECTED_FIELD_NUMBER.toString() to true,
),
TASK_ID_FIELD_NUMBER.toString() to "single_choice_task_other",
),
mapOf(
Expand All @@ -249,9 +270,15 @@ class SubmissionMutationConverterTest {
mapOf(
SELECTED_OPTION_IDS_FIELD_NUMBER.toString() to listOf("option id 1", "option id 2"),
OTHER_TEXT_FIELD_NUMBER.toString() to "other value",
OTHER_SELECTED_FIELD_NUMBER.toString() to true,
),
TASK_ID_FIELD_NUMBER.toString() to "multiple_choice_task_other",
),
mapOf(
MULTIPLE_CHOICE_RESPONSES_FIELD_NUMBER.toString() to
mapOf(OTHER_SELECTED_FIELD_NUMBER.toString() to true),
TASK_ID_FIELD_NUMBER.toString() to "multiple_choice_task_other_empty_value",
),
mapOf(
NUMBER_RESPONSE_FIELD_NUMBER.toString() to mapOf(NUMBER_FIELD_NUMBER.toString() to 123.0),
TASK_ID_FIELD_NUMBER.toString() to "number_task",
Expand Down

0 comments on commit 0e46c8b

Please sign in to comment.