mirror of
https://github.com/kiwix/kiwix-android.git
synced 2025-08-03 10:46:53 -04:00
Add test case for Initial Download
This commit is contained in:
parent
fd97b96949
commit
8617cc00ed
@ -0,0 +1,80 @@
|
||||
/*
|
||||
* Kiwix Android
|
||||
* Copyright (c) 2022 Kiwix <android.kiwix.org>
|
||||
* 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 <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
package org.kiwix.kiwixmobile.initial.download
|
||||
|
||||
import androidx.test.espresso.Espresso.onView
|
||||
import androidx.test.espresso.action.ViewActions.click
|
||||
import androidx.test.espresso.matcher.ViewMatchers.withText
|
||||
import applyWithViewHierarchyPrinting
|
||||
import com.adevinta.android.barista.interaction.BaristaSwipeRefreshInteractions.refresh
|
||||
import org.kiwix.kiwixmobile.BaseRobot
|
||||
import org.kiwix.kiwixmobile.Findable.Text
|
||||
import org.kiwix.kiwixmobile.Findable.ViewId
|
||||
import org.kiwix.kiwixmobile.R
|
||||
|
||||
fun initialDownload(func: InitialDownloadRobot.() -> Unit) =
|
||||
InitialDownloadRobot().applyWithViewHierarchyPrinting(func)
|
||||
|
||||
class InitialDownloadRobot : BaseRobot() {
|
||||
|
||||
private var retryCountForDataToLoad = 5
|
||||
private var retryCountForCheckDownloadStart = 5
|
||||
|
||||
fun assertLibraryListDisplayed() {
|
||||
isVisible(ViewId(R.id.libraryList))
|
||||
}
|
||||
|
||||
fun refreshList() {
|
||||
refresh(R.id.librarySwipeRefresh)
|
||||
}
|
||||
|
||||
fun waitForDataToLoad() {
|
||||
try {
|
||||
isVisible(Text("Off the Grid"))
|
||||
} catch (e: RuntimeException) {
|
||||
if (retryCountForDataToLoad > 0) {
|
||||
retryCountForDataToLoad--
|
||||
waitForDataToLoad()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun downloadZimFile() {
|
||||
clickOn(Text("Off the Grid"))
|
||||
}
|
||||
|
||||
fun assertStorageConfigureDialogDisplayed() {
|
||||
isVisible(Text("Download book to internal storage?"))
|
||||
}
|
||||
|
||||
fun clickYesToConfigureStorage() {
|
||||
onView(withText("YES")).perform(click())
|
||||
}
|
||||
|
||||
fun assertDownloadStart() {
|
||||
try {
|
||||
isVisible(ViewId(R.id.stop))
|
||||
} catch (e: RuntimeException) {
|
||||
if (retryCountForCheckDownloadStart > 0) {
|
||||
retryCountForCheckDownloadStart--
|
||||
assertDownloadStart()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,74 @@
|
||||
/*
|
||||
* Kiwix Android
|
||||
* Copyright (c) 2022 Kiwix <android.kiwix.org>
|
||||
* 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 <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
package org.kiwix.kiwixmobile.initial.download
|
||||
|
||||
import androidx.core.content.edit
|
||||
import androidx.preference.PreferenceManager
|
||||
import androidx.test.ext.junit.runners.AndroidJUnit4
|
||||
import androidx.test.filters.LargeTest
|
||||
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.junit.runner.RunWith
|
||||
import org.kiwix.kiwixmobile.BaseActivityTest
|
||||
import org.kiwix.kiwixmobile.R
|
||||
import org.kiwix.kiwixmobile.core.utils.SharedPreferenceUtil
|
||||
import org.kiwix.kiwixmobile.main.KiwixMainActivity
|
||||
|
||||
@LargeTest
|
||||
@RunWith(AndroidJUnit4::class)
|
||||
class InitialDownloadTest : BaseActivityTest() {
|
||||
override var activityRule: ActivityTestRule<KiwixMainActivity> = activityTestRule {
|
||||
PreferenceManager.getDefaultSharedPreferences(context).edit {
|
||||
putBoolean(SharedPreferenceUtil.PREF_SHOW_INTRO, false)
|
||||
putBoolean(SharedPreferenceUtil.PREF_WIFI_ONLY, false)
|
||||
putBoolean(SharedPreferenceUtil.PREF_SHOW_STORAGE_OPTION, true)
|
||||
}
|
||||
}
|
||||
|
||||
@Before
|
||||
fun waitForIdle() {
|
||||
UiDevice.getInstance(InstrumentationRegistry.getInstrumentation()).waitForIdle()
|
||||
}
|
||||
|
||||
@Test
|
||||
fun initialDownloadTest() {
|
||||
UiThreadStatement.runOnUiThread { activityRule.activity.navigate(R.id.downloadsFragment) }
|
||||
initialDownload {
|
||||
assertLibraryListDisplayed()
|
||||
refreshList()
|
||||
waitForDataToLoad()
|
||||
downloadZimFile()
|
||||
assertStorageConfigureDialogDisplayed()
|
||||
clickYesToConfigureStorage()
|
||||
assertDownloadStart()
|
||||
}
|
||||
}
|
||||
|
||||
@After
|
||||
fun setPrefStorageOption() {
|
||||
PreferenceManager.getDefaultSharedPreferences(context).edit {
|
||||
putBoolean(SharedPreferenceUtil.PREF_SHOW_STORAGE_OPTION, false)
|
||||
}
|
||||
}
|
||||
}
|
@ -218,7 +218,7 @@ class SharedPreferenceUtil @Inject constructor(val context: Context) {
|
||||
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"
|
||||
private const val PREF_SHOW_STORAGE_OPTION = "show_storgae_option"
|
||||
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"
|
||||
private const val PREF_SHOW_HISTORY_ALL_BOOKS = "show_history_current_book"
|
||||
|
@ -18,6 +18,7 @@
|
||||
<ignore regexp=".*TopLevelDestinationRobot.kt.*"/>
|
||||
<ignore regexp=".*ZimHostRobot.kt.*"/>
|
||||
<ignore regexp=".*SearchRobot.kt.*"/>
|
||||
<ignore regexp=".*InitialDownloadRobot.kt.*"/>
|
||||
</issue>
|
||||
<issue id="TypographyEllipsis">
|
||||
<ignore path="**-iw/**.xml" />
|
||||
|
Loading…
x
Reference in New Issue
Block a user