Skip to content

Commit

Permalink
Hide previous and next button (google#2397)
Browse files Browse the repository at this point in the history
* Hide previous button on first page

* Hide next button on last page

* Add tests
  • Loading branch information
FikriMilano committed Jan 23, 2024
1 parent 9d41e1b commit 99c5b9c
Show file tree
Hide file tree
Showing 2 changed files with 150 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -190,8 +190,8 @@ class QuestionnaireFragment : Fragment() {
reviewModeEditButton.visibility = View.GONE

if (displayMode.pagination.isPaginated) {
paginationPreviousButton.visibility = View.VISIBLE
paginationPreviousButton.isEnabled = displayMode.pagination.hasPreviousPage
paginationPreviousButton.visibility =
if (displayMode.pagination.hasPreviousPage) View.VISIBLE else View.GONE
paginationNextButton.visibility =
if (displayMode.pagination.hasNextPage) View.VISIBLE else View.GONE
} else {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2022-2023 Google LLC
* Copyright 2022-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 @@ -139,6 +139,153 @@ class QuestionnaireFragmentTest {
.isEqualTo(View.VISIBLE)
}

@Test
fun `should hide next button on last page`() {
val questionnaireJson =
"""{
"resourceType": "Questionnaire",
"item": [
{
"linkId": "1",
"type": "group",
"extension": [
{
"url": "http:https://hl7.org/fhir/StructureDefinition/questionnaire-itemControl",
"valueCodeableConcept": {
"coding": [
{
"system": "http:https://hl7.org/fhir/questionnaire-item-control",
"code": "page",
"display": "Page"
}
],
"text": "Page"
}
}
],
"item": [
{
"linkId": "1.1",
"type": "display",
"text": "Item 1"
}
]
},
{
"linkId": "2",
"type": "group",
"extension": [
{
"url": "http:https://hl7.org/fhir/StructureDefinition/questionnaire-itemControl",
"valueCodeableConcept": {
"coding": [
{
"system": "http:https://hl7.org/fhir/questionnaire-item-control",
"code": "page",
"display": "Page"
}
],
"text": "Page"
}
}
],
"item": [
{
"linkId": "2.1",
"type": "display",
"text": "Item 2"
}
]
}
]
}
"""
val scenario =
launchFragmentInContainer<QuestionnaireFragment>(
bundleOf(
EXTRA_QUESTIONNAIRE_JSON_STRING to questionnaireJson,
),
)
scenario.moveToState(Lifecycle.State.RESUMED)
val view = scenario.withFragment { requireView() }
view.findViewById<Button>(R.id.pagination_next_button).performClick()
assertThat(view.findViewById<Button>(R.id.pagination_next_button).visibility)
.isEqualTo(View.GONE)
}

@Test
fun `should hide previous button on first page`() {
val questionnaireJson =
"""{
"resourceType": "Questionnaire",
"item": [
{
"linkId": "1",
"type": "group",
"extension": [
{
"url": "http:https://hl7.org/fhir/StructureDefinition/questionnaire-itemControl",
"valueCodeableConcept": {
"coding": [
{
"system": "http:https://hl7.org/fhir/questionnaire-item-control",
"code": "page",
"display": "Page"
}
],
"text": "Page"
}
}
],
"item": [
{
"linkId": "1.1",
"type": "display",
"text": "Item 1"
}
]
},
{
"linkId": "2",
"type": "group",
"extension": [
{
"url": "http:https://hl7.org/fhir/StructureDefinition/questionnaire-itemControl",
"valueCodeableConcept": {
"coding": [
{
"system": "http:https://hl7.org/fhir/questionnaire-item-control",
"code": "page",
"display": "Page"
}
],
"text": "Page"
}
}
],
"item": [
{
"linkId": "2.1",
"type": "display",
"text": "Item 2"
}
]
}
]
}
"""
val scenario =
launchFragmentInContainer<QuestionnaireFragment>(
bundleOf(
EXTRA_QUESTIONNAIRE_JSON_STRING to questionnaireJson,
),
)
scenario.moveToState(Lifecycle.State.RESUMED)
val view = scenario.withFragment { requireView() }
assertThat(view.findViewById<Button>(R.id.pagination_previous_button).visibility)
.isEqualTo(View.GONE)
}

@Test
fun `questionnaireItemViewHolderFactoryMatchersProvider should have custom QuestionnaireItemViewHolderFactoryMatchers `() {
ApplicationProvider.getApplicationContext<DataCaptureTestApplication>()
Expand Down

0 comments on commit 99c5b9c

Please sign in to comment.