Skip to content

Commit

Permalink
Hide the Next button if it is disabled (#2407)
Browse files Browse the repository at this point in the history
* add horizontalscrollview to bottom navigation

* Revert horizontal scrollview.

* Make Next button hidden if disabled.

* spotless apply.

* Add android tests.

* Removed dead code.

* Add missing file.

---------

Co-authored-by: Santosh Pingle <[email protected]>
  • Loading branch information
santosh-pingle and Santosh Pingle authored Jan 15, 2024
1 parent 30a07d7 commit 110d62e
Show file tree
Hide file tree
Showing 4 changed files with 90 additions and 5 deletions.
60 changes: 60 additions & 0 deletions datacapture/sampledata/layout_paginated.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
{
"resourceType": "Questionnaire",
"item": [
{
"linkId": "1",
"type": "group",
"extension": [
{
"url": "http://hl7.org/fhir/StructureDefinition/questionnaire-itemControl",
"valueCodeableConcept": {
"coding": [
{
"system": "http://hl7.org/fhir/questionnaire-item-control",
"code": "page",
"display": "Page"
}
],
"text": "Page"
}
}
],
"item": [
{
"linkId": "1.1",
"type": "display",
"text": "Personal information",
"prefix": "1."
}
]
},
{
"linkId": "2",
"type": "group",
"extension": [
{
"url": "http://hl7.org/fhir/StructureDefinition/questionnaire-itemControl",
"valueCodeableConcept": {
"coding": [
{
"system": "http://hl7.org/fhir/questionnaire-item-control",
"code": "page",
"display": "Page"
}
],
"text": "Page"
}
}
],
"item": [
{
"linkId": "2.1",
"type": "date",
"text": "Date of birth",
"prefix": "2.",
"required": true
}
]
}
]
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2023 Google LLC
* Copyright 2023-2024 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 @@ -105,6 +105,30 @@ class QuestionnaireUiEspressoTest {
)
}

@Test
fun shouldHideNextButtonIfDisabled() {
buildFragmentFromQuestionnaire("/layout_paginated.json", true)

clickOnText("Next")

onView(withId(R.id.pagination_next_button))
.check(
ViewAssertions.matches(ViewMatchers.withEffectiveVisibility(ViewMatchers.Visibility.GONE)),
)
}

@Test
fun shouldDisplayNextButtonIfEnabled() {
buildFragmentFromQuestionnaire("/layout_paginated.json", true)

onView(withId(R.id.pagination_next_button))
.check(
ViewAssertions.matches(
ViewMatchers.withEffectiveVisibility(ViewMatchers.Visibility.VISIBLE),
),
)
}

@Test
fun integerTextEdit_inputOutOfRange_shouldShowError() {
buildFragmentFromQuestionnaire("/text_questionnaire_integer.json")
Expand Down Expand Up @@ -503,6 +527,7 @@ class QuestionnaireUiEspressoTest {
val questionnaireFragment =
QuestionnaireFragment.builder()
.setQuestionnaire(questionnaireJsonString)
.setShowCancelButton(true)
.showReviewPageBeforeSubmit(isReviewMode)
.build()
activityScenarioRule.scenario.onActivity { activity ->
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2023 Google LLC
* Copyright 2023-2024 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 @@ -192,8 +192,8 @@ class QuestionnaireFragment : Fragment() {
if (displayMode.pagination.isPaginated) {
paginationPreviousButton.visibility = View.VISIBLE
paginationPreviousButton.isEnabled = displayMode.pagination.hasPreviousPage
paginationNextButton.visibility = View.VISIBLE
paginationNextButton.isEnabled = displayMode.pagination.hasNextPage
paginationNextButton.visibility =
if (displayMode.pagination.hasNextPage) View.VISIBLE else View.GONE
} else {
paginationPreviousButton.visibility = View.GONE
paginationNextButton.visibility = View.GONE
Expand Down
2 changes: 1 addition & 1 deletion datacapture/src/main/res/values/styles.xml
Original file line number Diff line number Diff line change
Expand Up @@ -400,7 +400,7 @@
</style>
<style
name="Questionnaire.CancelButtonStyle"
parent="Widget.Material3.Button.OutlinedButton"
parent="Widget.Material3.Button.TextButton"
>
<item name="android:textAllCaps">false</item>
<item name="android:visibility">visible</item>
Expand Down

0 comments on commit 110d62e

Please sign in to comment.