Skip to content

Commit

Permalink
Improving Formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
TanishMoral11 committed Dec 3, 2024
1 parent 233d71d commit cde7984
Show file tree
Hide file tree
Showing 3 changed files with 96 additions and 84 deletions.
4 changes: 1 addition & 3 deletions .idea/codeStyles/Project.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,8 @@ class AudioViewModel @Inject constructor(
selectedLanguageName.set(locale.getDisplayLanguage(locale))

when {
selectedLanguageCode.isEmpty() && languages.contains(defaultLanguage) -> setAudioLanguageCode(defaultLanguage)
selectedLanguageCode.isEmpty() && languages.contains(defaultLanguage) ->
setAudioLanguageCode(defaultLanguage)
languages.contains(selectedLanguageCode) -> setAudioLanguageCode(selectedLanguageCode)
languages.isNotEmpty() -> {
autoPlay = false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import androidx.test.ext.junit.runners.AndroidJUnit4
import com.google.common.truth.Truth.assertThat
import dagger.Component
import java.util.concurrent.TimeoutException
import org.hamcrest.CoreMatchers.allOf
import org.hamcrest.Description
import org.hamcrest.Matcher
import org.hamcrest.TypeSafeMatcher
Expand Down Expand Up @@ -131,8 +132,7 @@ import org.hamcrest.CoreMatchers.allOf
@RunWith(AndroidJUnit4::class)
@LooperMode(LooperMode.Mode.PAUSED)
@Config(
application = AudioFragmentTest.TestApplication::class,
qualifiers = "port-xxhdpi"
application = AudioFragmentTest.TestApplication::class, qualifiers = "port-xxhdpi"
)
class AudioFragmentTest {
@get:Rule
Expand All @@ -158,11 +158,9 @@ class AudioFragmentTest {
private lateinit var shadowMediaPlayer: Any

private val TEST_URL =
"https://storage.googleapis.com/oppiaserver-resources/exploration/" +
"2mzzFVDLuAj8/assets/audio/content-en-057j51i2es.mp3"
"https://storage.googleapis.com/oppiaserver-resources/exploration/" + "2mzzFVDLuAj8/assets/audio/content-en-057j51i2es.mp3"
private val TEST_URL2 =
"https://storage.googleapis.com/oppiaserver-resources/exploration/" +
"2mzzFVDLuAj8/assets/audio/content-hi-2hn6btuei5.mp3"
"https://storage.googleapis.com/oppiaserver-resources/exploration/" + "2mzzFVDLuAj8/assets/audio/content-hi-2hn6btuei5.mp3"

private var internalProfileId = 0
private var profileId = ProfileId.newBuilder().setInternalId(internalProfileId).build()
Expand All @@ -180,8 +178,7 @@ class AudioFragmentTest {

private fun createAudioFragmentTestIntent(profileId: Int): Intent {
return AudioFragmentTestActivity.createAudioFragmentTestActivity(
context,
profileId
context, profileId
)
}

Expand All @@ -194,14 +191,13 @@ class AudioFragmentTest {
)
).use {
testCoroutineDispatchers.runCurrent()
onView(withId(R.id.audio_progress_seek_bar))
.check(
matches(
withContentDescription(
context.getString(R.string.audio_player_seekbar_content_description)
)
onView(withId(R.id.audio_progress_seek_bar)).check(
matches(
withContentDescription(
context.getString(R.string.audio_player_seekbar_content_description)
)
)
)
}
}

Expand All @@ -214,14 +210,13 @@ class AudioFragmentTest {
)
).use {
testCoroutineDispatchers.runCurrent()
onView(withId(R.id.audio_language_icon))
.check(
matches(
withContentDescription(
context.getString(R.string.audio_language_icon_content_description)
)
onView(withId(R.id.audio_language_icon)).check(
matches(
withContentDescription(
context.getString(R.string.audio_language_icon_content_description)
)
)
)
}
}

Expand All @@ -235,16 +230,27 @@ class AudioFragmentTest {
).use {
testCoroutineDispatchers.runCurrent()

waitForTheView(allOf(withId(R.id.play_pause_audio_icon), WithNonZeroDimensionsMatcher()))
.perform(click())
waitForTheView(
allOf(
withId(R.id.play_pause_audio_icon),
WithNonZeroDimensionsMatcher()
)
).perform(click())
testCoroutineDispatchers.runCurrent()

onView(withId(R.id.audio_progress_seek_bar)).perform(setProgress(100))

onView(isRoot()).perform(orientationLandscape())
testCoroutineDispatchers.runCurrent()
onView(withId(R.id.play_pause_audio_icon))
.check(matches(withContentDescription(context.getString(R.string.audio_play_description))))
onView(withId(R.id.play_pause_audio_icon)).check(
matches(
withContentDescription(
context.getString(
R.string.audio_play_description
)
)
)
)
}
}

Expand Down Expand Up @@ -290,11 +296,8 @@ class AudioFragmentTest {
} while (System.currentTimeMillis() < endTime)

// Couldn't match in time.
throw PerformException.Builder()
.withActionDescription(description)
.withViewDescription(HumanReadables.describe(view))
.withCause(TimeoutException())
.build()
throw PerformException.Builder().withActionDescription(description)
.withViewDescription(HumanReadables.describe(view)).withCause(TimeoutException()).build()
}
}
}
Expand All @@ -308,10 +311,16 @@ class AudioFragmentTest {
)
).use {
testCoroutineDispatchers.runCurrent()
onView(withId(R.id.play_pause_audio_icon))
.check(matches(isDisplayed()))
onView(withId(R.id.play_pause_audio_icon))
.check(matches(withContentDescription(context.getString(R.string.audio_play_description))))
onView(withId(R.id.play_pause_audio_icon)).check(matches(isDisplayed()))
onView(withId(R.id.play_pause_audio_icon)).check(
matches(
withContentDescription(
context.getString(
R.string.audio_play_description
)
)
)
)
}
}

Expand All @@ -330,8 +339,15 @@ class AudioFragmentTest {
onView(withId(R.id.play_pause_audio_icon)).perform(click())

testCoroutineDispatchers.runCurrent()
onView(withId(R.id.play_pause_audio_icon))
.check(matches(withContentDescription(context.getString(R.string.audio_pause_description))))
onView(withId(R.id.play_pause_audio_icon)).check(
matches(
withContentDescription(
context.getString(
R.string.audio_pause_description
)
)
)
)
}
}

Expand All @@ -348,8 +364,15 @@ class AudioFragmentTest {
onView(withId(R.id.audio_progress_seek_bar)).perform(setProgress(100))

testCoroutineDispatchers.runCurrent()
onView(withId(R.id.play_pause_audio_icon))
.check(matches(withContentDescription(context.getString(R.string.audio_play_description))))
onView(withId(R.id.play_pause_audio_icon)).check(
matches(
withContentDescription(
context.getString(
R.string.audio_play_description
)
)
)
)
}
}

Expand All @@ -370,8 +393,15 @@ class AudioFragmentTest {
onView(withId(R.id.audio_progress_seek_bar)).perform(setProgress(100))

testCoroutineDispatchers.runCurrent()
onView(withId(R.id.play_pause_audio_icon))
.check(matches(withContentDescription(context.getString(R.string.audio_pause_description))))
onView(withId(R.id.play_pause_audio_icon)).check(
matches(
withContentDescription(
context.getString(
R.string.audio_pause_description
)
)
)
)
}
}

Expand All @@ -387,8 +417,15 @@ class AudioFragmentTest {
onView(withId(R.id.play_pause_audio_icon)).perform(click())
onView(withId(R.id.audio_progress_seek_bar)).perform(setProgress(100))
onView(isRoot()).perform(orientationLandscape())
onView(withId(R.id.play_pause_audio_icon))
.check(matches(withContentDescription(context.getString(R.string.audio_pause_description))))
onView(withId(R.id.play_pause_audio_icon)).check(
matches(
withContentDescription(
context.getString(
R.string.audio_pause_description
)
)
)
)
}
}

Expand All @@ -410,16 +447,22 @@ class AudioFragmentTest {
onView(withId(R.id.audio_language_icon)).perform(click())

testCoroutineDispatchers.runCurrent()
onView(withText(R.string.hinglish_localized_language_name))
.inRoot(isDialog())
onView(withText(R.string.hinglish_localized_language_name)).inRoot(isDialog())
.perform(click())

testCoroutineDispatchers.runCurrent()
onView(withText("Ok")).inRoot(isDialog()).perform(click())

testCoroutineDispatchers.runCurrent()
onView(withId(R.id.play_pause_audio_icon))
.check(matches(withContentDescription(context.getString(R.string.audio_play_description))))
onView(withId(R.id.play_pause_audio_icon)).check(
matches(
withContentDescription(
context.getString(
R.string.audio_play_description
)
)
)
)
onView(withId(R.id.audio_progress_seek_bar)).check(matches(withSeekBarPosition(0)))
}
}
Expand All @@ -433,8 +476,8 @@ class AudioFragmentTest {
testCoroutineDispatchers.runCurrent()
scenario.onActivity { activity ->

val audioFragment = activity.supportFragmentManager
.findFragmentById(R.id.audio_fragment_placeholder) as AudioFragment
val audioFragment =
activity.supportFragmentManager.findFragmentById(R.id.audio_fragment_placeholder) as AudioFragment
val receivedProfileId = audioFragment.arguments?.extractCurrentUserProfileId()

assertThat(receivedProfileId).isEqualTo(profileId)
Expand Down Expand Up @@ -476,9 +519,7 @@ class AudioFragmentTest {
if (isOnRobolectric()) {
val dataSource = toDataSource(context, Uri.parse(TEST_URL))
val dataSource2 = toDataSource(context, Uri.parse(TEST_URL2))
val mediaInfo = createMediaInfo(
/* duration= */ 1000,
/* preparationDelay= */ 0
val mediaInfo = createMediaInfo(/* duration= */ 1000,/* preparationDelay= */ 0
)
addMediaInfo(dataSource, mediaInfo)
addMediaInfo(dataSource2, mediaInfo)
Expand Down Expand Up @@ -560,34 +601,7 @@ class AudioFragmentTest {
// TODO(#59): Figure out a way to reuse modules instead of needing to re-declare them.
@Singleton
@Component(
modules = [
RobolectricModule::class,
PlatformParameterModule::class, PlatformParameterSingletonModule::class,
TestDispatcherModule::class, ApplicationModule::class,
LoggerModule::class, ContinueModule::class, FractionInputModule::class,
ItemSelectionInputModule::class, MultipleChoiceInputModule::class,
NumberWithUnitsRuleModule::class, NumericInputRuleModule::class, TextInputRuleModule::class,
DragDropSortInputModule::class, ImageClickInputModule::class, InteractionsModule::class,
GcsResourceModule::class, GlideImageLoaderModule::class, ImageParsingModule::class,
HtmlParserEntityTypeModule::class, QuestionModule::class, TestLogReportingModule::class,
AccessibilityTestModule::class, LogStorageModule::class, CachingTestModule::class,
ExpirationMetaDataRetrieverModule::class,
ViewBindingShimModule::class, RatioInputModule::class, WorkManagerConfigurationModule::class,
ApplicationStartupListenerModule::class, LogReportWorkerModule::class,
HintsAndSolutionConfigModule::class, HintsAndSolutionProdModule::class,
FirebaseLogUploaderModule::class, FakeOppiaClockModule::class,
DeveloperOptionsStarterModule::class, DeveloperOptionsModule::class,
ExplorationStorageModule::class, NetworkModule::class, NetworkConfigProdModule::class,
NetworkConnectionUtilDebugModule::class, NetworkConnectionDebugUtilModule::class,
AssetModule::class, LocaleProdModule::class, ActivityRecreatorTestModule::class,
NumericExpressionInputModule::class, AlgebraicExpressionInputModule::class,
MathEquationInputModule::class, SplitScreenInteractionModule::class,
LoggingIdentifierModule::class, ApplicationLifecycleModule::class,
SyncStatusModule::class, MetricLogSchedulerModule::class, TestingBuildFlavorModule::class,
ActivityRouterModule::class,
CpuPerformanceSnapshotterModule::class, ExplorationProgressModule::class,
TestAuthenticationModule::class
]
modules = [RobolectricModule::class, PlatformParameterModule::class, PlatformParameterSingletonModule::class, TestDispatcherModule::class, ApplicationModule::class, LoggerModule::class, ContinueModule::class, FractionInputModule::class, ItemSelectionInputModule::class, MultipleChoiceInputModule::class, NumberWithUnitsRuleModule::class, NumericInputRuleModule::class, TextInputRuleModule::class, DragDropSortInputModule::class, ImageClickInputModule::class, InteractionsModule::class, GcsResourceModule::class, GlideImageLoaderModule::class, ImageParsingModule::class, HtmlParserEntityTypeModule::class, QuestionModule::class, TestLogReportingModule::class, AccessibilityTestModule::class, LogStorageModule::class, CachingTestModule::class, ExpirationMetaDataRetrieverModule::class, ViewBindingShimModule::class, RatioInputModule::class, WorkManagerConfigurationModule::class, ApplicationStartupListenerModule::class, LogReportWorkerModule::class, HintsAndSolutionConfigModule::class, HintsAndSolutionProdModule::class, FirebaseLogUploaderModule::class, FakeOppiaClockModule::class, DeveloperOptionsStarterModule::class, DeveloperOptionsModule::class, ExplorationStorageModule::class, NetworkModule::class, NetworkConfigProdModule::class, NetworkConnectionUtilDebugModule::class, NetworkConnectionDebugUtilModule::class, AssetModule::class, LocaleProdModule::class, ActivityRecreatorTestModule::class, NumericExpressionInputModule::class, AlgebraicExpressionInputModule::class, MathEquationInputModule::class, SplitScreenInteractionModule::class, LoggingIdentifierModule::class, ApplicationLifecycleModule::class, SyncStatusModule::class, MetricLogSchedulerModule::class, TestingBuildFlavorModule::class, ActivityRouterModule::class, CpuPerformanceSnapshotterModule::class, ExplorationProgressModule::class, TestAuthenticationModule::class]
)
interface TestApplicationComponent : ApplicationComponent {
@Component.Builder
Expand All @@ -603,8 +617,7 @@ class AudioFragmentTest {

class TestApplication : Application(), ActivityComponentFactory, ApplicationInjectorProvider {
private val component: TestApplicationComponent by lazy {
DaggerAudioFragmentTest_TestApplicationComponent.builder()
.setApplication(this)
DaggerAudioFragmentTest_TestApplicationComponent.builder().setApplication(this)
.build() as TestApplicationComponent
}

Expand Down

0 comments on commit cde7984

Please sign in to comment.