Skip to content

Commit

Permalink
Add test for optionsfragment
Browse files Browse the repository at this point in the history
  • Loading branch information
subhajitxyz committed Jan 21, 2025
1 parent 20cb063 commit 9e24a44
Show file tree
Hide file tree
Showing 13 changed files with 89 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -438,7 +438,7 @@ class AdministratorControlsFragmentTest {
}

@Test
fun testFragmentArguments_afterCreation_areCorrect() {
fun testFragment_argumentsAreCorrect() {
launch<AdministratorControlsFragmentTestActivity>(
createAdministratorControlsFragmentTestActivityIntent(
profileId = internalProfileId
Expand All @@ -455,12 +455,11 @@ class AdministratorControlsFragmentTest {

val arguments = checkNotNull(administratorControlsFragment.arguments) {
"Expected arguments to be passed to AdministratorControlsFragment"
}
val args = arguments.getProto(
}.getProto(
ADMINISTRATOR_CONTROLS_FRAGMENT_ARGUMENTS_KEY,
AdministratorControlsFragmentArguments.getDefaultInstance()
)
val receivedIsMultipane = args.isMultipane
val receivedIsMultipane = arguments.isMultipane

assertThat(receivedIsMultipane).isEqualTo(isMultipane)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1651,7 +1651,7 @@ class RecentlyPlayedFragmentTest {
}

@Test
fun testFragmentArguments_afterCreation_areCorrect() {
fun testFragment_argumentsAreCorrect() {
ActivityScenario.launch<RecentlyPlayedActivity>(
createRecentlyPlayedActivityIntent(
internalProfileId = internalProfileId,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package org.oppia.android.app.options
import android.app.Application
import android.content.Context
import android.content.Intent
import android.widget.FrameLayout
import androidx.appcompat.app.AppCompatActivity
import androidx.drawerlayout.widget.DrawerLayout
import androidx.test.core.app.ActivityScenario
Expand All @@ -21,6 +22,7 @@ import androidx.test.espresso.matcher.ViewMatchers.withContentDescription
import androidx.test.espresso.matcher.ViewMatchers.withId
import androidx.test.espresso.matcher.ViewMatchers.withText
import androidx.test.ext.junit.runners.AndroidJUnit4
import com.google.common.truth.Truth.assertThat
import dagger.Component
import org.hamcrest.Matchers.allOf
import org.junit.After
Expand All @@ -44,6 +46,7 @@ import org.oppia.android.app.model.AppLanguageActivityParams
import org.oppia.android.app.model.AudioLanguage
import org.oppia.android.app.model.AudioLanguageActivityParams
import org.oppia.android.app.model.OppiaLanguage
import org.oppia.android.app.model.OptionsFragmentArguments
import org.oppia.android.app.model.ProfileId
import org.oppia.android.app.model.ReadingTextSize
import org.oppia.android.app.model.ReadingTextSizeActivityParams
Expand Down Expand Up @@ -99,6 +102,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.LoggerModule
Expand Down Expand Up @@ -559,6 +563,39 @@ class OptionsFragmentTest {
}
}

@Test
fun testFragment_argumentsAreCorrect() {
launch<OptionsActivity>(
createOptionActivityIntent(
internalProfileId = 0,
isFromNavigationDrawer = true
)
).use { scenario ->
testCoroutineDispatchers.runCurrent()
scenario.onActivity { activity ->

val optionsFragment = activity.supportFragmentManager
.findFragmentById(R.id.options_fragment_placeholder) as OptionsFragment

val args = optionsFragment.arguments?.getProto(
OPTIONS_FRAGMENT_ARGUMENTS_KEY,
OptionsFragmentArguments.getDefaultInstance()
)

val isMultipane =
activity.findViewById<FrameLayout>(R.id.multipane_options_container) != null

val receivedIsMultipane = args?.isMultipane
val receivedIsFirstOpen = args?.isFirstOpen
val receivedSelectedFragment = checkNotNull(args?.selectedFragment)

assertThat(receivedIsMultipane).isEqualTo(isMultipane)
assertThat(receivedIsFirstOpen).isEqualTo(true)
assertThat(receivedSelectedFragment).isEqualTo(READING_TEXT_SIZE_FRAGMENT)
}
}
}

private fun rotateToLandscape() {
onView(isRoot()).perform(orientationLandscape())
testCoroutineDispatchers.runCurrent()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5241,7 +5241,7 @@ class StateFragmentTest {
}

@Test
fun testFragmentArguments_afterCreation_areCorrect() {
fun testFragment_argumentsAreCorrect() {
setUpTestWithLanguageSwitchingFeatureOff()
launchForExploration(
FRACTIONS_EXPLORATION_ID_1,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -329,7 +329,7 @@ class PoliciesFragmentTest {
}

@Test
fun testFragmentArguments_afterCreation_areCorrect() {
fun testFragment_argumentsAreCorrect() {
launch<PoliciesFragmentTestActivity>(
createPoliciesFragmentTestIntent(
getApplicationContext(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -827,7 +827,7 @@ class ProfileProgressFragmentTest {
}

@Test
fun testFragmentArguments_afterCreation_areCorrect() {
fun testFragment_argumentsAreCorrect() {
launch<ProfileProgressActivity>(
createProfileProgressActivityIntent(internalProfileId)
).use { scenario ->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -321,7 +321,7 @@ class LicenseTextViewerFragmentTest {
}

@Test
fun testFragmentArguments_afterCreation_areCorrect() {
fun testFragment_argumentsAreCorrect() {
launch<LicenseTextViewerActivity>(
createLicenseTextViewerActivity(
dependencyIndex = 3,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -452,7 +452,7 @@ class TopicInfoFragmentTest {
}

@Test
fun testFragmentArguments_afterCreation_areCorrect() {
fun testFragment_argumentsAreCorrect() {
launchTopicActivityIntent(
profileId = profileId,
classroomId = TEST_CLASSROOM_ID,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1210,7 +1210,7 @@ class TopicLessonsFragmentTest {
}

@Test
fun testFragmentArguments_afterCreation_areCorrect() {
fun testFragment_argumentsAreCorrect() {
launch<TopicActivity>(
createTopicPlayStoryActivityIntent(
profileId,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -389,7 +389,7 @@ class TopicPracticeFragmentTest {
}

@Test
fun testFragmentArguments_afterCreation_areCorrect() {
fun testFragment_argumentsAreCorrect() {
launchTopicActivityIntent(
profileId = profileId,
classroomId = TEST_CLASSROOM_ID_1,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,7 @@ class TopicRevisionFragmentTest {
}

@Test
fun testFragmentArguments_afterCreation_areCorrect() {
fun testFragment_argumentsAreCorrect() {
launchTopicActivityIntent(
profileId = profileId,
classroomId = TEST_CLASSROOM_ID_1,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,7 @@ class WalkthroughFinalFragmentTest {
}

@Test
fun testFragmentArguments_afterCreation_areCorrect() {
fun testFragment_argumentsAreCorrect() {
launch<WalkthroughActivity>(createWalkthroughActivityIntent(0)).use { scenario ->
testCoroutineDispatchers.runCurrent()
scenario.onActivity { activity ->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package org.oppia.android.app.testing.options

import android.app.Application
import android.content.Intent
import android.widget.FrameLayout
import androidx.appcompat.app.AppCompatActivity
import androidx.test.core.app.ActivityScenario.launch
import androidx.test.core.app.ApplicationProvider
Expand All @@ -27,10 +28,14 @@ import org.oppia.android.app.application.ApplicationStartupListenerModule
import org.oppia.android.app.application.testing.TestingBuildFlavorModule
import org.oppia.android.app.devoptions.DeveloperOptionsModule
import org.oppia.android.app.devoptions.DeveloperOptionsStarterModule
import org.oppia.android.app.model.OptionsFragmentArguments
import org.oppia.android.app.model.ProfileId
import org.oppia.android.app.options.AppLanguageFragment
import org.oppia.android.app.options.AudioLanguageFragment
import org.oppia.android.app.options.OPTIONS_FRAGMENT_ARGUMENTS_KEY
import org.oppia.android.app.options.OptionsActivity
import org.oppia.android.app.options.OptionsFragment
import org.oppia.android.app.options.READING_TEXT_SIZE_FRAGMENT
import org.oppia.android.app.options.ReadingTextSizeFragment
import org.oppia.android.app.player.state.itemviewmodel.SplitScreenInteractionModule
import org.oppia.android.app.recyclerview.RecyclerViewMatcher.Companion.atPositionOnView
Expand Down Expand Up @@ -78,6 +83,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.LoggerModule
Expand Down Expand Up @@ -197,6 +203,39 @@ class OptionsFragmentTest {
}
}

@Test
fun testFragment_argumentsAreCorrect() {
launch<OptionsActivity>(
createOptionActivityIntent(
internalProfileId = 0,
isFromNavigationDrawer = true
)
).use { scenario ->
testCoroutineDispatchers.runCurrent()
scenario.onActivity { activity ->

val optionsFragment = activity.supportFragmentManager
.findFragmentById(R.id.options_fragment_placeholder) as OptionsFragment

val args = optionsFragment.arguments?.getProto(
OPTIONS_FRAGMENT_ARGUMENTS_KEY,
OptionsFragmentArguments.getDefaultInstance()
)

val isMultipane =
activity.findViewById<FrameLayout>(R.id.multipane_options_container) != null

val receivedIsMultipane = args?.isMultipane
val receivedIsFirstOpen = args?.isFirstOpen
val receivedSelectedFragment = checkNotNull(args?.selectedFragment)

assertThat(receivedIsMultipane).isEqualTo(isMultipane)
assertThat(receivedIsFirstOpen).isEqualTo(true)
assertThat(receivedSelectedFragment).isEqualTo(READING_TEXT_SIZE_FRAGMENT)
}
}
}

private fun createOptionActivityIntent(
internalProfileId: Int,
isFromNavigationDrawer: Boolean
Expand Down

0 comments on commit 9e24a44

Please sign in to comment.