diff --git a/app/src/androidTest/kotlin/com/pitchedapps/frost/StartActivityTest.kt b/app/src/androidTest/kotlin/com/pitchedapps/frost/StartActivityTest.kt new file mode 100644 index 000000000..cf266dd6f --- /dev/null +++ b/app/src/androidTest/kotlin/com/pitchedapps/frost/StartActivityTest.kt @@ -0,0 +1,48 @@ +/* + * 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 + +import com.pitchedapps.frost.helper.TEST_FORMATTED_URL +import com.pitchedapps.frost.helper.activityRule +import com.pitchedapps.frost.utils.ARG_URL +import dagger.hilt.android.testing.HiltAndroidRule +import dagger.hilt.android.testing.HiltAndroidTest +import org.junit.Rule +import org.junit.Test + +@HiltAndroidTest +class StartActivityTest { + + @get:Rule(order = 0) + val hildAndroidRule = HiltAndroidRule(this) + + @get:Rule(order = 1) + val activityRule = activityRule( + intentAction = { + putExtra(ARG_URL, TEST_FORMATTED_URL) + } + ) + + @Test + fun initializesSuccessfully() { + activityRule.scenario.use { + it.onActivity { + // Verify no crash + } + } + } +} diff --git a/app/src/androidTest/kotlin/com/pitchedapps/frost/activities/AboutActivityTest.kt b/app/src/androidTest/kotlin/com/pitchedapps/frost/activities/AboutActivityTest.kt new file mode 100644 index 000000000..6435f22b6 --- /dev/null +++ b/app/src/androidTest/kotlin/com/pitchedapps/frost/activities/AboutActivityTest.kt @@ -0,0 +1,42 @@ +/* + * 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 com.pitchedapps.frost.helper.activityRule +import dagger.hilt.android.testing.HiltAndroidRule +import dagger.hilt.android.testing.HiltAndroidTest +import org.junit.Rule +import org.junit.Test + +@HiltAndroidTest +class AboutActivityTest { + + @get:Rule(order = 0) + val hildAndroidRule = HiltAndroidRule(this) + + @get:Rule(order = 1) + val activityRule = activityRule() + + @Test + fun initializesSuccessfully() { + activityRule.scenario.use { + it.onActivity { + // Verify no crash + } + } + } +} diff --git a/app/src/androidTest/kotlin/com/pitchedapps/frost/activities/ActivityConstructionTest.kt b/app/src/androidTest/kotlin/com/pitchedapps/frost/activities/ActivityConstructionTest.kt deleted file mode 100644 index 22e6cbab6..000000000 --- a/app/src/androidTest/kotlin/com/pitchedapps/frost/activities/ActivityConstructionTest.kt +++ /dev/null @@ -1,158 +0,0 @@ -/* - * 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( - intentAction = { - putExtra(ARG_IMAGE_URL, FORMATTED_URL) - } - ) - } - - @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/androidTest/kotlin/com/pitchedapps/frost/activities/DebugActivityTest.kt b/app/src/androidTest/kotlin/com/pitchedapps/frost/activities/DebugActivityTest.kt new file mode 100644 index 000000000..7dd32ada4 --- /dev/null +++ b/app/src/androidTest/kotlin/com/pitchedapps/frost/activities/DebugActivityTest.kt @@ -0,0 +1,42 @@ +/* + * 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 com.pitchedapps.frost.helper.activityRule +import dagger.hilt.android.testing.HiltAndroidRule +import dagger.hilt.android.testing.HiltAndroidTest +import org.junit.Rule +import org.junit.Test + +@HiltAndroidTest +class DebugActivityTest { + + @get:Rule(order = 0) + val hildAndroidRule = HiltAndroidRule(this) + + @get:Rule(order = 1) + val activityRule = activityRule() + + @Test + fun initializesSuccessfully() { + activityRule.scenario.use { + it.onActivity { + // Verify no crash + } + } + } +} diff --git a/app/src/androidTest/kotlin/com/pitchedapps/frost/activities/FrostWebActivityTest.kt b/app/src/androidTest/kotlin/com/pitchedapps/frost/activities/FrostWebActivityTest.kt new file mode 100644 index 000000000..d45848008 --- /dev/null +++ b/app/src/androidTest/kotlin/com/pitchedapps/frost/activities/FrostWebActivityTest.kt @@ -0,0 +1,48 @@ +/* + * 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 com.pitchedapps.frost.helper.TEST_FORMATTED_URL +import com.pitchedapps.frost.helper.activityRule +import com.pitchedapps.frost.utils.ARG_URL +import dagger.hilt.android.testing.HiltAndroidRule +import dagger.hilt.android.testing.HiltAndroidTest +import org.junit.Rule +import org.junit.Test + +@HiltAndroidTest +class FrostWebActivityTest { + + @get:Rule(order = 0) + val hildAndroidRule = HiltAndroidRule(this) + + @get:Rule(order = 1) + val activityRule = activityRule( + intentAction = { + putExtra(ARG_URL, TEST_FORMATTED_URL) + } + ) + + @Test + fun initializesSuccessfully() { + activityRule.scenario.use { + it.onActivity { + // Verify no crash + } + } + } +} diff --git a/app/src/androidTest/kotlin/com/pitchedapps/frost/activities/ImageActivityTest.kt b/app/src/androidTest/kotlin/com/pitchedapps/frost/activities/ImageActivityTest.kt index 57441a623..6c4fe60a8 100644 --- a/app/src/androidTest/kotlin/com/pitchedapps/frost/activities/ImageActivityTest.kt +++ b/app/src/androidTest/kotlin/com/pitchedapps/frost/activities/ImageActivityTest.kt @@ -17,15 +17,18 @@ package com.pitchedapps.frost.activities import android.content.Intent -import androidx.test.ext.junit.runners.AndroidJUnit4 -import androidx.test.rule.ActivityTestRule -import ca.allanwang.kau.utils.isVisible -import com.pitchedapps.frost.FrostTestRule +import androidx.core.view.isVisible +import androidx.test.core.app.ActivityScenario +import androidx.test.core.app.ApplicationProvider +import com.pitchedapps.frost.helper.TEST_FORMATTED_URL +import com.pitchedapps.frost.helper.activityRule import com.pitchedapps.frost.helper.getResource import com.pitchedapps.frost.utils.ARG_COOKIE import com.pitchedapps.frost.utils.ARG_IMAGE_URL import com.pitchedapps.frost.utils.ARG_TEXT import com.pitchedapps.frost.utils.isIndirectImageUrl +import dagger.hilt.android.testing.HiltAndroidRule +import dagger.hilt.android.testing.HiltAndroidTest import okhttp3.internal.closeQuietly import okhttp3.mockwebserver.Dispatcher import okhttp3.mockwebserver.MockResponse @@ -35,42 +38,31 @@ import okio.Buffer import okio.source import org.junit.After import org.junit.Before +import org.junit.Ignore import org.junit.Rule import org.junit.Test -import org.junit.rules.RuleChain -import org.junit.rules.TestRule import org.junit.rules.Timeout -import org.junit.runner.RunWith import kotlin.test.assertEquals import kotlin.test.assertFalse import kotlin.test.assertNotNull import kotlin.test.assertNull import kotlin.test.assertTrue -@RunWith(AndroidJUnit4::class) +@HiltAndroidTest class ImageActivityTest { - val activity: ActivityTestRule = - ActivityTestRule(ImageActivity::class.java, true, false) + @get:Rule(order = 0) + val hildAndroidRule = HiltAndroidRule(this) - @get:Rule - val rule: TestRule = RuleChain.outerRule(FrostTestRule()).around(activity) - - @get:Rule - val globalTimeout: Timeout = Timeout.seconds(15) - - private fun launchActivity(imageUrl: String, text: String? = null, cookie: String? = null) { - assertFalse( - imageUrl.isIndirectImageUrl, - "For simplicity, urls that are direct will be used without modifications in the production code." - ) - val intent = Intent().apply { - putExtra(ARG_IMAGE_URL, imageUrl) - putExtra(ARG_TEXT, text) - putExtra(ARG_COOKIE, cookie) + @get:Rule(order = 1) + val activityRule = activityRule( + intentAction = { + putExtra(ARG_IMAGE_URL, TEST_FORMATTED_URL) } - activity.launchActivity(intent) - } + ) + + @get:Rule(order = 2) + val globalTimeout: Timeout = Timeout.seconds(15) lateinit var mockServer: MockWebServer @@ -84,6 +76,86 @@ class ImageActivityTest { mockServer.closeQuietly() } + @Test + fun initializesSuccessfully() = launchScenario(mockServer.url("image").toString()) { + // Verify no crash + } + + @Test + fun validImageTest() = launchScenario(mockServer.url("image").toString()) { + mockServer.takeRequest() + assertEquals(1, mockServer.requestCount, "One http request expected") +// assertEquals( +// FabStates.DOWNLOAD, +// fabAction, +// "Image should be successful, image should be downloaded" +// ) + assertFalse(binding.error.isVisible, "Error should not be shown") + val tempFile = assertNotNull(tempFile, "Temp file not created") + assertTrue(tempFile.exists(), "Image should be located at temp file") + assertTrue( + System.currentTimeMillis() - tempFile.lastModified() < 2000L, + "Image should have been modified within the last few seconds" + ) + assertNull(errorRef, "No error should exist") + tempFile.delete() + } + + @Test + @Ignore("apparently this fails") + fun invalidImageTest() = launchScenario(mockServer.url("text").toString()) { + mockServer.takeRequest() + assertEquals(1, mockServer.requestCount, "One http request expected") + assertTrue(binding.error.isVisible, "Error should be shown") + +// assertEquals( +// FabStates.ERROR, +// fabAction, +// "Text should not be a valid image format, error state expected" +// ) + assertEquals( + "Image format not supported", + errorRef?.message, + "Error message mismatch" + ) + assertFalse(tempFile?.exists() == true, "Temp file should have been removed") + } + + @Test + fun errorTest() = launchScenario(mockServer.url("error").toString()) { + mockServer.takeRequest() + assertEquals(1, mockServer.requestCount, "One http request expected") + assertTrue(binding.error.isVisible, "Error should be shown") +// assertEquals(FabStates.ERROR, fabAction, "Error response code, error state expected") + assertEquals( + "Unsuccessful response for image: Error mock response", + errorRef?.message, + "Error message mismatch" + ) + assertFalse(tempFile?.exists() == true, "Temp file should have been removed") + } + + private fun launchScenario( + imageUrl: String, + text: String? = null, + cookie: String? = null, + action: ImageActivity.() -> Unit + ) { + assertFalse( + imageUrl.isIndirectImageUrl, + "For simplicity, urls that are direct will be used without modifications in the production code." + ) + val intent = + Intent(ApplicationProvider.getApplicationContext(), ImageActivity::class.java).apply { + putExtra(ARG_IMAGE_URL, imageUrl) + putExtra(ARG_TEXT, text) + putExtra(ARG_COOKIE, cookie) + } + ActivityScenario.launch(intent).use { + it.onActivity(action) + } + } + private fun mockServer(): MockWebServer { val img = Buffer() img.writeAll(getResource("bayer-pattern.jpg").source()) @@ -91,9 +163,10 @@ class ImageActivityTest { dispatcher = object : Dispatcher() { override fun dispatch(request: RecordedRequest): MockResponse = when { - request.path?.contains("text") == true -> MockResponse().setResponseCode(200).setBody( - "Valid mock text response" - ) + request.path?.contains("text") == true -> MockResponse().setResponseCode(200) + .setBody( + "Valid mock text response" + ) request.path?.contains("image") == true -> MockResponse().setResponseCode( 200 ).setBody( @@ -105,62 +178,4 @@ class ImageActivityTest { start() } } - - @Test - fun validImageTest() { - launchActivity(mockServer.url("image").toString()) - mockServer.takeRequest() - with(activity.activity) { - assertEquals(1, mockServer.requestCount, "One http request expected") -// assertEquals( -// FabStates.DOWNLOAD, -// fabAction, -// "Image should be successful, image should be downloaded" -// ) - assertFalse(binding.error.isVisible, "Error should not be shown") - val tempFile = assertNotNull(tempFile, "Temp file not created") - assertTrue(tempFile.exists(), "Image should be located at temp file") - assertTrue( - System.currentTimeMillis() - tempFile.lastModified() < 2000L, - "Image should have been modified within the last few seconds" - ) - assertNull(errorRef, "No error should exist") - tempFile.delete() - } - } - - @Test - fun invalidImageTest() { - launchActivity(mockServer.url("text").toString()) - mockServer.takeRequest() - with(activity.activity) { - assertEquals(1, mockServer.requestCount, "One http request expected") - assertTrue(binding.error.isVisible, "Error should be shown") - -// assertEquals( -// FabStates.ERROR, -// fabAction, -// "Text should not be a valid image format, error state expected" -// ) - assertEquals("Image format not supported", errorRef?.message, "Error message mismatch") - assertFalse(tempFile?.exists() == true, "Temp file should have been removed") - } - } - - @Test - fun errorTest() { - launchActivity(mockServer.url("error").toString()) - mockServer.takeRequest() - with(activity.activity) { - assertEquals(1, mockServer.requestCount, "One http request expected") - assertTrue(binding.error.isVisible, "Error should be shown") -// assertEquals(FabStates.ERROR, fabAction, "Error response code, error state expected") - assertEquals( - "Unsuccessful response for image: Error mock response", - errorRef?.message, - "Error message mismatch" - ) - assertFalse(tempFile?.exists() == true, "Temp file should have been removed") - } - } } diff --git a/app/src/androidTest/kotlin/com/pitchedapps/frost/activities/IntroActivityTest.kt b/app/src/androidTest/kotlin/com/pitchedapps/frost/activities/IntroActivityTest.kt new file mode 100644 index 000000000..0fea49fed --- /dev/null +++ b/app/src/androidTest/kotlin/com/pitchedapps/frost/activities/IntroActivityTest.kt @@ -0,0 +1,42 @@ +/* + * 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 com.pitchedapps.frost.helper.activityRule +import dagger.hilt.android.testing.HiltAndroidRule +import dagger.hilt.android.testing.HiltAndroidTest +import org.junit.Rule +import org.junit.Test + +@HiltAndroidTest +class IntroActivityTest { + + @get:Rule(order = 0) + val hildAndroidRule = HiltAndroidRule(this) + + @get:Rule(order = 1) + val activityRule = activityRule() + + @Test + fun initializesSuccessfully() { + activityRule.scenario.use { + it.onActivity { + // Verify no crash + } + } + } +} diff --git a/app/src/androidTest/kotlin/com/pitchedapps/frost/activities/LoginActivityTest.kt b/app/src/androidTest/kotlin/com/pitchedapps/frost/activities/LoginActivityTest.kt new file mode 100644 index 000000000..1a77d00cf --- /dev/null +++ b/app/src/androidTest/kotlin/com/pitchedapps/frost/activities/LoginActivityTest.kt @@ -0,0 +1,42 @@ +/* + * 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 com.pitchedapps.frost.helper.activityRule +import dagger.hilt.android.testing.HiltAndroidRule +import dagger.hilt.android.testing.HiltAndroidTest +import org.junit.Rule +import org.junit.Test + +@HiltAndroidTest +class LoginActivityTest { + + @get:Rule(order = 0) + val hildAndroidRule = HiltAndroidRule(this) + + @get:Rule(order = 1) + val activityRule = activityRule() + + @Test + fun initializesSuccessfully() { + activityRule.scenario.use { + it.onActivity { + // Verify no crash + } + } + } +} diff --git a/app/src/androidTest/kotlin/com/pitchedapps/frost/activities/MainActivityTest.kt b/app/src/androidTest/kotlin/com/pitchedapps/frost/activities/MainActivityTest.kt new file mode 100644 index 000000000..b5c01e311 --- /dev/null +++ b/app/src/androidTest/kotlin/com/pitchedapps/frost/activities/MainActivityTest.kt @@ -0,0 +1,42 @@ +/* + * 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 com.pitchedapps.frost.helper.activityRule +import dagger.hilt.android.testing.HiltAndroidRule +import dagger.hilt.android.testing.HiltAndroidTest +import org.junit.Rule +import org.junit.Test + +@HiltAndroidTest +class MainActivityTest { + + @get:Rule(order = 0) + val hildAndroidRule = HiltAndroidRule(this) + + @get:Rule(order = 1) + val activityRule = activityRule() + + @Test + fun initializesSuccessfully() { + activityRule.scenario.use { + it.onActivity { + // Verify no crash + } + } + } +} diff --git a/app/src/androidTest/kotlin/com/pitchedapps/frost/activities/SelectorActivityTest.kt b/app/src/androidTest/kotlin/com/pitchedapps/frost/activities/SelectorActivityTest.kt new file mode 100644 index 000000000..7f3b12902 --- /dev/null +++ b/app/src/androidTest/kotlin/com/pitchedapps/frost/activities/SelectorActivityTest.kt @@ -0,0 +1,42 @@ +/* + * 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 com.pitchedapps.frost.helper.activityRule +import dagger.hilt.android.testing.HiltAndroidRule +import dagger.hilt.android.testing.HiltAndroidTest +import org.junit.Rule +import org.junit.Test + +@HiltAndroidTest +class SelectorActivityTest { + + @get:Rule(order = 0) + val hildAndroidRule = HiltAndroidRule(this) + + @get:Rule(order = 1) + val activityRule = activityRule() + + @Test + fun initializesSuccessfully() { + activityRule.scenario.use { + it.onActivity { + // Verify no crash + } + } + } +} diff --git a/app/src/androidTest/kotlin/com/pitchedapps/frost/activities/SettingActivityTest.kt b/app/src/androidTest/kotlin/com/pitchedapps/frost/activities/SettingActivityTest.kt new file mode 100644 index 000000000..026498a11 --- /dev/null +++ b/app/src/androidTest/kotlin/com/pitchedapps/frost/activities/SettingActivityTest.kt @@ -0,0 +1,42 @@ +/* + * 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 com.pitchedapps.frost.helper.activityRule +import dagger.hilt.android.testing.HiltAndroidRule +import dagger.hilt.android.testing.HiltAndroidTest +import org.junit.Rule +import org.junit.Test + +@HiltAndroidTest +class SettingActivityTest { + + @get:Rule(order = 0) + val hildAndroidRule = HiltAndroidRule(this) + + @get:Rule(order = 1) + val activityRule = activityRule() + + @Test + fun initializesSuccessfully() { + activityRule.scenario.use { + it.onActivity { + // Verify no crash + } + } + } +} diff --git a/app/src/androidTest/kotlin/com/pitchedapps/frost/activities/TabCustomizerActivityTest.kt b/app/src/androidTest/kotlin/com/pitchedapps/frost/activities/TabCustomizerActivityTest.kt new file mode 100644 index 000000000..ed30b809f --- /dev/null +++ b/app/src/androidTest/kotlin/com/pitchedapps/frost/activities/TabCustomizerActivityTest.kt @@ -0,0 +1,42 @@ +/* + * 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 com.pitchedapps.frost.helper.activityRule +import dagger.hilt.android.testing.HiltAndroidRule +import dagger.hilt.android.testing.HiltAndroidTest +import org.junit.Rule +import org.junit.Test + +@HiltAndroidTest +class TabCustomizerActivityTest { + + @get:Rule(order = 0) + val hildAndroidRule = HiltAndroidRule(this) + + @get:Rule(order = 1) + val activityRule = activityRule() + + @Test + fun initializesSuccessfully() { + activityRule.scenario.use { + it.onActivity { + // Verify no crash + } + } + } +} diff --git a/app/src/androidTest/kotlin/com/pitchedapps/frost/activities/WebOverlayActivityTest.kt b/app/src/androidTest/kotlin/com/pitchedapps/frost/activities/WebOverlayActivityTest.kt new file mode 100644 index 000000000..dac81fe74 --- /dev/null +++ b/app/src/androidTest/kotlin/com/pitchedapps/frost/activities/WebOverlayActivityTest.kt @@ -0,0 +1,42 @@ +/* + * 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 com.pitchedapps.frost.helper.activityRule +import dagger.hilt.android.testing.HiltAndroidRule +import dagger.hilt.android.testing.HiltAndroidTest +import org.junit.Rule +import org.junit.Test + +@HiltAndroidTest +class WebOverlayActivityTest { + + @get:Rule(order = 0) + val hildAndroidRule = HiltAndroidRule(this) + + @get:Rule(order = 1) + val activityRule = activityRule() + + @Test + fun initializesSuccessfully() { + activityRule.scenario.use { + it.onActivity { + // Verify no crash + } + } + } +} diff --git a/app/src/androidTest/kotlin/com/pitchedapps/frost/helper/Helper.kt b/app/src/androidTest/kotlin/com/pitchedapps/frost/helper/Helper.kt index f7484cb37..52bf4494f 100644 --- a/app/src/androidTest/kotlin/com/pitchedapps/frost/helper/Helper.kt +++ b/app/src/androidTest/kotlin/com/pitchedapps/frost/helper/Helper.kt @@ -16,7 +16,12 @@ */ package com.pitchedapps.frost.helper +import android.app.Activity import android.content.Context +import android.content.Intent +import android.os.Bundle +import androidx.test.core.app.ApplicationProvider +import androidx.test.ext.junit.rules.ActivityScenarioRule import androidx.test.platform.app.InstrumentationRegistry import java.io.InputStream @@ -30,3 +35,14 @@ private class Helper fun getResource(resource: String): InputStream = Helper::class.java.classLoader!!.getResource(resource).openStream() + +inline fun activityRule( + intentAction: Intent.() -> Unit = {}, + activityOptions: Bundle? = null +): ActivityScenarioRule { + val intent = + Intent(ApplicationProvider.getApplicationContext(), A::class.java).also(intentAction) + return ActivityScenarioRule(intent, activityOptions) +} + +const val TEST_FORMATTED_URL = "https://www.google.com"