Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2022-2024 Google LLC
* Copyright 2022-2025 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -125,6 +125,9 @@ internal object CheckBoxGroupViewHolderFactory :
when (isChecked) {
true -> {
val newAnswers = questionnaireViewItem.answers.toMutableList()
if (!questionnaireViewItem.questionnaireItem.repeats) {
newAnswers.clear()
}
Comment on lines 127 to +130
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
val newAnswers = questionnaireViewItem.answers.toMutableList()
if (!questionnaireViewItem.questionnaireItem.repeats) {
newAnswers.clear()
}
val newAnswers = if (questionnaireViewItem.questionnaireItem.repeats) {
questionnaireViewItem.answers.toMutableList()
} else {
emptyList()
}

newAnswers +=
QuestionnaireResponse.QuestionnaireResponseItemAnswerComponent().apply {
value = answerOption.value
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2023-2024 Google LLC
* Copyright 2023-2025 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -616,4 +616,51 @@ class CheckBoxGroupViewHolderFactoryTest {
},
)
}

@Test
fun click_should_Select_Other_CheckboxButton() {
viewHolder.bind(
QuestionnaireViewItem(
Questionnaire.QuestionnaireItemComponent().apply {
repeats = false
addAnswerOption(
Questionnaire.QuestionnaireItemAnswerOptionComponent().apply {
value =
Coding().apply {
code = "code-1"
display = "display-1"
}
},
)
addAnswerOption(
Questionnaire.QuestionnaireItemAnswerOptionComponent().apply {
value =
Coding().apply {
code = "code-2"
display = "display-2"
}
},
)
},
QuestionnaireResponse.QuestionnaireResponseItemComponent().apply {
addAnswer(
QuestionnaireResponse.QuestionnaireResponseItemAnswerComponent().apply {
value =
Coding().apply {
code = "code-1"
display = "display-1"
}
},
)
},
validationResult = NotValidated,
answersChangedCallback = { _, _, _, _ -> },
),
)

val checkBoxGroup = viewHolder.itemView.findViewById<ConstraintLayout>(R.id.checkbox_group)
assertThat((checkBoxGroup.getChildAt(1) as CheckBox).isChecked).isTrue()
checkBoxGroup.getChildAt(2).performClick()
assertThat((checkBoxGroup.getChildAt(2) as CheckBox).isChecked).isTrue()
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

check here that the first answer is not selected.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

add

  assertThat((checkBoxGroup.getChildAt(1) as CheckBox).isChecked).isFalse()

}
}
Loading