Skip to content

Commit

Permalink
Fix oppia#387, oppia#1771: Show concept cards (oppia#1637)
Browse files Browse the repository at this point in the history
* Add support for showing concept cards in feedback, and add a concept
card as one of the remediation pathways for 'the meaning of equal parts'
lesson.

* Introduce test coroutine dispatchers support in Espresso.

This piggybacks off of the solution introduced in oppia#1276 for Robolectric.
That PR allows Robolectric tests in app module to share dependencies
with production components by creating a test application & telling
Robolectric to use it instead of OppiaApplication via a @config
annotation.

This PR achieves the same thing by using a custom test runner that reads
the same annotation and forces Espresso & instrumentation to use the
test application instead of the default OppiaApplication. This setup
will be easier once oppia#59 is finished since we can specify the application
in per-test manifests that both Robolectric & Espresso will respect.

Note that while this lets the same test coroutine dispatchers work in
both production & test code for Espresso, some additional work was
needed to ensure the coroutines behave correctly. In particular, the
coroutines use a fake system clock in Robolectric that requires explicit
synchronization points in the tests to allow the clock to move forward
& properly coordinate execution between background & main thread
operations. However, in Espresso, since everything is using a real clock
an idling resource is the preferred way to synchronize execution: it
allows the background coroutines to operate in real-time much like they
would in production, and then notify Espresso when completed. The test
dispatchers API is now setup to support both synchronization mechanisms
for both Robolectric & Espresso (the idling resource does nothing on
Robolectric and the force synchronization effectively does nothing on
Espresso).

The first test being demonstrated as now stable is SplashActivityTest
(as part of downstream work in oppia#1397.

* Revert "Fixes oppia#941: Add radar effect in Hints and solution (oppia#1475)"

This reverts commit 41eb10b.

* Stabilize StateFragmentTest such that it passes on both Robolectric and
Espresso.

Note that some issues were found during this: oppia#1612 (oppia#1611 was found a
few weeks ago, but it also affects these tests). To ensure the tests can
still be run, a @runon annotation was added to allow tests to target
specific test platforms. The tests that currently fail on Robolectric
due to oppia#1611 and oppia#1612 are disabled for that platform. The test suite as
a whole has been verified to pass in its current state on both
Robolectric and Espresso (on a Pixel XL).

The aim of this PR is to actually enable critical state fragment tests
in CI, so both StateFragmentTest and StateFragmentLocalTest are being
enabled in GitHub actions.

* Enable StateFragmentTest (Robolectric) & StateFragmentLocalTest for CI.

* Add thorough documentation for new dispatchers.

* Clean up comments & add additional documentation.

* Fix lint errors.

* Fix broken test after changes to FakeSystemClock.

* Fix linter errors.

* Update test lesson to include references to concept cards.

* Lint fixes & use HtmlCompat instead of Html.

* Add support for the newer & finalized tag format.

* Lint fixes.

* Use a custom executor service for Glide requests that coordinates with
Oppia's test dispatchers. Note that this does not actually introduce the
service--that will happen in a new branch.

* Introduce new executor service which allows interop with Kotlin
coroutines, plus a test to verify that it fundamentally follows one
interpretation of ExecutorService's API.

* Fix flaky timeout tests by improving cancellation cooperation for
invokeAny() and provide longer timeouts for tests that are
CPU-sensitive.

* Add documentation & clean up unused code.

* Lint fixes.

* Significantly reorganize invokeAll() to try and make it more cooperative
for cancellation, and increase timeout times in tests to reduce
flakiness for time-sensitive tests. Some tests are remaining flaky, so
ignoring those.

Re-add maybeWithTimeoutOrNull since it actually was needed.

* Lint fixes.

* Post-merge module fixes.

* Post-merge fixes with ratio input & add a TODO to improve speed of the
new coroutine executor service.

* Revert "Fixes part of oppia#40 & oppia#42: Generalisation Highfi Mobile Portrait + Landscape - Buttons (oppia#1653)"

This reverts commit 1bb1ffa.

* Ensure terminated tasks do not interfere with one another (timeouts
should happen individually for each task during termination). This fixes
a failure observed in StateFragmentLocalTest in oppia#1630.

* Ignore failing tests until oppia#1769 is resolved.

* Fix awaitTermination & improve test. Improve stack trace for test
dispatcher timeouts.

* Fix slow & broken tests in Robolectric for StateFragmentLocalTest.

* Add missing deps for StateFragmentLocalTest.

* Address TODOs (including adding support for list tags which replaces the
old handler & adds nested custom tag support), and add tests.

* Lint fixes.

* Address reviewer comments.

* Address review comments. Fix new concept card tests on Espresso & add
landscape versions (required configuring hints to show quickly to avoid
delaying the test, and fixing a bug in the espresso test dispatcher).
Add support for disabling concept cards of they aren't enabled for
parsing particular HTML (the default behavior is to ignore the custom
tag).

* Add support for concept cards in questions. Note that it's not clear how
to test verifying that pressing the exit button closes the concept card
since the exit button is part of the dialog's toolbar.

* Fix image-breaking duplicated code in HtmlParser, fix a paragraph
parsing issue in BulletTagHandler, and add tests for
CustomHtmlContentHandler.

* Lint fixes.
  • Loading branch information
BenHenning authored and prayutsu committed Sep 3, 2020
1 parent fdff618 commit e35f2a4
Show file tree
Hide file tree
Showing 48 changed files with 1,299 additions and 177 deletions.
3 changes: 2 additions & 1 deletion app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -105,8 +105,8 @@ dependencies {
'androidx.test.espresso:espresso-core:3.2.0',
'androidx.test.espresso:espresso-intents:3.1.0',
'androidx.test.ext:junit:1.1.1',
'com.google.truth:truth:0.43',
'com.github.bumptech.glide:mocks:4.11.0',
'com.google.truth:truth:0.43',
'org.robolectric:annotations:4.3',
'org.robolectric:robolectric:4.3',
'org.jetbrains.kotlinx:kotlinx-coroutines-test:1.2.2',
Expand All @@ -121,6 +121,7 @@ dependencies {
'androidx.test.espresso:espresso-core:3.2.0',
'androidx.test.espresso:espresso-intents:3.1.0',
'androidx.test.ext:junit:1.1.1',
'com.github.bumptech.glide:mocks:4.11.0',
'com.google.truth:truth:0.43',
'org.jetbrains.kotlinx:kotlinx-coroutines-test:1.2.2',
'org.mockito:mockito-android:2.7.22',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import android.app.Application
import dagger.BindsInstance
import dagger.Component
import org.oppia.app.activity.ActivityComponent
import org.oppia.app.player.state.hintsandsolution.HintsAndSolutionConfigModule
import org.oppia.app.shim.IntentFactoryShimModule
import org.oppia.app.shim.ViewBindingShimModule
import org.oppia.domain.classify.InteractionsModule
Expand Down Expand Up @@ -57,7 +58,8 @@ import javax.inject.Singleton
LogStorageModule::class, IntentFactoryShimModule::class,
ViewBindingShimModule::class, PrimeTopicAssetsControllerModule::class,
ExpirationMetaDataRetrieverModule::class, RatioInputModule::class,
UncaughtExceptionLoggerModule::class, ApplicationStartupListenerModule::class
UncaughtExceptionLoggerModule::class, ApplicationStartupListenerModule::class,
HintsAndSolutionConfigModule::class
]
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import org.oppia.app.player.state.listener.RouteToHintsAndSolutionListener
import org.oppia.app.player.state.listener.StateKeyboardButtonListener
import org.oppia.app.player.stopplaying.StopExplorationDialogFragment
import org.oppia.app.player.stopplaying.StopStatePlayingSessionListener
import org.oppia.app.topic.conceptcard.ConceptCardListener
import javax.inject.Inject

private const val TAG_STOP_EXPLORATION_DIALOG = "STOP_EXPLORATION_DIALOG"
Expand All @@ -34,7 +35,8 @@ class ExplorationActivity :
RevealHintListener,
RevealSolutionInterface,
DefaultFontSizeStateListener,
HintsAndSolutionExplorationManagerListener {
HintsAndSolutionExplorationManagerListener,
ConceptCardListener {

@Inject
lateinit var explorationActivityPresenter: ExplorationActivityPresenter
Expand Down Expand Up @@ -181,4 +183,6 @@ class ExplorationActivity :
override fun onExplorationStateLoaded(state: State) {
this.state = state
}

override fun dismissConceptCard() = explorationActivityPresenter.dismissConceptCard()
}
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,10 @@ class ExplorationActivityPresenter @Inject constructor(
}
}

fun dismissConceptCard() {
getExplorationFragment()?.dismissConceptCard()
}

private fun updateToolbarTitle(explorationId: String) {
subscribeToExploration(explorationDataController.getExplorationById(explorationId))
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,4 +107,6 @@ class ExplorationFragment : InjectableFragment() {
fun revealSolution(saveUserChoice: Boolean) {
explorationFragmentPresenter.revealSolution(saveUserChoice)
}

fun dismissConceptCard() = explorationFragmentPresenter.dismissConceptCard()
}
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@ class ExplorationFragmentPresenter @Inject constructor(
getStateFragment()?.revealSolution(saveUserChoice)
}

fun dismissConceptCard() = getStateFragment()?.dismissConceptCard()

private fun getStateFragment(): StateFragment? {
return fragment
.childFragmentManager
Expand Down
2 changes: 2 additions & 0 deletions app/src/main/java/org/oppia/app/player/state/StateFragment.kt
Original file line number Diff line number Diff line change
Expand Up @@ -129,4 +129,6 @@ class StateFragment :
fun revealSolution(saveUserChoice: Boolean) {
stateFragmentPresenter.revealSolution(saveUserChoice)
}

fun dismissConceptCard() = stateFragmentPresenter.dismissConceptCard()
}
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,9 @@ class StateFragmentPresenter @Inject constructor(
.addAudioVoiceoverSupport(
explorationId, viewModel.currentStateName, viewModel.isAudioBarVisible,
this::getAudioUiManager
).build()
)
.addConceptCardSupport()
.build()
}

fun revealHint(saveUserChoice: Boolean, hintIndex: Int) {
Expand Down Expand Up @@ -461,6 +463,14 @@ class StateFragmentPresenter @Inject constructor(
subscribeToAnswerOutcome(explorationProgressController.submitAnswer(answer))
}

fun dismissConceptCard() {
fragment.childFragmentManager.findFragmentByTag(
CONCEPT_CARD_DIALOG_FRAGMENT_TAG
)?.let { dialogFragment ->
fragment.childFragmentManager.beginTransaction().remove(dialogFragment).commitNow()
}
}

private fun moveToNextState() {
viewModel.setCanSubmitAnswer(canSubmitAnswer = false)
explorationProgressController.moveToNextState().observe(
Expand All @@ -487,8 +497,6 @@ class StateFragmentPresenter @Inject constructor(
binding.stateRecyclerView.smoothScrollToPosition(0)
}

private fun isAudioShowing(): Boolean = viewModel.isAudioBarVisible.get()!!

/** Updates submit button UI as active if pendingAnswerError null else inactive. */
fun updateSubmitButton(pendingAnswerError: String?, inputAnswerAvailable: Boolean) {
if (inputAnswerAvailable) {
Expand Down
Loading

0 comments on commit e35f2a4

Please sign in to comment.