diff --git a/datacapture/src/main/java/com/google/android/fhir/datacapture/QuestionnaireFragment.kt b/datacapture/src/main/java/com/google/android/fhir/datacapture/QuestionnaireFragment.kt index a67e139557..457d8230ad 100644 --- a/datacapture/src/main/java/com/google/android/fhir/datacapture/QuestionnaireFragment.kt +++ b/datacapture/src/main/java/com/google/android/fhir/datacapture/QuestionnaireFragment.kt @@ -160,9 +160,13 @@ class QuestionnaireFragment : Fragment() { } // Set bottom navigation - bottomNavContainerFrame.visibility = View.VISIBLE - NavigationViewHolder(bottomNavContainerFrame) - .bind(state.bottomNavItems.single().questionnaireNavigationUIState) + if (state.bottomNavItems.isNotEmpty()) { + bottomNavContainerFrame.visibility = View.VISIBLE + NavigationViewHolder(bottomNavContainerFrame) + .bind(state.bottomNavItems.single().questionnaireNavigationUIState) + } else { + bottomNavContainerFrame.visibility = View.GONE + } // Hide progress indicator questionnaireProgressIndicator.visibility = View.GONE @@ -175,9 +179,13 @@ class QuestionnaireFragment : Fragment() { reviewModeEditButton.visibility = View.GONE // Set bottom navigation - bottomNavContainerFrame.visibility = View.VISIBLE - NavigationViewHolder(bottomNavContainerFrame) - .bind(state.bottomNavItems.single().questionnaireNavigationUIState) + if (state.bottomNavItems.isNotEmpty()) { + bottomNavContainerFrame.visibility = View.VISIBLE + NavigationViewHolder(bottomNavContainerFrame) + .bind(state.bottomNavItems.single().questionnaireNavigationUIState) + } else { + bottomNavContainerFrame.visibility = View.GONE + } // Set progress indicator questionnaireProgressIndicator.visibility = View.VISIBLE diff --git a/datacapture/src/test/java/com/google/android/fhir/datacapture/QuestionnaireFragmentTest.kt b/datacapture/src/test/java/com/google/android/fhir/datacapture/QuestionnaireFragmentTest.kt index e181a93271..c34e0f36e6 100644 --- a/datacapture/src/test/java/com/google/android/fhir/datacapture/QuestionnaireFragmentTest.kt +++ b/datacapture/src/test/java/com/google/android/fhir/datacapture/QuestionnaireFragmentTest.kt @@ -417,6 +417,61 @@ class QuestionnaireFragmentTest { } } + fun `show bottom navigation container when setShowNavigationInDefaultLongScroll is set to false`() { + val questionnaire = + Questionnaire().apply { + id = "a-questionnaire" + addItem( + Questionnaire.QuestionnaireItemComponent().apply { + linkId = "a-link-id" + type = Questionnaire.QuestionnaireItemType.BOOLEAN + }, + ) + } + val questionnaireJson = parser.encodeResourceToString(questionnaire) + val scenario = + launchFragment( + QuestionnaireFragment.builder() + .setQuestionnaire(questionnaireJson) + .setShowNavigationInDefaultLongScroll(false) + .buildArgs(), + ) + scenario.moveToState(Lifecycle.State.RESUMED) + scenario.withFragment { + val bottomNavContainer = requireView().findViewById(R.id.bottom_nav_container_frame) + assertThat(bottomNavContainer.visibility).isEqualTo(View.VISIBLE) + assertThat(bottomNavContainer.findViewById(R.id.submit_questionnaire).isEnabled) + .isTrue() + } + } + + @Test + fun `hide the bottom navigation container when setShowNavigationInDefaultLongScroll is set to true`() { + val questionnaire = + Questionnaire().apply { + id = "a-questionnaire" + addItem( + Questionnaire.QuestionnaireItemComponent().apply { + linkId = "a-link-id" + type = Questionnaire.QuestionnaireItemType.BOOLEAN + }, + ) + } + val questionnaireJson = parser.encodeResourceToString(questionnaire) + val scenario = + launchFragment( + QuestionnaireFragment.builder() + .setQuestionnaire(questionnaireJson) + .setShowNavigationInDefaultLongScroll(true) + .buildArgs(), + ) + scenario.moveToState(Lifecycle.State.RESUMED) + scenario.withFragment { + val bottomNavContainer = requireView().findViewById(R.id.bottom_nav_container_frame) + assertThat(bottomNavContainer.visibility).isEqualTo(View.GONE) + } + } + object QuestionnaireItemViewHolderFactoryMatchersProviderFactoryTestImpl : QuestionnaireItemViewHolderFactoryMatchersProviderFactory { override fun get( diff --git a/datacapture/src/test/java/com/google/android/fhir/datacapture/QuestionnaireViewModelTest.kt b/datacapture/src/test/java/com/google/android/fhir/datacapture/QuestionnaireViewModelTest.kt index 5b69d9f85f..6f04e0048a 100644 --- a/datacapture/src/test/java/com/google/android/fhir/datacapture/QuestionnaireViewModelTest.kt +++ b/datacapture/src/test/java/com/google/android/fhir/datacapture/QuestionnaireViewModelTest.kt @@ -3193,9 +3193,38 @@ class QuestionnaireViewModelTest { } val viewModel = createQuestionnaireViewModel(questionnaire, showNavigationInLongScroll = true) val questionnaireState = viewModel.questionnaireStateFlow.first() - println(questionnaireState.items) + assertThat(questionnaireState.bottomNavItems.isEmpty()).isTrue() assertThat(questionnaireState.items.last()) .isInstanceOf(QuestionnaireAdapterItem.Navigation::class.java) + val navigationItem = questionnaireState.items.last() as QuestionnaireAdapterItem.Navigation + assertThat(navigationItem.questionnaireNavigationUIState.navSubmit.isEnabled).isTrue() + } + + fun `EXTRA_SHOW_NAVIGATION_IN_DEFAULT_LONG_SCROLL not setting should not add navigation item to questionnaireState items`() = + runTest { + val questionnaire = + Questionnaire().apply { + id = "a-questionnaire" + addItem( + Questionnaire.QuestionnaireItemComponent().apply { + linkId = "a-linkId" + type = Questionnaire.QuestionnaireItemType.BOOLEAN + }, + ) + } + val viewModel = createQuestionnaireViewModel(questionnaire) + val questionnaireState = viewModel.questionnaireStateFlow.first() + assertThat(questionnaireState.items.map { it::class.java }) + .doesNotContain(QuestionnaireAdapterItem.Navigation::class.java) + assertThat(questionnaireState.bottomNavItems.isNotEmpty()).isTrue() + assertThat( + questionnaireState.bottomNavItems + .single() + .questionnaireNavigationUIState + .navSubmit + .isEnabled, + ) + .isTrue() } // ==================================================================== //