diff --git a/app/src/androidTest/java/com/nmc/android/ui/LauncherActivityIT.kt b/app/src/androidTest/java/com/nmc/android/ui/LauncherActivityIT.kt index b928e3bb93..501ea315e9 100644 --- a/app/src/androidTest/java/com/nmc/android/ui/LauncherActivityIT.kt +++ b/app/src/androidTest/java/com/nmc/android/ui/LauncherActivityIT.kt @@ -23,7 +23,10 @@ package com.nmc.android.ui import androidx.test.espresso.Espresso.onView import androidx.test.espresso.assertion.ViewAssertions.matches +import androidx.test.espresso.matcher.ViewMatchers import androidx.test.espresso.matcher.ViewMatchers.isCompletelyDisplayed +import androidx.test.espresso.matcher.ViewMatchers.isDisplayed +import androidx.test.espresso.matcher.ViewMatchers.withEffectiveVisibility import androidx.test.espresso.matcher.ViewMatchers.withId import androidx.test.espresso.matcher.ViewMatchers.withText import androidx.test.ext.junit.rules.ActivityScenarioRule @@ -33,6 +36,7 @@ import com.owncloud.android.R import org.junit.Rule import org.junit.Test import org.junit.runner.RunWith +import org.mockito.AdditionalMatchers.not @RunWith(AndroidJUnit4::class) class LauncherActivityIT : AbstractIT() { @@ -41,14 +45,26 @@ class LauncherActivityIT : AbstractIT() { val activityRule = ActivityScenarioRule(LauncherActivity::class.java) @Test - fun verifyUIElements() { + fun testSplashScreenWithEmptyTitlesShouldHideTitles() { waitForIdleSync() onView(withId(R.id.ivSplash)).check(matches(isCompletelyDisplayed())) - onView(withId(R.id.splashScreenBold)).check(matches(isCompletelyDisplayed())) - onView(withId(R.id.splashScreenNormal)).check(matches(isCompletelyDisplayed())) - onView(withId(R.id.splashScreenBold)).check(matches(withText("Magenta"))) - onView(withId(R.id.splashScreenNormal)).check(matches(withText("CLOUD"))) + onView(withId(R.id.splashScreenBold)).check(matches(withEffectiveVisibility(ViewMatchers.Visibility.GONE))) + onView(withId(R.id.splashScreenNormal)).check(matches(withEffectiveVisibility(ViewMatchers.Visibility.GONE))) + } + + @Test + fun testSplashScreenWithTitlesShouldShowTitles() { + waitForIdleSync() + onView(withId(R.id.ivSplash)).check(matches(isCompletelyDisplayed())) + + activityRule.scenario.onActivity { + it.setSplashTitles("Example", "Cloud") + } + + val onePercentArea = ViewMatchers.isDisplayingAtLeast(1) + onView(withId(R.id.splashScreenBold)).check(matches(onePercentArea)) + onView(withId(R.id.splashScreenNormal)).check(matches(onePercentArea)) } } diff --git a/app/src/main/java/com/nmc/android/ui/LauncherActivity.kt b/app/src/main/java/com/nmc/android/ui/LauncherActivity.kt index 02c2db3d6f..bd65a0a659 100644 --- a/app/src/main/java/com/nmc/android/ui/LauncherActivity.kt +++ b/app/src/main/java/com/nmc/android/ui/LauncherActivity.kt @@ -23,8 +23,10 @@ package com.nmc.android.ui import android.content.Intent import android.os.Bundle import android.os.Handler +import android.os.Looper import android.text.TextUtils import android.view.View +import androidx.annotation.VisibleForTesting import androidx.core.splashscreen.SplashScreen.Companion.installSplashScreen import com.nextcloud.client.preferences.AppPreferences import com.owncloud.android.R @@ -54,6 +56,15 @@ class LauncherActivity : BaseActivity() { scheduleSplashScreen() } + @VisibleForTesting + fun setSplashTitles(boldText: String, normalText: String) { + binding.splashScreenBold.visibility = View.VISIBLE + binding.splashScreenNormal.visibility = View.VISIBLE + + binding.splashScreenBold.text = boldText + binding.splashScreenNormal.text = normalText + } + private fun updateTitleVisibility() { if (TextUtils.isEmpty(resources.getString(R.string.splashScreenBold))) { binding.splashScreenBold.visibility = View.GONE @@ -64,18 +75,14 @@ class LauncherActivity : BaseActivity() { } private fun scheduleSplashScreen() { - Handler().postDelayed( - { - // if user is null then go to authenticator activity - if (!user.isPresent) { - startActivity(Intent(this, AuthenticatorActivity::class.java)) - } else { - startActivity(Intent(this, FileDisplayActivity::class.java)) - } - finish() - }, - SPLASH_DURATION - ) + Handler(Looper.getMainLooper()).postDelayed({ + if (!user.isPresent) { + startActivity(Intent(this, AuthenticatorActivity::class.java)) + } else { + startActivity(Intent(this, FileDisplayActivity::class.java)) + } + finish() + }, SPLASH_DURATION) } companion object {