Fix SplashScreen title tests

Signed-off-by: alperozturk <alper_ozturk@proton.me>
This commit is contained in:
alperozturk 2023-10-11 10:43:43 +02:00
parent ff6919124a
commit 887c197287
No known key found for this signature in database
GPG key ID: 4E577DC593B59BDF
2 changed files with 40 additions and 17 deletions

View file

@ -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))
}
}

View file

@ -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
Handler(Looper.getMainLooper()).postDelayed({
if (!user.isPresent) {
startActivity(Intent(this, AuthenticatorActivity::class.java))
} else {
startActivity(Intent(this, FileDisplayActivity::class.java))
}
finish()
},
SPLASH_DURATION
)
}, SPLASH_DURATION)
}
companion object {