Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/develop' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
subhajitxyz committed Sep 5, 2024
2 parents 52c6bb1 + 16082aa commit 773c810
Show file tree
Hide file tree
Showing 25 changed files with 541 additions and 32 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import org.oppia.android.app.model.HintsAndSolutionDialogFragmentStateBundle
import org.oppia.android.app.model.ProfileId
import org.oppia.android.app.model.State
import org.oppia.android.app.model.WrittenTranslationContext
import org.oppia.android.app.topic.conceptcard.ConceptCardFragment
import org.oppia.android.util.extensions.getProto
import org.oppia.android.util.extensions.putProto
import javax.inject.Inject
Expand Down Expand Up @@ -192,4 +193,12 @@ class HintsAndSolutionDialogFragment :
isSolutionRevealed
)
}

/**
* Delegates the removal of all [ConceptCardFragment] instances
* to the [hintsAndSolutionDialogFragmentPresenter].
*/
fun dismissConceptCard() {
hintsAndSolutionDialogFragmentPresenter.dismissConceptCard()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -331,4 +331,9 @@ class HintsAndSolutionDialogFragmentPresenter @Inject constructor(
override fun onConceptCardLinkClicked(view: View, skillId: String) {
ConceptCardFragment.bringToFrontOrCreateIfNew(skillId, profileId, fragment.childFragmentManager)
}

/** Removes all [ConceptCardFragment] in the given FragmentManager. */
fun dismissConceptCard() {
ConceptCardFragment.dismissAll(fragment.childFragmentManager)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@ class AppLanguageFragment : InjectableFragment(), AppLanguageRadioButtonListener
}
}

private fun Bundle.retrieveLanguageFromArguments(): OppiaLanguage {
/** Returns the [OppiaLanguage] stored in the fragment's arguments. */
fun Bundle.retrieveLanguageFromArguments(): OppiaLanguage {
return getProto(
FRAGMENT_ARGUMENTS_KEY, AppLanguageFragmentArguments.getDefaultInstance()
).oppiaLanguage
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,8 @@ class AudioLanguageFragment : InjectableFragment(), AudioLanguageRadioButtonList
}
}

private fun Bundle.retrieveLanguageFromArguments(): AudioLanguage {
/** Returns the [AudioLanguage] stored in the fragment's arguments. */
fun Bundle.retrieveLanguageFromArguments(): AudioLanguage {
return getProto(
FRAGMENT_ARGUMENTS_KEY, AudioLanguageFragmentArguments.getDefaultInstance()
).audioLanguage
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,9 @@ class ExplorationActivity :
this.writtenTranslationContext = writtenTranslationContext
}

override fun dismissConceptCard() = explorationActivityPresenter.dismissConceptCard()
override fun dismissConceptCard() {
getHintsAndSolution()?.dismissConceptCard()
}

override fun requestVoiceOverIconSpotlight(numberOfLogins: Int) {
explorationActivityPresenter.requestVoiceOverIconSpotlight(numberOfLogins)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -334,10 +334,6 @@ class ExplorationActivityPresenter @Inject constructor(
showDialogFragmentBasedOnCurrentCheckpointState()
}

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

private fun updateToolbarTitle(explorationId: String) {
subscribeToExploration(
explorationDataController.getExplorationById(profileId, explorationId).toLiveData()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,5 @@ class ExplorationFragment : InjectableFragment() {
explorationFragmentPresenter.viewSolution()
}

fun dismissConceptCard() = explorationFragmentPresenter.dismissConceptCard()

fun getExplorationCheckpointState() = explorationFragmentPresenter.getExplorationCheckpointState()
}
Original file line number Diff line number Diff line change
Expand Up @@ -141,8 +141,6 @@ class ExplorationFragmentPresenter @Inject constructor(
getStateFragment()?.viewSolution()
}

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

fun getExplorationCheckpointState() = getStateFragment()?.getExplorationCheckpointState()

private fun getStateFragment(): StateFragment? {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -162,8 +162,6 @@ class StateFragment :
stateFragmentPresenter.viewSolution()
}

fun dismissConceptCard() = stateFragmentPresenter.dismissConceptCard()

fun getExplorationCheckpointState() = stateFragmentPresenter.getExplorationCheckpointState()

override fun onSaveInstanceState(outState: Bundle) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ import org.oppia.android.app.player.state.listener.RouteToHintsAndSolutionListen
import org.oppia.android.app.player.stopplaying.StopStatePlayingSessionWithSavedProgressListener
import org.oppia.android.app.survey.SurveyWelcomeDialogFragment
import org.oppia.android.app.survey.TAG_SURVEY_WELCOME_DIALOG
import org.oppia.android.app.topic.conceptcard.ConceptCardFragment
import org.oppia.android.app.translation.AppLanguageResourceHandler
import org.oppia.android.app.utility.SplitScreenManager
import org.oppia.android.app.utility.lifecycle.LifecycleSafeTimerFactory
Expand Down Expand Up @@ -428,10 +427,6 @@ class StateFragmentPresenter @Inject constructor(
subscribeToAnswerOutcome(explorationProgressController.submitAnswer(answer).toLiveData())
}

fun dismissConceptCard() {
ConceptCardFragment.dismissAll(fragment.childFragmentManager)
}

private fun moveToNextState() {
stateViewModel.setCanSubmitAnswer(canSubmitAnswer = false)
explorationProgressController.moveToNextState().toLiveData().observe(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class ConceptCardFragmentTestActivity :
}

override fun dismissConceptCard() {
getConceptCardFragment()?.dismiss()
ConceptCardFragment.dismissAll(supportFragmentManager)
}

private fun getConceptCardFragment(): ConceptCardFragment? {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,9 @@ class QuestionPlayerActivityPresenter @Inject constructor(
getHintsAndSolutionDialogFragment()?.dismiss()
}

fun dismissConceptCard() = getQuestionPlayerFragment()?.dismissConceptCard()
fun dismissConceptCard() {
getHintsAndSolutionDialogFragment()?.dismissConceptCard()
}

private fun getHintsAndSolutionDialogFragment(): HintsAndSolutionDialogFragment? {
return activity.supportFragmentManager.findFragmentByTag(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,8 +106,6 @@ class QuestionPlayerFragment :
questionPlayerFragmentPresenter.revealSolution()
}

fun dismissConceptCard() = questionPlayerFragmentPresenter.dismissConceptCard()

companion object {

/** Arguments key for [QuestionPlayerFragment]. */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ import org.oppia.android.app.player.state.StatePlayerRecyclerViewAssembler
import org.oppia.android.app.player.state.listener.RouteToHintsAndSolutionListener
import org.oppia.android.app.player.stopplaying.RestartPlayingSessionListener
import org.oppia.android.app.player.stopplaying.StopStatePlayingSessionListener
import org.oppia.android.app.topic.conceptcard.ConceptCardFragment
import org.oppia.android.app.utility.FontScaleConfigurationUtil
import org.oppia.android.app.utility.SplitScreenManager
import org.oppia.android.databinding.QuestionPlayerFragmentBinding
Expand Down Expand Up @@ -124,10 +123,6 @@ class QuestionPlayerFragmentPresenter @Inject constructor(
subscribeToHintSolution(questionAssessmentProgressController.submitSolutionIsRevealed())
}

fun dismissConceptCard() {
ConceptCardFragment.dismissAll(fragment.childFragmentManager)
}

private fun retrieveArguments(): QuestionPlayerFragmentArguments {
return fragment.requireArguments().getProto(
QuestionPlayerFragment.ARGUMENTS_KEY, QuestionPlayerFragmentArguments.getDefaultInstance()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,10 @@ import org.oppia.android.app.application.ApplicationInjectorProvider
import org.oppia.android.app.application.ApplicationModule
import org.oppia.android.app.application.ApplicationStartupListenerModule
import org.oppia.android.app.application.testing.TestingBuildFlavorModule
import org.oppia.android.app.devoptions.markchapterscompleted.MarkChaptersCompletedFragment
import org.oppia.android.app.devoptions.markchapterscompleted.testing.MarkChaptersCompletedTestActivity
import org.oppia.android.app.model.ChapterPlayState
import org.oppia.android.app.model.MarkChaptersCompletedFragmentArguments
import org.oppia.android.app.model.ProfileId
import org.oppia.android.app.player.state.itemviewmodel.SplitScreenInteractionModule
import org.oppia.android.app.recyclerview.RecyclerViewMatcher.Companion.atPositionOnView
Expand Down Expand Up @@ -94,6 +96,7 @@ import org.oppia.android.testing.time.FakeOppiaClockModule
import org.oppia.android.util.accessibility.AccessibilityTestModule
import org.oppia.android.util.caching.AssetModule
import org.oppia.android.util.caching.testing.CachingTestModule
import org.oppia.android.util.extensions.getProto
import org.oppia.android.util.gcsresource.GcsResourceModule
import org.oppia.android.util.locale.LocaleProdModule
import org.oppia.android.util.logging.EventLoggingConfigurationModule
Expand Down Expand Up @@ -901,6 +904,70 @@ class MarkChaptersCompletedFragmentTest {
}
}

@Test
fun testFragment_fragmentLoaded_verifyCorrectArgumentsPassed() {
launchMarkChaptersCompletedFragmentTestActivity(
internalProfileId, showConfirmationNotice = true
).use { scenario ->
testCoroutineDispatchers.runCurrent()
scenario.onActivity { activity ->

val fragment = activity.supportFragmentManager
.findFragmentById(R.id.mark_chapters_completed_container) as MarkChaptersCompletedFragment
val arguments =
checkNotNull(fragment.arguments) {
"Expected arguments to be passed to MarkChaptersCompletedFragment"
}
val args = arguments.getProto(
"MarkChaptersCompletedFragment.arguments",
MarkChaptersCompletedFragmentArguments.getDefaultInstance()
)
val receivedInternalProfileId = args?.internalProfileId
val receivedShowConfirmationNotice = args?.showConfirmationNotice

assertThat(receivedInternalProfileId).isEqualTo(internalProfileId)
assertThat(receivedShowConfirmationNotice).isEqualTo(true)
}
}
}

@Test
fun testFragment_saveInstanceState_verifyCorrectStateRestored() {
launchMarkChaptersCompletedFragmentTestActivity(
internalProfileId, showConfirmationNotice = true
).use { scenario ->
testCoroutineDispatchers.runCurrent()
onView(withId(R.id.mark_chapters_completed_all_check_box_container)).perform(click())
var actualSelectedExplorationIds = ArrayList<String>()
var actualSelectedExplorationTitles = ArrayList<String>()

scenario.onActivity { activity ->
var fragment = activity.supportFragmentManager
.findFragmentById(R.id.mark_chapters_completed_container) as MarkChaptersCompletedFragment

actualSelectedExplorationIds =
fragment.markChaptersCompletedFragmentPresenter.serializableSelectedExplorationIds
actualSelectedExplorationTitles =
fragment.markChaptersCompletedFragmentPresenter.serializableSelectedExplorationTitles
}

scenario.recreate()

scenario.onActivity { activity ->
val newFragment = activity.supportFragmentManager
.findFragmentById(R.id.mark_chapters_completed_container) as MarkChaptersCompletedFragment

val receivedSelectedExplorationIds =
newFragment.markChaptersCompletedFragmentPresenter.serializableSelectedExplorationIds
val receivedSelectedExplorationTitles =
newFragment.markChaptersCompletedFragmentPresenter.serializableSelectedExplorationTitles

assertThat(receivedSelectedExplorationIds).isEqualTo(actualSelectedExplorationIds)
assertThat(receivedSelectedExplorationTitles).isEqualTo(actualSelectedExplorationTitles)
}
}
}

private fun launchMarkChaptersCompletedFragmentTestActivity(
internalProfileId: Int,
showConfirmationNotice: Boolean = false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ import org.oppia.android.app.application.ApplicationInjectorProvider
import org.oppia.android.app.application.ApplicationModule
import org.oppia.android.app.application.ApplicationStartupListenerModule
import org.oppia.android.app.application.testing.TestingBuildFlavorModule
import org.oppia.android.app.devoptions.markstoriescompleted.MarkStoriesCompletedFragment
import org.oppia.android.app.devoptions.markstoriescompleted.testing.MarkStoriesCompletedTestActivity
import org.oppia.android.app.model.ProfileId
import org.oppia.android.app.player.state.itemviewmodel.SplitScreenInteractionModule
Expand Down Expand Up @@ -99,6 +100,7 @@ import org.oppia.android.util.networking.NetworkConnectionUtilDebugModule
import org.oppia.android.util.parser.html.HtmlParserEntityTypeModule
import org.oppia.android.util.parser.image.GlideImageLoaderModule
import org.oppia.android.util.parser.image.ImageParsingModule
import org.oppia.android.util.profile.CurrentUserProfileIdIntentDecorator.extractCurrentUserProfileId
import org.robolectric.annotation.Config
import org.robolectric.annotation.LooperMode
import javax.inject.Inject
Expand Down Expand Up @@ -469,6 +471,58 @@ class MarkStoriesCompletedFragmentTest {
}
}

@Test
fun testFragment_fragmentLoaded_verifyCorrectArgumentsPassed() {
launch<MarkStoriesCompletedTestActivity>(
createMarkStoriesCompletedTestActivityIntent(internalProfileId)
).use { scenario ->
testCoroutineDispatchers.runCurrent()
scenario.onActivity { activity ->

val fragment = activity.supportFragmentManager
.findFragmentById(R.id.mark_stories_completed_container) as MarkStoriesCompletedFragment

val arguments =
checkNotNull(fragment.arguments) {
"Expected arguments to be passed to MarkStoriesCompletedFragment"
}
val profileId = arguments.extractCurrentUserProfileId()
val receivedInternalProfileId = profileId.internalId

assertThat(receivedInternalProfileId).isEqualTo(internalProfileId)
}
}
}

@Test
fun testFragment_saveInstanceState_verifyCorrectStateRestored() {
launch<MarkStoriesCompletedTestActivity>(
createMarkStoriesCompletedTestActivityIntent(internalProfileId)
).use { scenario ->
testCoroutineDispatchers.runCurrent()
onView(withId(R.id.mark_stories_completed_all_check_box_container)).perform(click())
var actualSelectedStoryIdList = ArrayList<String>()

scenario.onActivity { activity ->
var fragment = activity.supportFragmentManager
.findFragmentById(R.id.mark_stories_completed_container) as MarkStoriesCompletedFragment
actualSelectedStoryIdList =
fragment.markStoriesCompletedFragmentPresenter.selectedStoryIdList
}

scenario.recreate()

scenario.onActivity { activity ->
val newFragment = activity.supportFragmentManager
.findFragmentById(R.id.mark_stories_completed_container) as MarkStoriesCompletedFragment
val receivedSelectedStoryIdList =
newFragment.markStoriesCompletedFragmentPresenter.selectedStoryIdList

assertThat(receivedSelectedStoryIdList).isEqualTo(actualSelectedStoryIdList)
}
}
}

private fun createMarkStoriesCompletedTestActivityIntent(internalProfileId: Int): Intent {
return MarkStoriesCompletedTestActivity.createMarkStoriesCompletedTestIntent(
context, internalProfileId
Expand Down
Loading

0 comments on commit 773c810

Please sign in to comment.