From 499fde0a1cfc010893d94c2a879c6ad4505becd0 Mon Sep 17 00:00:00 2001 From: TanishMoral11 Date: Sat, 14 Dec 2024 21:39:42 +0530 Subject: [PATCH 1/3] fix: Enable submit button after linking items in Drag & Drop Sort Interaction --- .../DragAndDropSortInteractionViewModel.kt | 21 +++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/app/src/main/java/org/oppia/android/app/player/state/itemviewmodel/DragAndDropSortInteractionViewModel.kt b/app/src/main/java/org/oppia/android/app/player/state/itemviewmodel/DragAndDropSortInteractionViewModel.kt index 7abeb9fff1f..2daa6148499 100644 --- a/app/src/main/java/org/oppia/android/app/player/state/itemviewmodel/DragAndDropSortInteractionViewModel.kt +++ b/app/src/main/java/org/oppia/android/app/player/state/itemviewmodel/DragAndDropSortInteractionViewModel.kt @@ -219,8 +219,12 @@ class DragAndDropSortInteractionViewModel private constructor( dragDropInteractionContentViewModel.itemIndex = index dragDropInteractionContentViewModel.listSize = _choiceItems.size } - // to update the content of grouped item + + // To update the list (adapter as BindableAdapter<*>).setDataUnchecked(_choiceItems) + + // *Trigger pending answer check* to re-enable submit button + checkPendingAnswerError(AnswerErrorCategory.REAL_TIME) } fun unlinkElement(itemIndex: Int, adapter: RecyclerView.Adapter) { @@ -246,15 +250,24 @@ class DragAndDropSortInteractionViewModel private constructor( dragDropInteractionContentViewModel.itemIndex = index dragDropInteractionContentViewModel.listSize = _choiceItems.size } - // to update the list + + // *Update the list* (adapter as BindableAdapter<*>).setDataUnchecked(_choiceItems) + + // *Trigger pending answer check* to re-enable submit button + checkPendingAnswerError(AnswerErrorCategory.REAL_TIME) } private fun getSubmitTimeError(): DragAndDropSortInteractionError { - return if (_originalChoiceItems == _choiceItems) { + val hasItemsChanged = _originalChoiceItems.size != _choiceItems.size || + _originalChoiceItems.zip(_choiceItems).any { (originalItem, currentItem) -> + originalItem.htmlContent != currentItem.htmlContent + } + return if (!hasItemsChanged) { DragAndDropSortInteractionError.EMPTY_INPUT - } else + } else { DragAndDropSortInteractionError.VALID + } } /** Implementation of [StateItemViewModel.InteractionItemFactory] for this view model. */ From cbd7196d11403a59fc45ee6e64c5e0adf7c85461 Mon Sep 17 00:00:00 2001 From: TanishMoral11 Date: Tue, 17 Dec 2024 17:11:15 +0530 Subject: [PATCH 2/3] Resolved Issues --- .../DragAndDropSortInteractionViewModel.kt | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/app/src/main/java/org/oppia/android/app/player/state/itemviewmodel/DragAndDropSortInteractionViewModel.kt b/app/src/main/java/org/oppia/android/app/player/state/itemviewmodel/DragAndDropSortInteractionViewModel.kt index 2daa6148499..bb2fb2c63d1 100644 --- a/app/src/main/java/org/oppia/android/app/player/state/itemviewmodel/DragAndDropSortInteractionViewModel.kt +++ b/app/src/main/java/org/oppia/android/app/player/state/itemviewmodel/DragAndDropSortInteractionViewModel.kt @@ -223,7 +223,7 @@ class DragAndDropSortInteractionViewModel private constructor( // To update the list (adapter as BindableAdapter<*>).setDataUnchecked(_choiceItems) - // *Trigger pending answer check* to re-enable submit button + // Trigger pending answer check to re-enable submit button checkPendingAnswerError(AnswerErrorCategory.REAL_TIME) } @@ -251,19 +251,19 @@ class DragAndDropSortInteractionViewModel private constructor( dragDropInteractionContentViewModel.listSize = _choiceItems.size } - // *Update the list* + // Update the list (adapter as BindableAdapter<*>).setDataUnchecked(_choiceItems) - // *Trigger pending answer check* to re-enable submit button + // Trigger pending answer check* to re-enable submit button checkPendingAnswerError(AnswerErrorCategory.REAL_TIME) } private fun getSubmitTimeError(): DragAndDropSortInteractionError { - val hasItemsChanged = _originalChoiceItems.size != _choiceItems.size || + val haveItemsChanged = _originalChoiceItems.size != _choiceItems.size || _originalChoiceItems.zip(_choiceItems).any { (originalItem, currentItem) -> originalItem.htmlContent != currentItem.htmlContent } - return if (!hasItemsChanged) { + return if (!haveItemsChanged) { DragAndDropSortInteractionError.EMPTY_INPUT } else { DragAndDropSortInteractionError.VALID From aed480225a708f2033901a2a3bd74d7949b38ada Mon Sep 17 00:00:00 2001 From: TanishMoral11 Date: Wed, 18 Dec 2024 17:31:05 +0530 Subject: [PATCH 3/3] Added Test --- .../android/app/player/state/StateFragmentTest.kt | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/app/src/sharedTest/java/org/oppia/android/app/player/state/StateFragmentTest.kt b/app/src/sharedTest/java/org/oppia/android/app/player/state/StateFragmentTest.kt index b9aa97a1a1e..2637fdc90dc 100644 --- a/app/src/sharedTest/java/org/oppia/android/app/player/state/StateFragmentTest.kt +++ b/app/src/sharedTest/java/org/oppia/android/app/player/state/StateFragmentTest.kt @@ -1117,6 +1117,18 @@ class StateFragmentTest { } } + @Test + fun testStateFragment_loadDragDropExp_groupingItemsEnablesSubmitButton() { + setUpTestWithLanguageSwitchingFeatureOff() + launchForExploration(TEST_EXPLORATION_ID_4, shouldSavePartialProgress = false).use { + startPlayingExploration() + clickSubmitAnswerButton() + verifySubmitAnswerButtonIsDisabled() + mergeDragAndDropItems(position = 0) + verifySubmitAnswerButtonIsEnabled() + } + } + @Test @RunOn(TestPlatform.ESPRESSO) // TODO(#1612): Enable for Robolectric. fun testStateFragment_loadDragDropExp_retainStateOnConfigurationChange() {