Skip to content

Commit

Permalink
fix: Make minor changes on the code for consistency with the rest of …
Browse files Browse the repository at this point in the history
…the codebase
  • Loading branch information
kkmurerwa committed Oct 17, 2023
1 parent 07cde7b commit bffbd4b
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 63 deletions.
11 changes: 1 addition & 10 deletions app/src/main/java/org/oppia/android/app/splash/SplashActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ class SplashActivity :
AppCompatActivity(),
FragmentComponentFactory,
DeprecationNoticeExitAppListener,
DeprecationNoticeActionListener,
BetaNoticeClosedListener,
GeneralAvailabilityUpgradeNoticeClosedListener {

Expand All @@ -62,15 +61,7 @@ class SplashActivity :
return builderInjector.getFragmentComponentBuilderProvider().get().setFragment(fragment).build()
}

override fun onActionButtonClicked(noticeType: DeprecationNoticeActionType) {
when (noticeType) {
DeprecationNoticeActionType.CLOSE -> splashActivityPresenter.handleOnCloseAppButtonClicked()
DeprecationNoticeActionType.DISMISS -> splashActivityPresenter.handleOnDismissButtonClicked()
DeprecationNoticeActionType.UPDATE -> splashActivityPresenter.handleOnUpdateButtonClicked()
}
}

override fun onCloseAppButtonClicked() = splashActivityPresenter.handleOnCloseAppButtonClicked()
override fun onCloseAppButtonClicked() = splashActivityPresenter.handleOnDeprecationNoticeCloseAppButtonClicked()

override fun onBetaNoticeOkayButtonClicked(permanentlyDismiss: Boolean) =
splashActivityPresenter.handleOnBetaNoticeOkayButtonClicked(permanentlyDismiss)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,14 +68,14 @@ class SplashActivityPresenter @Inject constructor(
}

/** Handles cases where the user clicks the close app option on a deprecation notice dialog. */
fun handleOnCloseAppButtonClicked() {
fun handleOnDeprecationNoticeCloseAppButtonClicked() {
// If the app close button is clicked for the deprecation notice, finish the activity to close
// the app.
activity.finish()
}

/** Handle cases where the user clicks the update option on a deprecation notice dialog. */
fun handleOnUpdateButtonClicked() {
/** Handles cases where the user clicks the update option on a deprecation notice dialog. */
fun handleOnDeprecationNoticeUpdateButtonClicked() {
// If the Update button is clicked for the deprecation notice, launch the Play Store and open
// the Oppia app's page.
val packageName = activity.packageName
Expand All @@ -99,8 +99,8 @@ class SplashActivityPresenter @Inject constructor(
activity.finish()
}

/** Handle cases where the user dismisses the deprecation notice dialog. */
fun handleOnDismissButtonClicked() {
/** Handles cases where the user dismisses the deprecation notice dialog. */
fun handleOnDeprecationNoticeDialogDismissed() {
// If the Dismiss button is clicked for the deprecation notice, the dialog is automatically
// dismissed. Navigate to profile chooser activity.
activity.startActivity(ProfileChooserActivity.createProfileChooserActivity(activity))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,10 @@ import androidx.test.core.app.ActivityScenario
import androidx.test.core.app.ApplicationProvider
import androidx.test.espresso.Espresso.onView
import androidx.test.espresso.action.ViewActions
import androidx.test.espresso.assertion.ViewAssertions
import androidx.test.espresso.assertion.ViewAssertions.matches
import androidx.test.espresso.matcher.RootMatchers.isDialog
import androidx.test.espresso.matcher.ViewMatchers
import androidx.test.espresso.matcher.ViewMatchers.isDisplayed
import androidx.test.espresso.matcher.ViewMatchers.withText
import androidx.test.ext.junit.runners.AndroidJUnit4
import dagger.BindsInstance
import dagger.Component
Expand Down Expand Up @@ -133,8 +134,7 @@ class ForcedAppDeprecationNoticeDialogFragmentTest {
@Test
fun testFragment_hasExpectedTitle() {
launchForcedAppDeprecationNoticeDialogFragmentTestActivity {
onDialogView(ViewMatchers.withText(R.string.forced_app_update_dialog_title))
.check(ViewAssertions.matches(ViewMatchers.isDisplayed()))
onDialogView(withText(R.string.forced_app_update_dialog_title)).check(matches(isDisplayed()))
}
}

Expand All @@ -146,26 +146,21 @@ class ForcedAppDeprecationNoticeDialogFragmentTest {
R.string.forced_app_update_dialog_message,
appName
)
onDialogView(ViewMatchers.withText(expectedString))
.check(ViewAssertions.matches(ViewMatchers.isDisplayed()))
onDialogView(withText(expectedString)).check(matches(isDisplayed()))
}
}

@Test
fun testFragment_hasUpdateButton() {
launchForcedAppDeprecationNoticeDialogFragmentTestActivity {
onDialogView(
ViewMatchers.withText(R.string.forced_app_update_dialog_update_button_text)
).check(ViewAssertions.matches(ViewMatchers.isDisplayed()))
onDialogView(withText(R.string.forced_app_update_dialog_update_button_text)).check(matches(isDisplayed()))
}
}

@Test
fun testFragment_clickOnUpdateButton_callsCallbackListener_withUpdateDeprecationActionType() {
launchForcedAppDeprecationNoticeDialogFragmentTestActivity {
clickOnDialogView(
ViewMatchers.withText(R.string.forced_app_update_dialog_update_button_text)
)
clickOnDialogView(withText(R.string.forced_app_update_dialog_update_button_text))

verify(mockDeprecationNoticeActionListener)
.onActionButtonClicked(DeprecationNoticeActionType.UPDATE)
Expand All @@ -175,18 +170,14 @@ class ForcedAppDeprecationNoticeDialogFragmentTest {
@Test
fun testFragment_hasCloseAppButton() {
launchForcedAppDeprecationNoticeDialogFragmentTestActivity {
onDialogView(
ViewMatchers.withText(R.string.forced_app_update_dialog_close_button_text)
).check(ViewAssertions.matches(ViewMatchers.isDisplayed()))
onDialogView(withText(R.string.forced_app_update_dialog_close_button_text)).check(matches(isDisplayed()))
}
}

@Test
fun testFragment_clockOnCloseAppButton_callsCallbackListener_withCloseDeprecationActionType() {
launchForcedAppDeprecationNoticeDialogFragmentTestActivity {
clickOnDialogView(
ViewMatchers.withText(R.string.forced_app_update_dialog_close_button_text)
)
clickOnDialogView(withText(R.string.forced_app_update_dialog_close_button_text))

verify(mockDeprecationNoticeActionListener)
.onActionButtonClicked(DeprecationNoticeActionType.CLOSE)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,10 @@ import androidx.test.core.app.ActivityScenario
import androidx.test.core.app.ApplicationProvider
import androidx.test.espresso.Espresso
import androidx.test.espresso.action.ViewActions
import androidx.test.espresso.assertion.ViewAssertions
import androidx.test.espresso.matcher.RootMatchers
import androidx.test.espresso.matcher.ViewMatchers
import androidx.test.espresso.assertion.ViewAssertions.matches
import androidx.test.espresso.matcher.RootMatchers.isDialog
import androidx.test.espresso.matcher.ViewMatchers.isDisplayed
import androidx.test.espresso.matcher.ViewMatchers.withText
import androidx.test.ext.junit.runners.AndroidJUnit4
import dagger.BindsInstance
import dagger.Component
Expand Down Expand Up @@ -133,8 +134,7 @@ class OptionalAppDeprecationNoticeDialogFragmentTest {
@Test
fun testFragment_hasExpectedTitle() {
launchOptionalAppDeprecationNoticeDialogFragmentTestActivity {
onDialogView(ViewMatchers.withText(R.string.optional_app_update_dialog_title))
.check(ViewAssertions.matches(ViewMatchers.isDisplayed()))
onDialogView(withText(R.string.optional_app_update_dialog_title)).check(matches(isDisplayed()))
}
}

Expand All @@ -146,25 +146,21 @@ class OptionalAppDeprecationNoticeDialogFragmentTest {
R.string.optional_app_update_dialog_message,
appName
)
onDialogView(ViewMatchers.withText(expectedString))
.check(ViewAssertions.matches(ViewMatchers.isDisplayed()))
onDialogView(withText(expectedString)).check(matches(isDisplayed()))
}
}

@Test
fun testFragment_hasUpdateButton() {
launchOptionalAppDeprecationNoticeDialogFragmentTestActivity {
onDialogView(ViewMatchers.withText(R.string.optional_app_update_dialog_update_button_text))
.check(ViewAssertions.matches(ViewMatchers.isDisplayed()))
onDialogView(withText(R.string.optional_app_update_dialog_update_button_text)).check(matches(isDisplayed()))
}
}

@Test
fun testFragment_clickOnUpdateButton_callsCallbackListener_withUpdateDeprecationActionType() {
launchOptionalAppDeprecationNoticeDialogFragmentTestActivity {
clickOnDialogView(
ViewMatchers.withText(R.string.optional_app_update_dialog_update_button_text)
)
clickOnDialogView(withText(R.string.optional_app_update_dialog_update_button_text))

verify(mockDeprecationNoticeActionListener)
.onActionButtonClicked(DeprecationNoticeActionType.UPDATE)
Expand All @@ -174,18 +170,14 @@ class OptionalAppDeprecationNoticeDialogFragmentTest {
@Test
fun testFragment_hasDismissButton() {
launchOptionalAppDeprecationNoticeDialogFragmentTestActivity {
onDialogView(
ViewMatchers.withText(R.string.optional_app_update_dialog_dismiss_button_text)
).check(ViewAssertions.matches(ViewMatchers.isDisplayed()))
onDialogView(withText(R.string.optional_app_update_dialog_dismiss_button_text)).check(matches(isDisplayed()))
}
}

@Test
fun testFragment_clickOnDismissButton_callsCallbackListener_withDismissDeprecationActionType() {
launchOptionalAppDeprecationNoticeDialogFragmentTestActivity {
clickOnDialogView(
ViewMatchers.withText(R.string.optional_app_update_dialog_dismiss_button_text)
)
clickOnDialogView(withText(R.string.optional_app_update_dialog_dismiss_button_text))

verify(mockDeprecationNoticeActionListener)
.onActionButtonClicked(DeprecationNoticeActionType.DISMISS)
Expand Down Expand Up @@ -217,7 +209,7 @@ class OptionalAppDeprecationNoticeDialogFragmentTest {

private companion object {
private fun onDialogView(matcher: Matcher<View>) = Espresso.onView(matcher)
.inRoot(RootMatchers.isDialog())
.inRoot(isDialog())
}

@Singleton
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,10 @@ import androidx.test.core.app.ActivityScenario
import androidx.test.core.app.ApplicationProvider
import androidx.test.espresso.Espresso
import androidx.test.espresso.action.ViewActions
import androidx.test.espresso.assertion.ViewAssertions
import androidx.test.espresso.matcher.RootMatchers
import androidx.test.espresso.matcher.ViewMatchers
import androidx.test.espresso.assertion.ViewAssertions.matches
import androidx.test.espresso.matcher.RootMatchers.isDialog
import androidx.test.espresso.matcher.ViewMatchers.withText
import androidx.test.espresso.matcher.ViewMatchers.isDisplayed
import androidx.test.ext.junit.runners.AndroidJUnit4
import dagger.BindsInstance
import dagger.Component
Expand Down Expand Up @@ -133,8 +134,7 @@ class OsDeprecationNoticeDialogFragmentTest {
@Test
fun testFragment_hasExpectedTitle() {
launchOsDeprecationNoticeDialogFragmentTestActivity {
onDialogView(ViewMatchers.withText(R.string.os_deprecation_dialog_title))
.check(ViewAssertions.matches(ViewMatchers.isDisplayed()))
onDialogView(withText(R.string.os_deprecation_dialog_title)).check(matches(isDisplayed()))
}
}

Expand All @@ -146,23 +146,21 @@ class OsDeprecationNoticeDialogFragmentTest {
R.string.os_deprecation_dialog_message,
appName
)
onDialogView(ViewMatchers.withText(expectedString))
.check(ViewAssertions.matches(ViewMatchers.isDisplayed()))
onDialogView(withText(expectedString)).check(matches(isDisplayed()))
}
}

@Test
fun testFragment_hasDismissButton() {
launchOsDeprecationNoticeDialogFragmentTestActivity {
onDialogView(ViewMatchers.withText(R.string.os_deprecation_dialog_dismiss_button_text))
.check(ViewAssertions.matches(ViewMatchers.isDisplayed()))
onDialogView(withText(R.string.os_deprecation_dialog_dismiss_button_text)).check(matches(isDisplayed()))
}
}

@Test
fun testFragment_clickOnDismissButton_callsCallbackListener_withDismissDeprecationActionType() {
launchOsDeprecationNoticeDialogFragmentTestActivity {
clickOnDialogView(ViewMatchers.withText(R.string.os_deprecation_dialog_dismiss_button_text))
clickOnDialogView(withText(R.string.os_deprecation_dialog_dismiss_button_text))

verify(mockDeprecationNoticeActionListener)
.onActionButtonClicked(DeprecationNoticeActionType.DISMISS)
Expand Down Expand Up @@ -194,7 +192,7 @@ class OsDeprecationNoticeDialogFragmentTest {

private companion object {
private fun onDialogView(matcher: Matcher<View>) = Espresso.onView(matcher)
.inRoot(RootMatchers.isDialog())
.inRoot(isDialog())
}

@Singleton
Expand Down

0 comments on commit bffbd4b

Please sign in to comment.