Skip to content

Commit

Permalink
Fix #1273: Add tests for hints and solutions (#1276)
Browse files Browse the repository at this point in the history
* Initial check in for the question data controller

* Removed progress controller test

* Address the renames suggested in #217.

* Introduce thoroughly stubbed QuestionAssessmentProgressController +
empty test suite.

* Review changes

* Review changes

* Pass data providers to the assessment controller, and set caps in the training controller

* Removed unnecessary imports/variables

* Add fake question data for stubbed interfaces

* Remove duplicate questions while fetching in training controller

* Comment explaining the filter function

* Improve duplicate checking - check it while filtering instead of after filtering

* Add linked skill id values

* Review changes

* add a new module for questions constants

* Review changes

* add a test to verify questions were fetched properly

* reformatted code

* Re-add QuestionTrainingController removed in merge.

* Finalize question progress controller interface.

* Implement QuestionAssessmentProgressController.

This includes some basic refactoring of internal structures used by the
exploration progress controller to share common functionality between the
two progress controllers. There's still some duplication, but this seems
like a reasonable split since there's likely to be further differences in
the progress controllers in the future.

The question assessment progress controller tests pass, but no new ones
have yet been added to thoroughly test the implementation.

* Add initial phase of tests for the progress controller based on
ExplorationProgressController. They haven't yet been verified as correct.

* Fix typo in QuestionTrainingController.

* Post-merge fixes and adjustments.

* Fix broken ProfileManagementControllerTest.

* Post-merge fixes.

* Update tests to build, but not pass.

* Started UI

* setup ViewModel

* added binding adapter

* Handles basic functionality

* Moved code around

* Added replay button

* Make questions partially work.

This introduces back button behavior to ensure training sessions can be
reset.

This also attempts to introduce proper asset loading, but it doesn't
seem to be working currently.

* Temporarily remove check in StateDeck that breaks questions.

* Ensure all state navigation buttons are on the same line and the same
size.

This required reworking how nav button binding works in the state
fragment such that multiple models are used depending on which type of
navigation scenario the fragment is currently in.

* Fix dp adjustment that caused previous button to disappear.

Fix previous button showing up twice for continue interaction.

* Undo .idea/misc.xml change that snuck in.

* Update & fix StateFragmentTest (at least for Espresso). See #495 description
for details on the changes necessary to make these tests work.

* Post-merge fixes with some temporary stop-gap solutions.

* Fix questions image rendering and consolidate GCS resource bucket names.

* Fix question session not properly being reinitialized for new sessions.

Also, ensure that notifications do not regenerate the training session.

* Fix index accounting for questions. Before, the index incremented upon
correct answer submission rather than navigation.

* Remove support for backward navigation in questions since it isn't
allowed.

* Set title of question activity to 'Train Mode'.

* Add support for a synthetic ephemeral question to represent the end of a
training session.

* Update question progress tracking to be translatable and to ensure that
the synthetic terminal state shows the correct progress: 'completed'.

* Move most state player functional support into a new configurable
assembler class to enable sharing between the exploration and question
players.

* Hook up StatePlayerRecyclerViewAssembler to the question player fragment
presenter. This also enables the congratulations text.

* Introduce proper terminal page and disable overscroll. Note that the end
session page introduced here has not been mocked yet, so it's mostly a
placeholder until a mock is available.

* Add support & button for training session replay.

* Update/add TODOs to correspond to GitHub tracked issues.

* Fix broken import.

* Finish tests for Question{Training,AssessmentProgress}Controllers.

Note that the nature of the assessment progress controller is such that
a new, dynamic DataProvider is needed since the data provider for the
current assessment question is actually a transformation of different
data providers depending on which questions are passed to the
controller.

* Initial introduction of test coroutine dispatchers to replace Kotlin's
test coroutine dispatcher.

This includes introducing a test-only module to contain testing
dependencies.

* Introduce a new LiveData mechanism to bridge coroutines from
DataProviders in a way that doesn't have the same limitations as the
previous MutableLiveData-based bridge.

* Introduce new nested data provider that effectively allows a
DataProvider to be set up like transformAsync() but with the ability to
change the root DataProvider.

* question player progress-bar hifi

* nit

* revert

* revert

* Early work at introducing FakeSystemClock tests (not yet complete).

* Post-merge fixes.

* Fix the submit button disabled states: with the new refactor, the submit
button is now properly disabled when an invalid answer is pending.

* Revert accidental changes to .idea/misc.xml.

* Address reviewer comments.

* Remove unnecessary meta file for Mockito.

* Minor import cleanup.

* Post-merge fixes.

* Fix audio playback & generalize it to facilitate enabling it for
questions in the future.

* Address reviewer comments & fix broken tests.

* Fix hints & solutions functionality after simplification (some bugs &
regressions were introduced due to the simplification; these have been
fixed).

* Revert the assembler delays to match the intended durations rather than
the test-only values used for development.

* Address reviewer comments.

* Remove infeasible testing structures, add documentation, and clean up
implementation to prepare for code review.

* Add notice that the dispatchers utility is temporary.

* Cleanup new LiveData bridge, add tests for it, and migrate other
DataProviders tests to using TestCoroutineDispatchers utility.

* Add AsyncResult tests, fix & re-enable an earlier test in PersistentCacheStoreTest, and fix FakeSystemClock so that it works properly in test environments.

* Use ktlint to reformat TestCoroutineDispatchers per reviewer comment
thread.

* Reformat files failing linter check.

* Reformat new DataProviders code.

* Add new tests for the NestedTransformedDataProvider.

* Address reviewer comment.

* Address reviewer comments.

* Address reviewer comments & fix lint issue.

* Update hints & solutions handling to more closely follow the intended
behavior graph (and added an actual visual representation of this graph
in code to simplify maintaining the solution in the future). Tests will
be added as part of solving #1273.

* Add support for sharing the test application component between UI
dependencies and tests. Also, fix the test coroutine dispatcher to
properly manage time in tests. This enables the test coroutine
dispatcher for app module tests.

* Clean up the documentation for test utilities.

* Add tests for hints & solutions. These are Robolectric-only tests since
we need to carefully coordinate timing and very quickly drive through a
bunch of different UI screens.

* Address reviewer comment.

* Address reviewer comments & fix broken tests after merging in develop.

* Post-merge fixes.

* Fix linter errors.
  • Loading branch information
BenHenning authored Jul 17, 2020
1 parent 5794fe5 commit abdc31b
Show file tree
Hide file tree
Showing 7 changed files with 1,181 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import org.oppia.util.parser.HtmlParser

// TODO(#216): Make use of generic data-binding-enabled RecyclerView adapter.

private const val TAG_REVEAL_SOLUTION_DIALOG = "REVEAL_SOLUTION_DIALOG"
const val TAG_REVEAL_SOLUTION_DIALOG = "REVEAL_SOLUTION_DIALOG"
private const val VIEW_TYPE_HINT_ITEM = 1
private const val VIEW_TYPE_SOLUTION_ITEM = 2

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1099,7 +1099,6 @@ class StatePlayerRecyclerViewAssembler private constructor(
}
}

// TODO(#1273): Add thorough testing for hints & solutions.
/**
* Handler for showing hints to the learner after a period of time in the event they submit a
* wrong answer.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,15 @@ import android.content.Context
import android.content.Intent
import android.os.Bundle
import org.oppia.app.activity.InjectableAppCompatActivity
import org.oppia.app.hintsandsolution.HintsAndSolutionDialogFragment
import org.oppia.app.hintsandsolution.HintsAndSolutionListener
import org.oppia.app.hintsandsolution.RevealHintListener
import org.oppia.app.hintsandsolution.RevealSolutionInterface
import org.oppia.app.model.HelpIndex
import org.oppia.app.model.State
import org.oppia.app.player.audio.AudioButtonListener
import org.oppia.app.player.exploration.HintsAndSolutionExplorationManagerListener
import org.oppia.app.player.exploration.TAG_HINTS_AND_SOLUTION_DIALOG
import org.oppia.app.player.state.listener.RouteToHintsAndSolutionListener
import org.oppia.app.player.state.listener.ShowHintAvailabilityListener
import org.oppia.app.player.state.listener.StateKeyboardButtonListener
import org.oppia.app.player.stopplaying.StopStatePlayingSessionListener
import javax.inject.Inject
Expand All @@ -30,8 +32,9 @@ class StateFragmentTestActivity :
RouteToHintsAndSolutionListener,
RevealHintListener,
RevealSolutionInterface,
ShowHintAvailabilityListener {
HintsAndSolutionExplorationManagerListener {
@Inject lateinit var stateFragmentTestActivityPresenter: StateFragmentTestActivityPresenter
private lateinit var state: State

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
Expand Down Expand Up @@ -80,11 +83,34 @@ class StateFragmentTestActivity :
explorationId: String,
newAvailableHintIndex: Int,
allHintsExhausted: Boolean
) {}
) {
if (getHintsAndSolution() == null) {
val hintsAndSolutionFragment =
HintsAndSolutionDialogFragment.newInstance(
explorationId,
newAvailableHintIndex,
allHintsExhausted
)
hintsAndSolutionFragment.loadState(state)
hintsAndSolutionFragment.showNow(supportFragmentManager, TAG_HINTS_AND_SOLUTION_DIALOG)
}
}

override fun revealHint(saveUserChoice: Boolean, hintIndex: Int) {}
override fun revealHint(saveUserChoice: Boolean, hintIndex: Int) {
stateFragmentTestActivityPresenter.revealHint(saveUserChoice, hintIndex)
}

override fun revealSolution(saveUserChoice: Boolean) {}
override fun revealSolution(saveUserChoice: Boolean) {
stateFragmentTestActivityPresenter.revealSolution(saveUserChoice)
}

override fun onHintAvailable(helpIndex: HelpIndex) {}
override fun onExplorationStateLoaded(state: State) {
this.state = state
}

private fun getHintsAndSolution(): HintsAndSolutionDialogFragment? {
return supportFragmentManager.findFragmentByTag(
TAG_HINTS_AND_SOLUTION_DIALOG
) as HintsAndSolutionDialogFragment?
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import androidx.lifecycle.Observer
import org.oppia.app.R
import org.oppia.app.activity.ActivityScope
import org.oppia.app.databinding.StateFragmentTestActivityBinding
import org.oppia.app.player.exploration.HintsAndSolutionExplorationManagerFragment
import org.oppia.app.player.exploration.TAG_HINTS_AND_SOLUTION_EXPLORATION_MANAGER
import org.oppia.app.player.state.StateFragment
import org.oppia.app.viewmodel.ViewModelProvider
import org.oppia.domain.exploration.ExplorationDataController
Expand Down Expand Up @@ -45,12 +47,25 @@ class StateFragmentTestActivityPresenter @Inject constructor(
activity.findViewById<Button>(R.id.play_test_exploration_button)?.setOnClickListener {
startPlayingExploration(profileId, topicId, storyId, explorationId)
}

if (getHintsAndSolutionManagerFragment() == null) {
activity.supportFragmentManager.beginTransaction().add(
R.id.exploration_fragment_placeholder,
HintsAndSolutionExplorationManagerFragment(),
TAG_HINTS_AND_SOLUTION_EXPLORATION_MANAGER
).commitNow()
}
}

fun stopExploration() = finishExploration()

fun scrollToTop() = getStateFragment()?.scrollToTop()

fun revealHint(saveUserChoice: Boolean, hintIndex: Int) =
getStateFragment()?.revealHint(saveUserChoice, hintIndex)

fun revealSolution(saveUserChoice: Boolean) = getStateFragment()?.revealSolution(saveUserChoice)

private fun startPlayingExploration(
profileId: Int,
topicId: String,
Expand Down Expand Up @@ -109,6 +124,12 @@ class StateFragmentTestActivityPresenter @Inject constructor(
) as? StateFragment
}

private fun getHintsAndSolutionManagerFragment(): HintsAndSolutionExplorationManagerFragment? {
return activity.supportFragmentManager.findFragmentByTag(
TAG_HINTS_AND_SOLUTION_EXPLORATION_MANAGER
) as HintsAndSolutionExplorationManagerFragment?
}

private fun getStateFragmentTestViewModel(): StateFragmentTestViewModel {
return viewModelProvider.getForActivity(activity, StateFragmentTestViewModel::class.java)
}
Expand Down
6 changes: 0 additions & 6 deletions app/src/main/res/layout/state_fragment.xml
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,6 @@
android:visibility="@{viewModel.isAudioBarVisible ? View.VISIBLE : View.GONE}" />
</FrameLayout>

<FrameLayout
android:id="@+id/hints_and_solution_fragment_placeholder"
android:layout_width="match_parent"
android:layout_height="match_parent">
</FrameLayout>

<FrameLayout
android:id="@+id/hints_and_solution_fragment_container"
android:layout_width="wrap_content"
Expand Down
5 changes: 5 additions & 0 deletions app/src/main/res/layout/state_fragment_test_activity.xml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,11 @@
android:layout_width="match_parent"
android:layout_height="match_parent" />

<FrameLayout
android:id="@+id/exploration_fragment_placeholder"
android:layout_width="match_parent"
android:layout_height="match_parent" />

<Button
android:id="@+id/play_test_exploration_button"
android:layout_width="wrap_content"
Expand Down
Loading

0 comments on commit abdc31b

Please sign in to comment.