mirror of
https://github.com/kiwix/kiwix-android.git
synced 2025-08-03 18:56:44 -04:00
Enhancement in tests for reducing CI failure
This commit is contained in:
parent
ef545094a2
commit
5198225972
@ -61,4 +61,6 @@ abstract class BaseActivityTest {
|
||||
protected fun testComponent(): TestComponent = DaggerTestComponent.builder()
|
||||
.context(context)
|
||||
.build()
|
||||
|
||||
abstract fun waitForIdle()
|
||||
}
|
||||
|
@ -18,12 +18,20 @@
|
||||
package org.kiwix.kiwixmobile.help
|
||||
|
||||
import androidx.test.internal.runner.junit4.statement.UiThreadStatement.runOnUiThread
|
||||
import androidx.test.platform.app.InstrumentationRegistry
|
||||
import androidx.test.uiautomator.UiDevice
|
||||
import org.junit.Before
|
||||
import org.junit.Test
|
||||
import org.kiwix.kiwixmobile.BaseActivityTest
|
||||
import org.kiwix.kiwixmobile.R
|
||||
|
||||
class HelpFragmentTest : BaseActivityTest() {
|
||||
|
||||
@Before
|
||||
override fun waitForIdle() {
|
||||
UiDevice.getInstance(InstrumentationRegistry.getInstrumentation()).waitForIdle()
|
||||
}
|
||||
|
||||
@Test
|
||||
fun verifyHelpActivity() {
|
||||
runOnUiThread { activityRule.activity.navigate(R.id.helpFragment) }
|
||||
|
@ -47,7 +47,7 @@ class InitialDownloadTest : BaseActivityTest() {
|
||||
}
|
||||
|
||||
@Before
|
||||
fun waitForIdle() {
|
||||
override fun waitForIdle() {
|
||||
UiDevice.getInstance(InstrumentationRegistry.getInstrumentation()).waitForIdle()
|
||||
}
|
||||
|
||||
|
@ -18,6 +18,9 @@
|
||||
package org.kiwix.kiwixmobile.intro
|
||||
|
||||
import androidx.test.internal.runner.junit4.statement.UiThreadStatement.runOnUiThread
|
||||
import androidx.test.platform.app.InstrumentationRegistry
|
||||
import androidx.test.uiautomator.UiDevice
|
||||
import org.junit.Before
|
||||
import org.junit.Test
|
||||
import org.kiwix.kiwixmobile.BaseActivityTest
|
||||
import org.kiwix.kiwixmobile.R
|
||||
@ -27,6 +30,11 @@ class IntroFragmentTest : BaseActivityTest() {
|
||||
@Test
|
||||
fun viewIsSwipeableAndNavigatesToMain() {
|
||||
runOnUiThread { activityRule.activity.navigate(R.id.introFragment) }
|
||||
intro(IntroRobot::swipeLeft) clickGetStarted { }
|
||||
intro(IntroRobot::swipeLeft) clickGetStarted {}
|
||||
}
|
||||
|
||||
@Before
|
||||
override fun waitForIdle() {
|
||||
UiDevice.getInstance(InstrumentationRegistry.getInstrumentation()).waitForIdle()
|
||||
}
|
||||
}
|
||||
|
@ -32,14 +32,12 @@ fun intro(func: IntroRobot.() -> Unit) = IntroRobot().applyWithViewHierarchyPrin
|
||||
class IntroRobot : BaseRobot() {
|
||||
|
||||
private val getStarted = ViewId(R.id.get_started)
|
||||
private val viewPager = ViewId(R.id.view_pager)
|
||||
|
||||
fun swipeLeft() {
|
||||
isVisible(getStarted)
|
||||
isVisible(TextId(R.string.welcome_to_the_family))
|
||||
isVisible(TextId(R.string.humankind_knowledge))
|
||||
attempt(10) {
|
||||
isVisible(viewPager).swipeLeft()
|
||||
isVisible(TextId(R.string.save_books_offline))
|
||||
isVisible(TextId(R.string.download_books_message))
|
||||
}
|
||||
|
@ -18,13 +18,9 @@
|
||||
|
||||
package org.kiwix.kiwixmobile.language
|
||||
|
||||
import androidx.test.espresso.Espresso.onView
|
||||
import androidx.test.espresso.action.ViewActions.click
|
||||
import androidx.test.espresso.matcher.ViewMatchers.withId
|
||||
import androidx.test.espresso.matcher.ViewMatchers.withText
|
||||
import applyWithViewHierarchyPrinting
|
||||
import org.kiwix.kiwixmobile.BaseRobot
|
||||
import org.kiwix.kiwixmobile.Findable
|
||||
import org.kiwix.kiwixmobile.Findable.Text
|
||||
import org.kiwix.kiwixmobile.Findable.ViewId
|
||||
import org.kiwix.kiwixmobile.R
|
||||
|
||||
@ -36,7 +32,7 @@ class LanguageRobot : BaseRobot() {
|
||||
|
||||
fun waitForDataToLoad() {
|
||||
try {
|
||||
isVisible(Findable.Text("Off the Grid"))
|
||||
isVisible(Text("Off the Grid"))
|
||||
} catch (e: RuntimeException) {
|
||||
if (retryCountForDataToLoad > 0) {
|
||||
retryCountForDataToLoad--
|
||||
@ -50,9 +46,9 @@ class LanguageRobot : BaseRobot() {
|
||||
}
|
||||
|
||||
fun searchAndSaveLanguage(searchLanguage: String, matchLanguage: String) {
|
||||
onView(withId(R.id.menu_language_search)).perform(click())
|
||||
clickOn(ViewId(R.id.menu_language_search))
|
||||
isVisible(ViewId(androidx.appcompat.R.id.search_src_text)).text = searchLanguage
|
||||
onView(withText(matchLanguage)).perform(click())
|
||||
onView(withId(R.id.menu_language_save)).perform(click())
|
||||
clickOn(Text(matchLanguage))
|
||||
clickOn(ViewId(R.id.menu_language_save))
|
||||
}
|
||||
}
|
||||
|
@ -21,6 +21,8 @@ import androidx.core.content.edit
|
||||
import androidx.preference.PreferenceManager
|
||||
import androidx.test.core.app.ActivityScenario
|
||||
import androidx.test.platform.app.InstrumentationRegistry
|
||||
import androidx.test.uiautomator.UiDevice
|
||||
import org.junit.After
|
||||
import org.junit.Before
|
||||
import org.junit.Test
|
||||
import org.kiwix.kiwixmobile.BaseActivityTest
|
||||
@ -33,12 +35,15 @@ import org.kiwix.kiwixmobile.webserver.ZimHostRobot
|
||||
class TopLevelDestinationTest : BaseActivityTest() {
|
||||
|
||||
@Before
|
||||
fun setUp() {
|
||||
override fun waitForIdle() {
|
||||
UiDevice.getInstance(InstrumentationRegistry.getInstrumentation()).waitForIdle()
|
||||
PreferenceManager.getDefaultSharedPreferences(
|
||||
InstrumentationRegistry.getInstrumentation().targetContext.applicationContext
|
||||
).edit {
|
||||
putBoolean(SharedPreferenceUtil.PREF_SHOW_INTRO, false)
|
||||
putBoolean(SharedPreferenceUtil.PREF_WIFI_ONLY, false)
|
||||
putBoolean(SharedPreferenceUtil.PREF_IS_TEST, true)
|
||||
putBoolean(SharedPreferenceUtil.PREF_EXTERNAL_LINK_POPUP, true)
|
||||
}
|
||||
}
|
||||
|
||||
@ -72,4 +77,11 @@ class TopLevelDestinationTest : BaseActivityTest() {
|
||||
pressBack()
|
||||
}
|
||||
}
|
||||
|
||||
@After
|
||||
fun setIsTestPreference() {
|
||||
PreferenceManager.getDefaultSharedPreferences(context).edit {
|
||||
putBoolean(SharedPreferenceUtil.PREF_IS_TEST, false)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -20,8 +20,11 @@ package org.kiwix.kiwixmobile.mimetype
|
||||
|
||||
import androidx.core.content.edit
|
||||
import androidx.preference.PreferenceManager
|
||||
import androidx.test.platform.app.InstrumentationRegistry
|
||||
import androidx.test.rule.ActivityTestRule
|
||||
import androidx.test.uiautomator.UiDevice
|
||||
import org.junit.Assert
|
||||
import org.junit.Before
|
||||
import org.junit.Test
|
||||
import org.kiwix.kiwixlib.JNIKiwixReader
|
||||
import org.kiwix.kiwixmobile.BaseActivityTest
|
||||
@ -42,6 +45,11 @@ class MimeTypeTest : BaseActivityTest() {
|
||||
}
|
||||
}
|
||||
|
||||
@Before
|
||||
override fun waitForIdle() {
|
||||
UiDevice.getInstance(InstrumentationRegistry.getInstrumentation()).waitForIdle()
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testMimeType() {
|
||||
val loadFileStream = MimeTypeTest::class.java.classLoader.getResourceAsStream("testzim.zim")
|
||||
|
@ -18,18 +18,31 @@
|
||||
|
||||
package org.kiwix.kiwixmobile.note
|
||||
|
||||
import android.os.Build
|
||||
import androidx.test.internal.runner.junit4.statement.UiThreadStatement
|
||||
import androidx.test.platform.app.InstrumentationRegistry
|
||||
import androidx.test.uiautomator.UiDevice
|
||||
import org.junit.Before
|
||||
import org.junit.Test
|
||||
import org.kiwix.kiwixmobile.BaseActivityTest
|
||||
import org.kiwix.kiwixmobile.R
|
||||
|
||||
class NoteFragmentTest : BaseActivityTest() {
|
||||
|
||||
@Before
|
||||
override fun waitForIdle() {
|
||||
UiDevice.getInstance(InstrumentationRegistry.getInstrumentation()).waitForIdle()
|
||||
}
|
||||
|
||||
@Test
|
||||
fun verifyNoteFragment() {
|
||||
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.TIRAMISU) {
|
||||
UiThreadStatement.runOnUiThread { activityRule.activity.navigate(R.id.notesFragment) }
|
||||
note {
|
||||
assertToolbarExist()
|
||||
assertNoteRecyclerViewExist()
|
||||
assertSwitchWidgetExist()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -26,7 +26,7 @@ fun note(func: NoteRobot.() -> Unit) = NoteRobot().apply(func)
|
||||
|
||||
class NoteRobot : BaseRobot() {
|
||||
|
||||
init {
|
||||
fun assertToolbarExist() {
|
||||
isVisible(Findable.ViewId(R.id.toolbar))
|
||||
}
|
||||
|
||||
|
@ -24,6 +24,7 @@ import androidx.test.internal.runner.junit4.statement.UiThreadStatement
|
||||
import androidx.test.platform.app.InstrumentationRegistry
|
||||
import androidx.test.rule.ActivityTestRule
|
||||
import androidx.test.uiautomator.UiDevice
|
||||
import org.junit.After
|
||||
import org.junit.Before
|
||||
import org.junit.Test
|
||||
import org.kiwix.kiwixmobile.BaseActivityTest
|
||||
@ -40,15 +41,17 @@ class SearchFragmentTest : BaseActivityTest() {
|
||||
PreferenceManager.getDefaultSharedPreferences(context).edit {
|
||||
putBoolean(SharedPreferenceUtil.PREF_SHOW_INTRO, false)
|
||||
putBoolean(SharedPreferenceUtil.PREF_WIFI_ONLY, false)
|
||||
putBoolean(SharedPreferenceUtil.PREF_IS_TEST, true)
|
||||
}
|
||||
}
|
||||
|
||||
@Before
|
||||
fun waitForIdle() {
|
||||
override fun waitForIdle() {
|
||||
UiDevice.getInstance(InstrumentationRegistry.getInstrumentation()).waitForIdle()
|
||||
}
|
||||
|
||||
@Test fun searchFragmentSimple() {
|
||||
@Test
|
||||
fun searchFragmentSimple() {
|
||||
UiThreadStatement.runOnUiThread { activityRule.activity.navigate(R.id.libraryFragment) }
|
||||
val loadFileStream =
|
||||
SearchFragmentTest::class.java.classLoader.getResourceAsStream("testzim.zim")
|
||||
@ -88,4 +91,11 @@ class SearchFragmentTest : BaseActivityTest() {
|
||||
checkZimFileSearchSuccessful(R.id.readerFragment)
|
||||
}
|
||||
}
|
||||
|
||||
@After
|
||||
fun setIsTestPreference() {
|
||||
PreferenceManager.getDefaultSharedPreferences(context).edit {
|
||||
putBoolean(SharedPreferenceUtil.PREF_IS_TEST, false)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -33,17 +33,24 @@ import org.kiwix.kiwixmobile.testutils.TestUtils.TEST_PAUSE_MS
|
||||
import org.kiwix.kiwixmobile.utils.StandardActions
|
||||
|
||||
class KiwixSettingsFragmentTest {
|
||||
@Rule @JvmField var activityTestRule = ActivityTestRule(
|
||||
@Rule
|
||||
@JvmField
|
||||
var activityTestRule = ActivityTestRule(
|
||||
KiwixMainActivity::class.java
|
||||
)
|
||||
|
||||
@Rule @JvmField var readPermissionRule: GrantPermissionRule =
|
||||
@Rule
|
||||
@JvmField
|
||||
var readPermissionRule: GrantPermissionRule =
|
||||
GrantPermissionRule.grant(Manifest.permission.READ_EXTERNAL_STORAGE)
|
||||
|
||||
@Rule @JvmField var writePermissionRule: GrantPermissionRule =
|
||||
@Rule
|
||||
@JvmField
|
||||
var writePermissionRule: GrantPermissionRule =
|
||||
GrantPermissionRule.grant(Manifest.permission.WRITE_EXTERNAL_STORAGE)
|
||||
|
||||
@Before fun setup() {
|
||||
@Before
|
||||
fun setup() {
|
||||
// Go to IntroFragment
|
||||
UiThreadStatement.runOnUiThread { activityTestRule.activity.navigate(R.id.introFragment) }
|
||||
intro(IntroRobot::swipeLeft) clickGetStarted { }
|
||||
|
@ -31,7 +31,7 @@ import com.adevinta.android.barista.assertion.BaristaVisibilityAssertions.assert
|
||||
import org.hamcrest.Matchers
|
||||
import org.kiwix.kiwixmobile.BaseRobot
|
||||
import org.kiwix.kiwixmobile.Findable.Text
|
||||
import org.kiwix.kiwixmobile.R
|
||||
import org.kiwix.kiwixmobile.core.R
|
||||
|
||||
/**
|
||||
* Authored by Ayush Shrivastava on 25/8/20
|
||||
|
@ -245,9 +245,12 @@ class LocalLibraryFragment : BaseFragment() {
|
||||
|
||||
override fun onResume() {
|
||||
super.onResume()
|
||||
if (!sharedPreferenceUtil.isPlayStoreBuildWithAndroid11OrAbove())
|
||||
if (!sharedPreferenceUtil.isPlayStoreBuildWithAndroid11OrAbove() &&
|
||||
!sharedPreferenceUtil.prefIsTest
|
||||
) {
|
||||
checkPermissions()
|
||||
}
|
||||
}
|
||||
|
||||
override fun onDestroyView() {
|
||||
super.onDestroyView()
|
||||
|
@ -1,5 +1,3 @@
|
||||
import kotlin.String
|
||||
|
||||
/**
|
||||
* Generated by https://github.com/jmfayard/buildSrcVersions
|
||||
*
|
||||
@ -188,12 +186,13 @@ object Libs {
|
||||
/**
|
||||
* https://developer.android.com/testing
|
||||
*/
|
||||
const val androidx_test_core: String = "androidx.test:core:" + Versions.androidx_test
|
||||
const val androidx_test_core: String = "androidx.test:core:" + Versions.androidx_test_core
|
||||
|
||||
/**
|
||||
* https://developer.android.com/testing
|
||||
*/
|
||||
const val orchestrator: String = "androidx.test:orchestrator:" + Versions.androidx_test
|
||||
const val orchestrator: String =
|
||||
"androidx.test:orchestrator:" + Versions.androidx_test_orchestrator
|
||||
|
||||
/**
|
||||
* https://developer.android.com/testing
|
||||
|
@ -36,7 +36,11 @@ object Versions {
|
||||
|
||||
const val com_jakewharton: String = "10.2.3"
|
||||
|
||||
const val androidx_test: String = "1.3.0"
|
||||
const val androidx_test: String = "1.4.0"
|
||||
|
||||
const val androidx_test_core: String = "1.5.0-alpha02"
|
||||
|
||||
const val androidx_test_orchestrator: String = "1.4.1"
|
||||
|
||||
const val io_objectbox: String = "2.9.1"
|
||||
|
||||
|
@ -59,6 +59,9 @@ class SharedPreferenceUtil @Inject constructor(val context: Context) {
|
||||
val prefIsFirstRun: Boolean
|
||||
get() = sharedPreferences.getBoolean(PREF_IS_FIRST_RUN, true)
|
||||
|
||||
val prefIsTest: Boolean
|
||||
get() = sharedPreferences.getBoolean(PREF_IS_TEST, false)
|
||||
|
||||
val prefFullScreen: Boolean
|
||||
get() = sharedPreferences.getBoolean(PREF_FULLSCREEN, false)
|
||||
|
||||
@ -213,11 +216,12 @@ class SharedPreferenceUtil @Inject constructor(val context: Context) {
|
||||
const val PREF_WIFI_ONLY = "pref_wifi_only"
|
||||
const val PREF_KIWIX_MOBILE = "kiwix-mobile"
|
||||
const val PREF_SHOW_INTRO = "showIntro"
|
||||
const val PREF_IS_TEST = "is_test"
|
||||
private const val PREF_BACK_TO_TOP = "pref_backtotop"
|
||||
private const val PREF_FULLSCREEN = "pref_fullscreen"
|
||||
private const val PREF_NEW_TAB_BACKGROUND = "pref_newtab_background"
|
||||
private const val PREF_STORAGE_TITLE = "pref_selected_title"
|
||||
private const val PREF_EXTERNAL_LINK_POPUP = "pref_external_link_popup"
|
||||
const val PREF_EXTERNAL_LINK_POPUP = "pref_external_link_popup"
|
||||
const val PREF_SHOW_STORAGE_OPTION = "show_storgae_option"
|
||||
private const val PREF_IS_FIRST_RUN = "isFirstRun"
|
||||
private const val PREF_SHOW_BOOKMARKS_ALL_BOOKS = "show_bookmarks_current_book"
|
||||
|
Loading…
x
Reference in New Issue
Block a user