From 561a370168bbab89620aa95066f09ef967b8b9bb Mon Sep 17 00:00:00 2001 From: Grzegorz Orczykowski Date: Sat, 20 Apr 2024 22:37:17 +0200 Subject: [PATCH 1/3] Added a failing test --- .../feature/formentry/FieldListUpdateTest.java | 14 ++++++++++++++ .../main/resources/forms/fieldlist-updates.xml | 15 +++++++++++++++ 2 files changed, 29 insertions(+) diff --git a/collect_app/src/androidTest/java/org/odk/collect/android/feature/formentry/FieldListUpdateTest.java b/collect_app/src/androidTest/java/org/odk/collect/android/feature/formentry/FieldListUpdateTest.java index df21aa249a8..611bb976a7d 100644 --- a/collect_app/src/androidTest/java/org/odk/collect/android/feature/formentry/FieldListUpdateTest.java +++ b/collect_app/src/androidTest/java/org/odk/collect/android/feature/formentry/FieldListUpdateTest.java @@ -421,6 +421,20 @@ public void recordingAudio_ShouldChangeRelevanceOfRelatedField() { .assertTextDoesNotExist("Target16"); } + @Test + public void changeInValueUsedToDetermineIfAQuestionIsRequired_ShouldUpdateTheRelatedRequiredQuestion() { + new FormEntryPage("fieldlist-updates") + .clickGoToArrow() + .clickGoUpIcon() + .clickOnGroup("Dynamic required question") + .clickOnQuestion("Source17") + .assertQuestion("Target17") + .answerQuestion(0, "blah") + .assertQuestion("Target17", true) + .answerQuestion(0, "") + .assertQuestion("Target17"); + } + // Scroll down until the desired group name is visible. This is needed to make the tests work // on devices with screens of different heights. private void jumpToGroupWithText(String text) { diff --git a/test-forms/src/main/resources/forms/fieldlist-updates.xml b/test-forms/src/main/resources/forms/fieldlist-updates.xml index f812e44bf28..cd52632c820 100644 --- a/test-forms/src/main/resources/forms/fieldlist-updates.xml +++ b/test-forms/src/main/resources/forms/fieldlist-updates.xml @@ -186,6 +186,10 @@ + + + + @@ -372,6 +376,8 @@ + + @@ -729,5 +735,14 @@ + + + + + + + + + From b92e638e93b0ceaf64f9a1070acdb0408c473eaf Mon Sep 17 00:00:00 2001 From: Grzegorz Orczykowski Date: Sat, 20 Apr 2024 22:37:42 +0200 Subject: [PATCH 2/3] Fixed updating required questions in a field-list --- .../android/logic/ImmutableDisplayableQuestion.java | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/collect_app/src/main/java/org/odk/collect/android/logic/ImmutableDisplayableQuestion.java b/collect_app/src/main/java/org/odk/collect/android/logic/ImmutableDisplayableQuestion.java index 32d5ecf7cd4..02007a78119 100644 --- a/collect_app/src/main/java/org/odk/collect/android/logic/ImmutableDisplayableQuestion.java +++ b/collect_app/src/main/java/org/odk/collect/android/logic/ImmutableDisplayableQuestion.java @@ -63,6 +63,11 @@ public class ImmutableDisplayableQuestion { */ private final boolean isReadOnly; + /** + * Whether the question is required. + */ + private final boolean isRequired; + /** * The choices displayed to a user if this question is of a type that has choices. */ @@ -78,6 +83,7 @@ public ImmutableDisplayableQuestion(FormEntryPrompt question) { guidanceText = question.getSpecialFormQuestionText(question.getQuestion().getHelpTextID(), "guidance"); answerText = question.getAnswerText(); isReadOnly = question.isReadOnly(); + isRequired = question.isRequired(); List choices = question.getSelectChoices(); if (choices != null) { @@ -106,7 +112,8 @@ public boolean sameAs(FormEntryPrompt question) { && (getGuidanceHintText(question) == null ? guidanceText == null : getGuidanceHintText(question).equals(guidanceText)) && (question.getAnswerText() == null ? answerText == null : question.getAnswerText().equals(answerText)) && (question.isReadOnly() == isReadOnly) - && selectChoiceListsEqual(question.getSelectChoices(), selectChoices); + && selectChoiceListsEqual(question.getSelectChoices(), selectChoices) + && question.isRequired() == isRequired; } private static boolean selectChoiceListsEqual(List selectChoiceList1, List selectChoiceList2) { From bc38868271a1bea2a285daaa552d52f3c3dfe07d Mon Sep 17 00:00:00 2001 From: Grzegorz Orczykowski Date: Sat, 20 Apr 2024 22:48:26 +0200 Subject: [PATCH 3/3] Improved the new test --- .../android/feature/formentry/FieldListUpdateTest.java | 4 +++- .../odk/collect/android/support/pages/FormEntryPage.java | 7 +++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/collect_app/src/androidTest/java/org/odk/collect/android/feature/formentry/FieldListUpdateTest.java b/collect_app/src/androidTest/java/org/odk/collect/android/feature/formentry/FieldListUpdateTest.java index 611bb976a7d..02f706d575a 100644 --- a/collect_app/src/androidTest/java/org/odk/collect/android/feature/formentry/FieldListUpdateTest.java +++ b/collect_app/src/androidTest/java/org/odk/collect/android/feature/formentry/FieldListUpdateTest.java @@ -431,8 +431,10 @@ public void changeInValueUsedToDetermineIfAQuestionIsRequired_ShouldUpdateTheRel .assertQuestion("Target17") .answerQuestion(0, "blah") .assertQuestion("Target17", true) + .swipeToNextQuestionWithConstraintViolation(org.odk.collect.strings.R.string.required_answer_error) .answerQuestion(0, "") - .assertQuestion("Target17"); + .assertQuestion("Target17") + .assertTextDoesNotExist(org.odk.collect.strings.R.string.required_answer_error); } // Scroll down until the desired group name is visible. This is needed to make the tests work diff --git a/collect_app/src/androidTest/java/org/odk/collect/android/support/pages/FormEntryPage.java b/collect_app/src/androidTest/java/org/odk/collect/android/support/pages/FormEntryPage.java index 7ae75db0bac..2c1541c97eb 100644 --- a/collect_app/src/androidTest/java/org/odk/collect/android/support/pages/FormEntryPage.java +++ b/collect_app/src/androidTest/java/org/odk/collect/android/support/pages/FormEntryPage.java @@ -143,6 +143,13 @@ public ErrorDialog swipeToNextQuestionWithError() { return new ErrorDialog().assertOnPage(); } + public FormEntryPage swipeToNextQuestionWithConstraintViolation(int constraintText) { + flingLeft(); + assertText(constraintText); + + return this; + } + public FormEntryPage swipeToNextQuestionWithConstraintViolation(String constraintText) { flingLeft(); assertText(constraintText);