From 47fcc3a2947be85a57086f7621ef1bdfcbd8a404 Mon Sep 17 00:00:00 2001 From: Allan Wang Date: Mon, 13 Sep 2021 20:57:56 -0700 Subject: Create initial hilt tests --- .../frost/activities/ActivityConstructionTest.kt | 24 ++++++++++++++++++++++ .../pitchedapps/frost/activities/ImageActivity.kt | 15 +++++++------- 2 files changed, 32 insertions(+), 7 deletions(-) create mode 100644 app/src/androidTest/kotlin/com/pitchedapps/frost/activities/ActivityConstructionTest.kt (limited to 'app/src') diff --git a/app/src/androidTest/kotlin/com/pitchedapps/frost/activities/ActivityConstructionTest.kt b/app/src/androidTest/kotlin/com/pitchedapps/frost/activities/ActivityConstructionTest.kt new file mode 100644 index 00000000..bad484ef --- /dev/null +++ b/app/src/androidTest/kotlin/com/pitchedapps/frost/activities/ActivityConstructionTest.kt @@ -0,0 +1,24 @@ +package com.pitchedapps.frost.activities + +import android.app.Activity +import android.os.Bundle +import androidx.test.core.app.ActivityScenario +import dagger.hilt.android.testing.HiltAndroidRule +import dagger.hilt.android.testing.HiltAndroidTest +import org.junit.Rule +import org.junit.Test + +@HiltAndroidTest +class ActivityConstructionTest { + + @get:Rule + val hiltRule = HiltAndroidRule(this) + + @Test + fun imageActivity() { + launch() + } + + private inline fun launch(activityOptions: Bundle? = null) = + ActivityScenario.launch(A::class.java, activityOptions) +} \ No newline at end of file diff --git a/app/src/main/kotlin/com/pitchedapps/frost/activities/ImageActivity.kt b/app/src/main/kotlin/com/pitchedapps/frost/activities/ImageActivity.kt index c5b8bdaa..e3b607a3 100644 --- a/app/src/main/kotlin/com/pitchedapps/frost/activities/ImageActivity.kt +++ b/app/src/main/kotlin/com/pitchedapps/frost/activities/ImageActivity.kt @@ -137,8 +137,9 @@ class ImageActivity : KauBaseActivity() { lateinit var binding: ActivityImageBinding private var bottomBehavior: BottomSheetBehavior? = null - private val baseBackgroundColor = if (prefs.blackMediaBg) Color.BLACK - else themeProvider.bgColor.withMinAlpha(235) + private val baseBackgroundColor: Int + get() = if (prefs.blackMediaBg) Color.BLACK + else themeProvider.bgColor.withMinAlpha(235) private fun loadError(e: Throwable) { if (e.message?.contains("") == true) { @@ -226,11 +227,11 @@ class ImageActivity : KauBaseActivity() { setState(FabStates.SHARE) } imagePhoto.setOnImageEventListener(object : - SubsamplingScaleImageView.DefaultOnImageEventListener() { - override fun onImageLoadError(e: Exception) { - loadError(e) - } - }) + SubsamplingScaleImageView.DefaultOnImageEventListener() { + override fun onImageLoadError(e: Exception) { + loadError(e) + } + }) activityThemer.setFrostColors { themeWindow = false } -- cgit v1.2.3 From f5c5b17040c9469904ab25c7d348a865764d4aa2 Mon Sep 17 00:00:00 2001 From: Allan Wang Date: Mon, 13 Sep 2021 21:29:58 -0700 Subject: Test remaining activities --- .../frost/activities/ActivityConstructionTest.kt | 142 ++++++++++++++++++++- .../pitchedapps/frost/activities/ImageActivity.kt | 10 +- .../pitchedapps/frost/activities/IntroActivity.kt | 21 +-- 3 files changed, 155 insertions(+), 18 deletions(-) (limited to 'app/src') diff --git a/app/src/androidTest/kotlin/com/pitchedapps/frost/activities/ActivityConstructionTest.kt b/app/src/androidTest/kotlin/com/pitchedapps/frost/activities/ActivityConstructionTest.kt index bad484ef..22e6cbab 100644 --- a/app/src/androidTest/kotlin/com/pitchedapps/frost/activities/ActivityConstructionTest.kt +++ b/app/src/androidTest/kotlin/com/pitchedapps/frost/activities/ActivityConstructionTest.kt @@ -1,24 +1,158 @@ +/* + * Copyright 2021 Allan Wang + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ package com.pitchedapps.frost.activities import android.app.Activity +import android.content.Context +import android.content.Intent import android.os.Bundle import androidx.test.core.app.ActivityScenario +import com.pitchedapps.frost.StartActivity +import com.pitchedapps.frost.utils.ARG_IMAGE_URL +import com.pitchedapps.frost.utils.ARG_URL +import dagger.hilt.android.qualifiers.ApplicationContext import dagger.hilt.android.testing.HiltAndroidRule import dagger.hilt.android.testing.HiltAndroidTest +import org.junit.Before +import org.junit.Ignore import org.junit.Rule import org.junit.Test +import javax.inject.Inject +/** + * Basic activity launching tests. + * + * Verifies that Hilt injections are not used prior to onCreate + */ @HiltAndroidTest class ActivityConstructionTest { + @ApplicationContext + @Inject + lateinit var appContext: Context + @get:Rule val hiltRule = HiltAndroidRule(this) + @Before + fun before() { + hiltRule.inject() + } + + @Test + fun aboutActivity() { + launch() + } + + @Test + fun debugActivity() { + launch() + } + + @Test + fun frostWebActivity() { + launch( + intentAction = { + putExtra(ARG_URL, FORMATTED_URL) + } + ) + } + @Test fun imageActivity() { - launch() + launch( + intentAction = { + putExtra(ARG_IMAGE_URL, FORMATTED_URL) + } + ) } - private inline fun launch(activityOptions: Bundle? = null) = - ActivityScenario.launch(A::class.java, activityOptions) -} \ No newline at end of file + @Test + @Ignore("Doesn't work, yet production is fine.") + fun introActivity() { + launch() + } + + @Test + fun loginActivity() { + launch() + } + + @Test + fun mainActivity() { + launch() + } + + @Test + fun selectorActivity() { + launch() + } + + @Test + fun settingsActivity() { + launch() + } + + @Test + fun startActivity() { + launch() + } + + @Test + fun tabCustomizerActivity() { + launch() + } + + @Test + fun webOverlayMobileActivity() { + launch( + intentAction = { + putExtra(ARG_URL, FORMATTED_URL) + } + ) + } + + @Test + fun webOverlayDesktopActivity() { + launch( + intentAction = { + putExtra(ARG_URL, FORMATTED_URL) + } + ) + } + + @Test + fun webOverlayActivity() { + launch( + intentAction = { + putExtra(ARG_URL, FORMATTED_URL) + } + ) + } + + private inline fun launch( + intentAction: Intent.() -> Unit = {}, + activityOptions: Bundle? = null + ): ActivityScenario { + val intent = Intent(appContext, A::class.java).also(intentAction) + return ActivityScenario.launch(intent, activityOptions) + } + + private companion object { + const val FORMATTED_URL = "https://www.google.com" + } +} diff --git a/app/src/main/kotlin/com/pitchedapps/frost/activities/ImageActivity.kt b/app/src/main/kotlin/com/pitchedapps/frost/activities/ImageActivity.kt index e3b607a3..b8a71fa1 100644 --- a/app/src/main/kotlin/com/pitchedapps/frost/activities/ImageActivity.kt +++ b/app/src/main/kotlin/com/pitchedapps/frost/activities/ImageActivity.kt @@ -227,11 +227,11 @@ class ImageActivity : KauBaseActivity() { setState(FabStates.SHARE) } imagePhoto.setOnImageEventListener(object : - SubsamplingScaleImageView.DefaultOnImageEventListener() { - override fun onImageLoadError(e: Exception) { - loadError(e) - } - }) + SubsamplingScaleImageView.DefaultOnImageEventListener() { + override fun onImageLoadError(e: Exception) { + loadError(e) + } + }) activityThemer.setFrostColors { themeWindow = false } diff --git a/app/src/main/kotlin/com/pitchedapps/frost/activities/IntroActivity.kt b/app/src/main/kotlin/com/pitchedapps/frost/activities/IntroActivity.kt index 817eebe1..02b7fb9d 100644 --- a/app/src/main/kotlin/com/pitchedapps/frost/activities/IntroActivity.kt +++ b/app/src/main/kotlin/com/pitchedapps/frost/activities/IntroActivity.kt @@ -28,6 +28,7 @@ import androidx.fragment.app.FragmentManager import androidx.fragment.app.FragmentPagerAdapter import androidx.viewpager.widget.ViewPager import ca.allanwang.kau.internal.KauBaseActivity +import ca.allanwang.kau.kotlin.lazyUi import ca.allanwang.kau.utils.blendWith import ca.allanwang.kau.utils.color import ca.allanwang.kau.utils.fadeScaleTransition @@ -82,14 +83,16 @@ class IntroActivity : lateinit var binding: ActivityIntroBinding private var barHasNext = true - val fragments = listOf( - IntroFragmentWelcome(), - IntroFragmentTheme(), - IntroAccountFragment(), - IntroTabTouchFragment(), - IntroTabContextFragment(), - IntroFragmentEnd() - ) + private val fragments by lazyUi { + listOf( + IntroFragmentWelcome(), + IntroFragmentTheme(), + IntroAccountFragment(), + IntroTabTouchFragment(), + IntroTabContextFragment(), + IntroFragmentEnd() + ) + } override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) @@ -130,7 +133,7 @@ class IntroActivity : /** * Transformations are mainly handled on a per view basis - * This sifies it by making the first fragment fade out as the second fragment comes in + * This makes the first fragment fade out as the second fragment comes in * All fragments are locked in position */ override fun transformPage(page: View, position: Float) { -- cgit v1.2.3