mirror of
https://github.com/kiwix/kiwix-android.git
synced 2025-09-09 15:27:55 -04:00
Refactored the test cases according to compose UI.
This commit is contained in:
parent
7d7f726d51
commit
080e518d2b
@ -29,11 +29,8 @@ import androidx.test.ext.junit.runners.AndroidJUnit4
|
|||||||
import androidx.test.platform.app.InstrumentationRegistry
|
import androidx.test.platform.app.InstrumentationRegistry
|
||||||
import androidx.test.rule.GrantPermissionRule
|
import androidx.test.rule.GrantPermissionRule
|
||||||
import com.adevinta.android.barista.interaction.BaristaClickInteractions.clickOn
|
import com.adevinta.android.barista.interaction.BaristaClickInteractions.clickOn
|
||||||
import com.adevinta.android.barista.interaction.BaristaDialogInteractions
|
|
||||||
import com.adevinta.android.barista.interaction.BaristaMenuClickInteractions.clickMenu
|
import com.adevinta.android.barista.interaction.BaristaMenuClickInteractions.clickMenu
|
||||||
import com.adevinta.android.barista.interaction.BaristaSleepInteractions
|
import com.adevinta.android.barista.interaction.BaristaSleepInteractions
|
||||||
import com.adevinta.android.barista.interaction.BaristaSwipeRefreshInteractions.refresh
|
|
||||||
import org.hamcrest.CoreMatchers
|
|
||||||
import org.junit.After
|
import org.junit.After
|
||||||
import org.junit.Before
|
import org.junit.Before
|
||||||
import org.junit.BeforeClass
|
import org.junit.BeforeClass
|
||||||
@ -110,8 +107,8 @@ class NetworkTest {
|
|||||||
}
|
}
|
||||||
clickOn(string.local_zims)
|
clickOn(string.local_zims)
|
||||||
try {
|
try {
|
||||||
Espresso.onData(CoreMatchers.allOf(ViewMatchers.withId(R.id.zim_swiperefresh)))
|
// Espresso.onData(CoreMatchers.allOf(ViewMatchers.withId(R.id.zim_swiperefresh)))
|
||||||
refresh(R.id.zim_swiperefresh)
|
// refresh(R.id.zim_swiperefresh)
|
||||||
Thread.sleep(500)
|
Thread.sleep(500)
|
||||||
} catch (e: InterruptedException) {
|
} catch (e: InterruptedException) {
|
||||||
e.printStackTrace()
|
e.printStackTrace()
|
||||||
@ -122,21 +119,21 @@ class NetworkTest {
|
|||||||
// onData(withContent("wikipedia_ab_all_2017-03")).inAdapterView(withId(R.id.zimfilelist)).perform(click());
|
// onData(withContent("wikipedia_ab_all_2017-03")).inAdapterView(withId(R.id.zimfilelist)).perform(click());
|
||||||
|
|
||||||
// Find matching zim files on the device
|
// Find matching zim files on the device
|
||||||
try {
|
// try {
|
||||||
val dataInteraction =
|
// val dataInteraction =
|
||||||
Espresso.onData(TestUtils.withContent("wikipedia_ab_all_2017-03"))
|
// Espresso.onData(TestUtils.withContent("wikipedia_ab_all_2017-03"))
|
||||||
.inAdapterView(ViewMatchers.withId(R.id.zimfilelist))
|
// .inAdapterView(ViewMatchers.withId(R.id.zimfilelist))
|
||||||
// TODO how can we get a count of the items matching the dataInteraction?
|
// // TODO how can we get a count of the items matching the dataInteraction?
|
||||||
dataInteraction.atPosition(0).perform(ViewActions.click())
|
// dataInteraction.atPosition(0).perform(ViewActions.click())
|
||||||
clickMenu(string.library)
|
// clickMenu(string.library)
|
||||||
val dataInteraction1 =
|
// val dataInteraction1 =
|
||||||
Espresso.onData(TestUtils.withContent("wikipedia_ab_all_2017-03"))
|
// Espresso.onData(TestUtils.withContent("wikipedia_ab_all_2017-03"))
|
||||||
.inAdapterView(ViewMatchers.withId(R.id.zimfilelist))
|
// .inAdapterView(ViewMatchers.withId(R.id.zimfilelist))
|
||||||
dataInteraction1.atPosition(0).perform(ViewActions.longClick()) // to delete the zim file
|
// dataInteraction1.atPosition(0).perform(ViewActions.longClick()) // to delete the zim file
|
||||||
BaristaDialogInteractions.clickDialogPositiveButton()
|
// BaristaDialogInteractions.clickDialogPositiveButton()
|
||||||
} catch (e: Exception) {
|
// } catch (e: Exception) {
|
||||||
Log.w(NETWORK_TEST_TAG, "failed to interact with local ZIM file: " + e.localizedMessage)
|
// Log.w(NETWORK_TEST_TAG, "failed to interact with local ZIM file: " + e.localizedMessage)
|
||||||
}
|
// }
|
||||||
}
|
}
|
||||||
|
|
||||||
@After fun finish() {
|
@After fun finish() {
|
||||||
|
@ -19,6 +19,9 @@
|
|||||||
package org.kiwix.kiwixmobile.download
|
package org.kiwix.kiwixmobile.download
|
||||||
|
|
||||||
import android.view.View
|
import android.view.View
|
||||||
|
import androidx.compose.ui.test.assertIsDisplayed
|
||||||
|
import androidx.compose.ui.test.junit4.ComposeContentTestRule
|
||||||
|
import androidx.compose.ui.test.onNodeWithTag
|
||||||
import androidx.recyclerview.widget.RecyclerView
|
import androidx.recyclerview.widget.RecyclerView
|
||||||
import androidx.test.espresso.Espresso.onView
|
import androidx.test.espresso.Espresso.onView
|
||||||
import androidx.test.espresso.UiController
|
import androidx.test.espresso.UiController
|
||||||
@ -48,6 +51,7 @@ import org.kiwix.kiwixmobile.core.R.string
|
|||||||
import org.kiwix.kiwixmobile.core.utils.files.Log
|
import org.kiwix.kiwixmobile.core.utils.files.Log
|
||||||
import org.kiwix.kiwixmobile.download.DownloadTest.Companion.KIWIX_DOWNLOAD_TEST
|
import org.kiwix.kiwixmobile.download.DownloadTest.Companion.KIWIX_DOWNLOAD_TEST
|
||||||
import org.kiwix.kiwixmobile.main.KiwixMainActivity
|
import org.kiwix.kiwixmobile.main.KiwixMainActivity
|
||||||
|
import org.kiwix.kiwixmobile.nav.destination.library.local.NO_FILE_TEXT_TESTING_TAG
|
||||||
import org.kiwix.kiwixmobile.testutils.TestUtils
|
import org.kiwix.kiwixmobile.testutils.TestUtils
|
||||||
import org.kiwix.kiwixmobile.testutils.TestUtils.testFlakyView
|
import org.kiwix.kiwixmobile.testutils.TestUtils.testFlakyView
|
||||||
import org.kiwix.kiwixmobile.utils.RecyclerViewMatcher
|
import org.kiwix.kiwixmobile.utils.RecyclerViewMatcher
|
||||||
@ -84,26 +88,28 @@ class DownloadRobot : BaseRobot() {
|
|||||||
try {
|
try {
|
||||||
onView(withText(string.swipe_down_for_library)).check(matches(isDisplayed()))
|
onView(withText(string.swipe_down_for_library)).check(matches(isDisplayed()))
|
||||||
refreshOnlineList()
|
refreshOnlineList()
|
||||||
} catch (e: RuntimeException) {
|
} catch (_: RuntimeException) {
|
||||||
try {
|
try {
|
||||||
// do nothing as currently downloading the online library.
|
// do nothing as currently downloading the online library.
|
||||||
onView(withId(R.id.onlineLibraryProgressLayout)).check(matches(isDisplayed()))
|
onView(withId(R.id.onlineLibraryProgressLayout)).check(matches(isDisplayed()))
|
||||||
} catch (e: RuntimeException) {
|
} catch (_: RuntimeException) {
|
||||||
// if not visible try to get the online library.
|
// if not visible try to get the online library.
|
||||||
refreshOnlineList()
|
refreshOnlineList()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun checkIfZimFileDownloaded() {
|
fun checkIfZimFileDownloaded(composeTestRule: ComposeContentTestRule) {
|
||||||
pauseForBetterTestPerformance()
|
pauseForBetterTestPerformance()
|
||||||
try {
|
try {
|
||||||
testFlakyView({
|
testFlakyView({
|
||||||
onView(withId(R.id.file_management_no_files)).check(matches(isDisplayed()))
|
composeTestRule.runOnIdle {
|
||||||
|
composeTestRule.onNodeWithTag(NO_FILE_TEXT_TESTING_TAG).assertIsDisplayed()
|
||||||
|
}
|
||||||
})
|
})
|
||||||
// if the "No files here" text found that means it failed to download the ZIM file.
|
// if the "No files here" text found that means it failed to download the ZIM file.
|
||||||
Assert.fail("Couldn't download the zim file. The [No files here] text is visible on screen")
|
Assert.fail("Couldn't download the zim file. The [No files here] text is visible on screen")
|
||||||
} catch (e: AssertionFailedError) {
|
} catch (_: AssertionFailedError) {
|
||||||
// check if "No files here" text is not visible on
|
// check if "No files here" text is not visible on
|
||||||
// screen that means zim file is downloaded successfully.
|
// screen that means zim file is downloaded successfully.
|
||||||
}
|
}
|
||||||
@ -175,9 +181,9 @@ class DownloadRobot : BaseRobot() {
|
|||||||
try {
|
try {
|
||||||
onView(withSubstring(context.getString(string.paused_state))).check(matches(isDisplayed()))
|
onView(withSubstring(context.getString(string.paused_state))).check(matches(isDisplayed()))
|
||||||
resumeDownload()
|
resumeDownload()
|
||||||
} catch (e: AssertionFailedError) {
|
} catch (_: AssertionFailedError) {
|
||||||
// do nothing since downloading is In Progress.
|
// do nothing since downloading is In Progress.
|
||||||
} catch (e: RuntimeException) {
|
} catch (_: RuntimeException) {
|
||||||
// do nothing since downloading is In Progress.
|
// do nothing since downloading is In Progress.
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -194,7 +200,7 @@ class DownloadRobot : BaseRobot() {
|
|||||||
private fun clickOnYesButton() {
|
private fun clickOnYesButton() {
|
||||||
try {
|
try {
|
||||||
onView(withText("YES")).perform(click())
|
onView(withText("YES")).perform(click())
|
||||||
} catch (ignore: Exception) {
|
} catch (_: Exception) {
|
||||||
// stop the downloading for Albanian language
|
// stop the downloading for Albanian language
|
||||||
onView(withText("PO")).perform(click())
|
onView(withText("PO")).perform(click())
|
||||||
}
|
}
|
||||||
@ -208,7 +214,7 @@ class DownloadRobot : BaseRobot() {
|
|||||||
assertStopDownloadDialogDisplayed()
|
assertStopDownloadDialogDisplayed()
|
||||||
clickOnYesButton()
|
clickOnYesButton()
|
||||||
pauseForBetterTestPerformance()
|
pauseForBetterTestPerformance()
|
||||||
} catch (e: Exception) {
|
} catch (_: Exception) {
|
||||||
Log.e(
|
Log.e(
|
||||||
KIWIX_DOWNLOAD_TEST,
|
KIWIX_DOWNLOAD_TEST,
|
||||||
"Failed to stop downloading. Probably because it is not downloading the zim file"
|
"Failed to stop downloading. Probably because it is not downloading the zim file"
|
||||||
|
@ -18,6 +18,7 @@
|
|||||||
package org.kiwix.kiwixmobile.download
|
package org.kiwix.kiwixmobile.download
|
||||||
|
|
||||||
import android.util.Log
|
import android.util.Log
|
||||||
|
import androidx.compose.ui.test.junit4.createComposeRule
|
||||||
import androidx.core.content.edit
|
import androidx.core.content.edit
|
||||||
import androidx.lifecycle.Lifecycle
|
import androidx.lifecycle.Lifecycle
|
||||||
import androidx.navigation.fragment.NavHostFragment
|
import androidx.navigation.fragment.NavHostFragment
|
||||||
@ -50,7 +51,6 @@ import org.kiwix.kiwixmobile.core.utils.LanguageUtils.Companion.handleLocaleChan
|
|||||||
import org.kiwix.kiwixmobile.core.utils.SharedPreferenceUtil
|
import org.kiwix.kiwixmobile.core.utils.SharedPreferenceUtil
|
||||||
import org.kiwix.kiwixmobile.main.KiwixMainActivity
|
import org.kiwix.kiwixmobile.main.KiwixMainActivity
|
||||||
import org.kiwix.kiwixmobile.main.topLevel
|
import org.kiwix.kiwixmobile.main.topLevel
|
||||||
import org.kiwix.kiwixmobile.nav.destination.library.LibraryRobot
|
|
||||||
import org.kiwix.kiwixmobile.nav.destination.library.OnlineLibraryFragment
|
import org.kiwix.kiwixmobile.nav.destination.library.OnlineLibraryFragment
|
||||||
import org.kiwix.kiwixmobile.nav.destination.library.library
|
import org.kiwix.kiwixmobile.nav.destination.library.library
|
||||||
import org.kiwix.kiwixmobile.testutils.RetryRule
|
import org.kiwix.kiwixmobile.testutils.RetryRule
|
||||||
@ -68,6 +68,9 @@ class DownloadTest : BaseActivityTest() {
|
|||||||
@JvmField
|
@JvmField
|
||||||
var retryRule = RetryRule()
|
var retryRule = RetryRule()
|
||||||
|
|
||||||
|
@get:Rule
|
||||||
|
val composeTestRule = createComposeRule()
|
||||||
|
|
||||||
private lateinit var kiwixMainActivity: KiwixMainActivity
|
private lateinit var kiwixMainActivity: KiwixMainActivity
|
||||||
|
|
||||||
init {
|
init {
|
||||||
@ -128,9 +131,9 @@ class DownloadTest : BaseActivityTest() {
|
|||||||
// delete all the ZIM files showing in the LocalLibrary
|
// delete all the ZIM files showing in the LocalLibrary
|
||||||
// screen to properly test the scenario.
|
// screen to properly test the scenario.
|
||||||
library {
|
library {
|
||||||
refreshList()
|
refreshList(composeTestRule)
|
||||||
waitUntilZimFilesRefreshing()
|
waitUntilZimFilesRefreshing(composeTestRule)
|
||||||
deleteZimIfExists()
|
deleteZimIfExists(composeTestRule)
|
||||||
}
|
}
|
||||||
downloadRobot {
|
downloadRobot {
|
||||||
clickDownloadOnBottomNav()
|
clickDownloadOnBottomNav()
|
||||||
@ -158,8 +161,8 @@ class DownloadTest : BaseActivityTest() {
|
|||||||
}
|
}
|
||||||
clickLibraryOnBottomNav()
|
clickLibraryOnBottomNav()
|
||||||
// refresh the local library list to show the downloaded zim file
|
// refresh the local library list to show the downloaded zim file
|
||||||
library(LibraryRobot::refreshList)
|
library { refreshList(composeTestRule) }
|
||||||
checkIfZimFileDownloaded()
|
checkIfZimFileDownloaded(composeTestRule)
|
||||||
}
|
}
|
||||||
} catch (e: Exception) {
|
} catch (e: Exception) {
|
||||||
Assert.fail(
|
Assert.fail(
|
||||||
@ -188,9 +191,9 @@ class DownloadTest : BaseActivityTest() {
|
|||||||
// delete all the ZIM files showing in the LocalLibrary
|
// delete all the ZIM files showing in the LocalLibrary
|
||||||
// screen to properly test the scenario.
|
// screen to properly test the scenario.
|
||||||
library {
|
library {
|
||||||
refreshList()
|
refreshList(composeTestRule)
|
||||||
waitUntilZimFilesRefreshing()
|
waitUntilZimFilesRefreshing(composeTestRule)
|
||||||
deleteZimIfExists()
|
deleteZimIfExists(composeTestRule)
|
||||||
}
|
}
|
||||||
downloadRobot {
|
downloadRobot {
|
||||||
// change the application language
|
// change the application language
|
||||||
|
@ -18,6 +18,7 @@
|
|||||||
|
|
||||||
package org.kiwix.kiwixmobile.initial.download
|
package org.kiwix.kiwixmobile.initial.download
|
||||||
|
|
||||||
|
import androidx.compose.ui.test.junit4.createComposeRule
|
||||||
import androidx.core.content.edit
|
import androidx.core.content.edit
|
||||||
import androidx.lifecycle.Lifecycle
|
import androidx.lifecycle.Lifecycle
|
||||||
import androidx.preference.PreferenceManager
|
import androidx.preference.PreferenceManager
|
||||||
@ -57,6 +58,9 @@ class InitialDownloadTest : BaseActivityTest() {
|
|||||||
@JvmField
|
@JvmField
|
||||||
var retryRule = RetryRule()
|
var retryRule = RetryRule()
|
||||||
|
|
||||||
|
@get:Rule
|
||||||
|
val composeTestRule = createComposeRule()
|
||||||
|
|
||||||
init {
|
init {
|
||||||
AccessibilityChecks.enable().apply {
|
AccessibilityChecks.enable().apply {
|
||||||
setRunChecksFromRootView(true)
|
setRunChecksFromRootView(true)
|
||||||
@ -111,9 +115,9 @@ class InitialDownloadTest : BaseActivityTest() {
|
|||||||
// delete all the ZIM files showing in the LocalLibrary
|
// delete all the ZIM files showing in the LocalLibrary
|
||||||
// screen to properly test the scenario.
|
// screen to properly test the scenario.
|
||||||
library {
|
library {
|
||||||
refreshList()
|
refreshList(composeTestRule)
|
||||||
waitUntilZimFilesRefreshing()
|
waitUntilZimFilesRefreshing(composeTestRule)
|
||||||
deleteZimIfExists()
|
deleteZimIfExists(composeTestRule)
|
||||||
}
|
}
|
||||||
initialDownload {
|
initialDownload {
|
||||||
clickDownloadOnBottomNav()
|
clickDownloadOnBottomNav()
|
||||||
|
@ -18,11 +18,12 @@
|
|||||||
|
|
||||||
package org.kiwix.kiwixmobile.localLibrary
|
package org.kiwix.kiwixmobile.localLibrary
|
||||||
|
|
||||||
|
import androidx.compose.ui.test.assertIsDisplayed
|
||||||
|
import androidx.compose.ui.test.junit4.ComposeContentTestRule
|
||||||
|
import androidx.compose.ui.test.onNodeWithTag
|
||||||
import androidx.test.espresso.Espresso.onView
|
import androidx.test.espresso.Espresso.onView
|
||||||
import androidx.test.espresso.action.ViewActions.click
|
import androidx.test.espresso.action.ViewActions.click
|
||||||
import androidx.test.espresso.assertion.ViewAssertions
|
|
||||||
import androidx.test.espresso.assertion.ViewAssertions.doesNotExist
|
import androidx.test.espresso.assertion.ViewAssertions.doesNotExist
|
||||||
import androidx.test.espresso.matcher.ViewMatchers
|
|
||||||
import androidx.test.espresso.matcher.ViewMatchers.withText
|
import androidx.test.espresso.matcher.ViewMatchers.withText
|
||||||
import androidx.test.espresso.web.sugar.Web
|
import androidx.test.espresso.web.sugar.Web
|
||||||
import androidx.test.espresso.web.webdriver.DriverAtoms
|
import androidx.test.espresso.web.webdriver.DriverAtoms
|
||||||
@ -35,6 +36,7 @@ import org.kiwix.kiwixmobile.Findable
|
|||||||
import org.kiwix.kiwixmobile.Findable.StringId.TextId
|
import org.kiwix.kiwixmobile.Findable.StringId.TextId
|
||||||
import org.kiwix.kiwixmobile.R.id
|
import org.kiwix.kiwixmobile.R.id
|
||||||
import org.kiwix.kiwixmobile.core.R
|
import org.kiwix.kiwixmobile.core.R
|
||||||
|
import org.kiwix.kiwixmobile.nav.destination.library.local.NO_FILE_TEXT_TESTING_TAG
|
||||||
import org.kiwix.kiwixmobile.testutils.TestUtils
|
import org.kiwix.kiwixmobile.testutils.TestUtils
|
||||||
import org.kiwix.kiwixmobile.testutils.TestUtils.testFlakyView
|
import org.kiwix.kiwixmobile.testutils.TestUtils.testFlakyView
|
||||||
import org.kiwix.kiwixmobile.utils.RecyclerViewMatcher
|
import org.kiwix.kiwixmobile.utils.RecyclerViewMatcher
|
||||||
@ -102,15 +104,11 @@ class CopyMoveFileHandlerRobot : BaseRobot() {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
fun assertZimFileAddedInTheLocalLibrary() {
|
fun assertZimFileAddedInTheLocalLibrary(composeTestRule: ComposeContentTestRule) {
|
||||||
try {
|
try {
|
||||||
onView(ViewMatchers.withId(id.file_management_no_files)).check(
|
composeTestRule.onNodeWithTag(NO_FILE_TEXT_TESTING_TAG).assertIsDisplayed()
|
||||||
ViewAssertions.matches(
|
|
||||||
ViewMatchers.isDisplayed()
|
|
||||||
)
|
|
||||||
)
|
|
||||||
throw RuntimeException("ZimFile not added in the local library")
|
throw RuntimeException("ZimFile not added in the local library")
|
||||||
} catch (e: AssertionFailedError) {
|
} catch (_: AssertionFailedError) {
|
||||||
// do nothing zim file is added in the local library
|
// do nothing zim file is added in the local library
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -20,6 +20,7 @@ package org.kiwix.kiwixmobile.localLibrary
|
|||||||
|
|
||||||
import android.net.Uri
|
import android.net.Uri
|
||||||
import android.os.Build
|
import android.os.Build
|
||||||
|
import androidx.compose.ui.test.junit4.createComposeRule
|
||||||
import androidx.core.content.edit
|
import androidx.core.content.edit
|
||||||
import androidx.documentfile.provider.DocumentFile
|
import androidx.documentfile.provider.DocumentFile
|
||||||
import androidx.lifecycle.Lifecycle
|
import androidx.lifecycle.Lifecycle
|
||||||
@ -48,7 +49,7 @@ import org.kiwix.kiwixmobile.core.utils.SharedPreferenceUtil
|
|||||||
import org.kiwix.kiwixmobile.core.utils.dialog.AlertDialogShower
|
import org.kiwix.kiwixmobile.core.utils.dialog.AlertDialogShower
|
||||||
import org.kiwix.kiwixmobile.main.KiwixMainActivity
|
import org.kiwix.kiwixmobile.main.KiwixMainActivity
|
||||||
import org.kiwix.kiwixmobile.nav.destination.library.CopyMoveFileHandler
|
import org.kiwix.kiwixmobile.nav.destination.library.CopyMoveFileHandler
|
||||||
import org.kiwix.kiwixmobile.nav.destination.library.LocalLibraryFragment
|
import org.kiwix.kiwixmobile.nav.destination.library.local.LocalLibraryFragment
|
||||||
import org.kiwix.kiwixmobile.testutils.RetryRule
|
import org.kiwix.kiwixmobile.testutils.RetryRule
|
||||||
import org.kiwix.kiwixmobile.testutils.TestUtils
|
import org.kiwix.kiwixmobile.testutils.TestUtils
|
||||||
import org.kiwix.kiwixmobile.zimManager.Fat32Checker
|
import org.kiwix.kiwixmobile.zimManager.Fat32Checker
|
||||||
@ -62,6 +63,9 @@ class CopyMoveFileHandlerTest : BaseActivityTest() {
|
|||||||
@JvmField
|
@JvmField
|
||||||
var retryRule = RetryRule()
|
var retryRule = RetryRule()
|
||||||
|
|
||||||
|
@get:Rule
|
||||||
|
val composeTestRule = createComposeRule()
|
||||||
|
|
||||||
private lateinit var sharedPreferenceUtil: SharedPreferenceUtil
|
private lateinit var sharedPreferenceUtil: SharedPreferenceUtil
|
||||||
private lateinit var kiwixMainActivity: KiwixMainActivity
|
private lateinit var kiwixMainActivity: KiwixMainActivity
|
||||||
private lateinit var selectedFile: File
|
private lateinit var selectedFile: File
|
||||||
@ -191,7 +195,7 @@ class CopyMoveFileHandlerTest : BaseActivityTest() {
|
|||||||
UiThreadStatement.runOnUiThread {
|
UiThreadStatement.runOnUiThread {
|
||||||
kiwixMainActivity.navigate(R.id.libraryFragment)
|
kiwixMainActivity.navigate(R.id.libraryFragment)
|
||||||
}
|
}
|
||||||
copyMoveFileHandler(CopyMoveFileHandlerRobot::assertZimFileAddedInTheLocalLibrary)
|
copyMoveFileHandler { assertZimFileAddedInTheLocalLibrary(composeTestRule) }
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun showMoveFileToPublicDirectoryDialog() {
|
private fun showMoveFileToPublicDirectoryDialog() {
|
||||||
|
@ -26,14 +26,14 @@ import android.net.Uri
|
|||||||
import android.os.Build
|
import android.os.Build
|
||||||
import android.provider.MediaStore
|
import android.provider.MediaStore
|
||||||
import android.util.Log
|
import android.util.Log
|
||||||
|
import androidx.compose.ui.test.junit4.createComposeRule
|
||||||
|
import androidx.compose.ui.test.onNodeWithTag
|
||||||
|
import androidx.compose.ui.test.performClick
|
||||||
import androidx.core.content.edit
|
import androidx.core.content.edit
|
||||||
import androidx.lifecycle.Lifecycle
|
import androidx.lifecycle.Lifecycle
|
||||||
import androidx.preference.PreferenceManager
|
import androidx.preference.PreferenceManager
|
||||||
import androidx.test.core.app.ActivityScenario
|
import androidx.test.core.app.ActivityScenario
|
||||||
import androidx.test.espresso.Espresso
|
|
||||||
import androidx.test.espresso.action.ViewActions
|
|
||||||
import androidx.test.espresso.intent.Intents
|
import androidx.test.espresso.intent.Intents
|
||||||
import androidx.test.espresso.matcher.ViewMatchers.withId
|
|
||||||
import androidx.test.ext.junit.runners.AndroidJUnit4
|
import androidx.test.ext.junit.runners.AndroidJUnit4
|
||||||
import androidx.test.platform.app.InstrumentationRegistry
|
import androidx.test.platform.app.InstrumentationRegistry
|
||||||
import androidx.test.uiautomator.By
|
import androidx.test.uiautomator.By
|
||||||
@ -49,6 +49,7 @@ import org.kiwix.kiwixmobile.R
|
|||||||
import org.kiwix.kiwixmobile.core.utils.LanguageUtils
|
import org.kiwix.kiwixmobile.core.utils.LanguageUtils
|
||||||
import org.kiwix.kiwixmobile.core.utils.SharedPreferenceUtil
|
import org.kiwix.kiwixmobile.core.utils.SharedPreferenceUtil
|
||||||
import org.kiwix.kiwixmobile.main.KiwixMainActivity
|
import org.kiwix.kiwixmobile.main.KiwixMainActivity
|
||||||
|
import org.kiwix.kiwixmobile.nav.destination.library.local.SELECT_FILE_BUTTON_TESTING_TAG
|
||||||
import org.kiwix.kiwixmobile.testutils.RetryRule
|
import org.kiwix.kiwixmobile.testutils.RetryRule
|
||||||
import org.kiwix.kiwixmobile.testutils.TestUtils
|
import org.kiwix.kiwixmobile.testutils.TestUtils
|
||||||
import java.io.File
|
import java.io.File
|
||||||
@ -61,6 +62,9 @@ class OpeningFilesFromStorageTest : BaseActivityTest() {
|
|||||||
@JvmField
|
@JvmField
|
||||||
var retryRule = RetryRule()
|
var retryRule = RetryRule()
|
||||||
|
|
||||||
|
@get:Rule
|
||||||
|
val composeTestRule = createComposeRule()
|
||||||
|
|
||||||
private lateinit var sharedPreferenceUtil: SharedPreferenceUtil
|
private lateinit var sharedPreferenceUtil: SharedPreferenceUtil
|
||||||
private lateinit var kiwixMainActivity: KiwixMainActivity
|
private lateinit var kiwixMainActivity: KiwixMainActivity
|
||||||
private lateinit var uiDevice: UiDevice
|
private lateinit var uiDevice: UiDevice
|
||||||
@ -112,7 +116,7 @@ class OpeningFilesFromStorageTest : BaseActivityTest() {
|
|||||||
try {
|
try {
|
||||||
sharedPreferenceUtil.shouldShowStorageSelectionDialog = true
|
sharedPreferenceUtil.shouldShowStorageSelectionDialog = true
|
||||||
// open file picker to select a file to test the real scenario.
|
// open file picker to select a file to test the real scenario.
|
||||||
Espresso.onView(withId(R.id.select_file)).perform(ViewActions.click())
|
composeTestRule.onNodeWithTag(SELECT_FILE_BUTTON_TESTING_TAG).performClick()
|
||||||
uiDevice.findObject(By.textContains(fileName)).click()
|
uiDevice.findObject(By.textContains(fileName)).click()
|
||||||
|
|
||||||
copyMoveFileHandler {
|
copyMoveFileHandler {
|
||||||
|
@ -41,7 +41,7 @@ import org.kiwix.kiwixmobile.BaseActivityTest
|
|||||||
import org.kiwix.kiwixmobile.R
|
import org.kiwix.kiwixmobile.R
|
||||||
import org.kiwix.kiwixmobile.core.utils.LanguageUtils
|
import org.kiwix.kiwixmobile.core.utils.LanguageUtils
|
||||||
import org.kiwix.kiwixmobile.core.utils.SharedPreferenceUtil
|
import org.kiwix.kiwixmobile.core.utils.SharedPreferenceUtil
|
||||||
import org.kiwix.kiwixmobile.nav.destination.library.LocalLibraryFragmentDirections
|
import org.kiwix.kiwixmobile.nav.destination.library.local.LocalLibraryFragmentDirections
|
||||||
import org.kiwix.kiwixmobile.nav.destination.reader.KiwixReaderFragment
|
import org.kiwix.kiwixmobile.nav.destination.reader.KiwixReaderFragment
|
||||||
import org.kiwix.kiwixmobile.settings.SettingsRobot
|
import org.kiwix.kiwixmobile.settings.SettingsRobot
|
||||||
import org.kiwix.kiwixmobile.settings.settingsRobo
|
import org.kiwix.kiwixmobile.settings.settingsRobo
|
||||||
|
@ -18,29 +18,33 @@
|
|||||||
|
|
||||||
package org.kiwix.kiwixmobile.nav.destination.library
|
package org.kiwix.kiwixmobile.nav.destination.library
|
||||||
|
|
||||||
|
import androidx.compose.ui.test.assertIsDisplayed
|
||||||
|
import androidx.compose.ui.test.assertIsNotDisplayed
|
||||||
|
import androidx.compose.ui.test.junit4.ComposeContentTestRule
|
||||||
|
import androidx.compose.ui.test.onNodeWithTag
|
||||||
import androidx.recyclerview.widget.RecyclerView.ViewHolder
|
import androidx.recyclerview.widget.RecyclerView.ViewHolder
|
||||||
import androidx.test.espresso.Espresso.onView
|
import androidx.test.espresso.Espresso.onView
|
||||||
import androidx.test.espresso.action.ViewActions.click
|
import androidx.test.espresso.action.ViewActions.click
|
||||||
import androidx.test.espresso.action.ViewActions.longClick
|
import androidx.test.espresso.action.ViewActions.longClick
|
||||||
import androidx.test.espresso.assertion.ViewAssertions.matches
|
|
||||||
import androidx.test.espresso.contrib.RecyclerViewActions.actionOnItemAtPosition
|
import androidx.test.espresso.contrib.RecyclerViewActions.actionOnItemAtPosition
|
||||||
import androidx.test.espresso.contrib.RecyclerViewActions.scrollToPosition
|
import androidx.test.espresso.contrib.RecyclerViewActions.scrollToPosition
|
||||||
import androidx.test.espresso.matcher.RootMatchers.isDialog
|
import androidx.test.espresso.matcher.RootMatchers.isDialog
|
||||||
import androidx.test.espresso.matcher.ViewMatchers.isDisplayed
|
|
||||||
import androidx.test.espresso.matcher.ViewMatchers.withId
|
import androidx.test.espresso.matcher.ViewMatchers.withId
|
||||||
import androidx.test.espresso.matcher.ViewMatchers.withText
|
import androidx.test.espresso.matcher.ViewMatchers.withText
|
||||||
import applyWithViewHierarchyPrinting
|
import applyWithViewHierarchyPrinting
|
||||||
import com.adevinta.android.barista.interaction.BaristaSleepInteractions
|
import com.adevinta.android.barista.interaction.BaristaSleepInteractions
|
||||||
import com.adevinta.android.barista.interaction.BaristaSwipeRefreshInteractions.refresh
|
|
||||||
import junit.framework.AssertionFailedError
|
import junit.framework.AssertionFailedError
|
||||||
import org.hamcrest.Matchers.not
|
|
||||||
import org.kiwix.kiwixmobile.BaseRobot
|
import org.kiwix.kiwixmobile.BaseRobot
|
||||||
import org.kiwix.kiwixmobile.Findable.ViewId
|
import org.kiwix.kiwixmobile.Findable.ViewId
|
||||||
import org.kiwix.kiwixmobile.R
|
import org.kiwix.kiwixmobile.R
|
||||||
import org.kiwix.kiwixmobile.core.utils.files.Log
|
import org.kiwix.kiwixmobile.core.utils.files.Log
|
||||||
import org.kiwix.kiwixmobile.localFileTransfer.LocalFileTransferRobot
|
import org.kiwix.kiwixmobile.localFileTransfer.LocalFileTransferRobot
|
||||||
import org.kiwix.kiwixmobile.localFileTransfer.localFileTransfer
|
import org.kiwix.kiwixmobile.localFileTransfer.localFileTransfer
|
||||||
|
import org.kiwix.kiwixmobile.nav.destination.library.local.BOOK_LIST_TESTING_TAG
|
||||||
|
import org.kiwix.kiwixmobile.nav.destination.library.local.CONTENT_LOADING_PROGRESSBAR_TESTING_TAG
|
||||||
|
import org.kiwix.kiwixmobile.nav.destination.library.local.NO_FILE_TEXT_TESTING_TAG
|
||||||
import org.kiwix.kiwixmobile.testutils.TestUtils
|
import org.kiwix.kiwixmobile.testutils.TestUtils
|
||||||
|
import org.kiwix.kiwixmobile.testutils.TestUtils.refresh
|
||||||
import org.kiwix.kiwixmobile.testutils.TestUtils.testFlakyView
|
import org.kiwix.kiwixmobile.testutils.TestUtils.testFlakyView
|
||||||
import org.kiwix.kiwixmobile.utils.RecyclerViewItemCount
|
import org.kiwix.kiwixmobile.utils.RecyclerViewItemCount
|
||||||
|
|
||||||
@ -58,25 +62,32 @@ class LibraryRobot : BaseRobot() {
|
|||||||
localFileTransfer(func)
|
localFileTransfer(func)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun assertLibraryListDisplayed() {
|
fun assertLibraryListDisplayed(composeTestRule: ComposeContentTestRule) {
|
||||||
isVisible(ViewId(R.id.zimfilelist))
|
testFlakyView({
|
||||||
|
composeTestRule.runOnIdle {
|
||||||
|
composeTestRule.onNodeWithTag(BOOK_LIST_TESTING_TAG).assertIsDisplayed()
|
||||||
|
}
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun assertNoFilesTextDisplayed() {
|
private fun assertNoFilesTextDisplayed(composeTestRule: ComposeContentTestRule) {
|
||||||
pauseForBetterTestPerformance()
|
testFlakyView({
|
||||||
testFlakyView({ isVisible(ViewId(R.id.file_management_no_files)) })
|
composeTestRule.runOnIdle {
|
||||||
|
composeTestRule.onNodeWithTag(NO_FILE_TEXT_TESTING_TAG).assertIsDisplayed()
|
||||||
|
}
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
fun refreshList() {
|
fun refreshList(composeTestRule: ComposeContentTestRule) {
|
||||||
pauseForBetterTestPerformance()
|
composeTestRule.runOnIdle {
|
||||||
try {
|
try {
|
||||||
onView(withId(R.id.file_management_no_files)).check(matches(isDisplayed()))
|
composeTestRule.onNodeWithTag(NO_FILE_TEXT_TESTING_TAG).assertIsDisplayed()
|
||||||
refresh(R.id.zim_swiperefresh)
|
composeTestRule.refresh()
|
||||||
} catch (ignore: AssertionFailedError) {
|
} catch (_: AssertionFailedError) {
|
||||||
try {
|
try {
|
||||||
onView(withId(R.id.zimfilelist)).check(matches(isDisplayed()))
|
composeTestRule.onNodeWithTag(BOOK_LIST_TESTING_TAG).assertIsDisplayed()
|
||||||
refresh(R.id.zim_swiperefresh)
|
composeTestRule.refresh()
|
||||||
} catch (e: AssertionFailedError) {
|
} catch (_: AssertionFailedError) {
|
||||||
Log.i(
|
Log.i(
|
||||||
"LOCAL_LIBRARY",
|
"LOCAL_LIBRARY",
|
||||||
"No need to refresh the data, since there is no files found"
|
"No need to refresh the data, since there is no files found"
|
||||||
@ -84,20 +95,22 @@ class LibraryRobot : BaseRobot() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
fun waitUntilZimFilesRefreshing() {
|
fun waitUntilZimFilesRefreshing(composeTestRule: ComposeContentTestRule) {
|
||||||
testFlakyView({
|
testFlakyView({
|
||||||
onView(withId(R.id.scanning_progress_view)).check(matches(not(isDisplayed())))
|
composeTestRule.onNodeWithTag(CONTENT_LOADING_PROGRESSBAR_TESTING_TAG)
|
||||||
|
.assertIsNotDisplayed()
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
fun deleteZimIfExists() {
|
fun deleteZimIfExists(composeTestRule: ComposeContentTestRule) {
|
||||||
try {
|
try {
|
||||||
try {
|
try {
|
||||||
onView(withId(R.id.file_management_no_files)).check(matches(isDisplayed()))
|
composeTestRule.onNodeWithTag(NO_FILE_TEXT_TESTING_TAG).assertIsDisplayed()
|
||||||
// if this view is displaying then we do not need to run the further code.
|
// if this view is displaying then we do not need to run the further code.
|
||||||
return
|
return
|
||||||
} catch (e: AssertionFailedError) {
|
} catch (_: AssertionFailedError) {
|
||||||
Log.e("DELETE_ZIM_FILE", "Zim files found in local library so we are deleting them")
|
Log.e("DELETE_ZIM_FILE", "Zim files found in local library so we are deleting them")
|
||||||
}
|
}
|
||||||
val recyclerViewId: Int = R.id.zimfilelist
|
val recyclerViewId: Int = R.id.zimfilelist
|
||||||
@ -114,7 +127,7 @@ class LibraryRobot : BaseRobot() {
|
|||||||
clickOnFileDeleteIcon()
|
clickOnFileDeleteIcon()
|
||||||
clickOnDeleteZimFile()
|
clickOnDeleteZimFile()
|
||||||
pauseForBetterTestPerformance()
|
pauseForBetterTestPerformance()
|
||||||
assertNoFilesTextDisplayed()
|
assertNoFilesTextDisplayed(composeTestRule)
|
||||||
} catch (e: Exception) {
|
} catch (e: Exception) {
|
||||||
Log.i(
|
Log.i(
|
||||||
"TEST_DELETE_ZIM",
|
"TEST_DELETE_ZIM",
|
||||||
|
@ -18,6 +18,7 @@
|
|||||||
|
|
||||||
package org.kiwix.kiwixmobile.nav.destination.library
|
package org.kiwix.kiwixmobile.nav.destination.library
|
||||||
|
|
||||||
|
import androidx.compose.ui.test.junit4.createComposeRule
|
||||||
import androidx.core.content.edit
|
import androidx.core.content.edit
|
||||||
import androidx.lifecycle.Lifecycle
|
import androidx.lifecycle.Lifecycle
|
||||||
import androidx.preference.PreferenceManager
|
import androidx.preference.PreferenceManager
|
||||||
@ -53,6 +54,9 @@ class LocalLibraryTest : BaseActivityTest() {
|
|||||||
@JvmField
|
@JvmField
|
||||||
var retryRule = RetryRule()
|
var retryRule = RetryRule()
|
||||||
|
|
||||||
|
@get:Rule
|
||||||
|
val composeTestRule = createComposeRule()
|
||||||
|
|
||||||
init {
|
init {
|
||||||
AccessibilityChecks.enable().apply {
|
AccessibilityChecks.enable().apply {
|
||||||
setRunChecksFromRootView(true)
|
setRunChecksFromRootView(true)
|
||||||
@ -112,9 +116,9 @@ class LocalLibraryTest : BaseActivityTest() {
|
|||||||
it.navigate(R.id.libraryFragment)
|
it.navigate(R.id.libraryFragment)
|
||||||
}
|
}
|
||||||
library {
|
library {
|
||||||
refreshList()
|
refreshList(composeTestRule)
|
||||||
waitUntilZimFilesRefreshing()
|
waitUntilZimFilesRefreshing(composeTestRule)
|
||||||
deleteZimIfExists()
|
deleteZimIfExists(composeTestRule)
|
||||||
}
|
}
|
||||||
// load a zim file to test, After downloading zim file library list is visible or not
|
// load a zim file to test, After downloading zim file library list is visible or not
|
||||||
val loadFileStream =
|
val loadFileStream =
|
||||||
@ -137,8 +141,8 @@ class LocalLibraryTest : BaseActivityTest() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
library {
|
library {
|
||||||
refreshList()
|
refreshList(composeTestRule)
|
||||||
assertLibraryListDisplayed()
|
assertLibraryListDisplayed(composeTestRule)
|
||||||
}
|
}
|
||||||
LeakAssertions.assertNoLeaks()
|
LeakAssertions.assertNoLeaks()
|
||||||
}
|
}
|
||||||
|
@ -48,7 +48,7 @@ import org.kiwix.kiwixmobile.R
|
|||||||
import org.kiwix.kiwixmobile.core.utils.LanguageUtils.Companion.handleLocaleChange
|
import org.kiwix.kiwixmobile.core.utils.LanguageUtils.Companion.handleLocaleChange
|
||||||
import org.kiwix.kiwixmobile.core.utils.SharedPreferenceUtil
|
import org.kiwix.kiwixmobile.core.utils.SharedPreferenceUtil
|
||||||
import org.kiwix.kiwixmobile.main.KiwixMainActivity
|
import org.kiwix.kiwixmobile.main.KiwixMainActivity
|
||||||
import org.kiwix.kiwixmobile.nav.destination.library.LocalLibraryFragmentDirections
|
import org.kiwix.kiwixmobile.nav.destination.library.local.LocalLibraryFragmentDirections
|
||||||
import org.kiwix.kiwixmobile.nav.destination.library.library
|
import org.kiwix.kiwixmobile.nav.destination.library.library
|
||||||
import org.kiwix.kiwixmobile.testutils.RetryRule
|
import org.kiwix.kiwixmobile.testutils.RetryRule
|
||||||
import org.kiwix.kiwixmobile.testutils.TestUtils
|
import org.kiwix.kiwixmobile.testutils.TestUtils
|
||||||
@ -161,9 +161,9 @@ class NoteFragmentTest : BaseActivityTest() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
library {
|
library {
|
||||||
refreshList()
|
refreshList(composeTestRule)
|
||||||
waitUntilZimFilesRefreshing()
|
waitUntilZimFilesRefreshing(composeTestRule)
|
||||||
deleteZimIfExists()
|
deleteZimIfExists(composeTestRule)
|
||||||
}
|
}
|
||||||
|
|
||||||
note {
|
note {
|
||||||
|
@ -44,7 +44,7 @@ import org.kiwix.kiwixmobile.core.utils.LanguageUtils.Companion.handleLocaleChan
|
|||||||
import org.kiwix.kiwixmobile.core.utils.SharedPreferenceUtil
|
import org.kiwix.kiwixmobile.core.utils.SharedPreferenceUtil
|
||||||
import org.kiwix.kiwixmobile.main.KiwixMainActivity
|
import org.kiwix.kiwixmobile.main.KiwixMainActivity
|
||||||
import org.kiwix.kiwixmobile.main.topLevel
|
import org.kiwix.kiwixmobile.main.topLevel
|
||||||
import org.kiwix.kiwixmobile.nav.destination.library.LocalLibraryFragmentDirections
|
import org.kiwix.kiwixmobile.nav.destination.library.local.LocalLibraryFragmentDirections
|
||||||
import org.kiwix.kiwixmobile.testutils.RetryRule
|
import org.kiwix.kiwixmobile.testutils.RetryRule
|
||||||
import org.kiwix.kiwixmobile.testutils.TestUtils
|
import org.kiwix.kiwixmobile.testutils.TestUtils
|
||||||
import org.kiwix.libkiwix.Book
|
import org.kiwix.libkiwix.Book
|
||||||
|
@ -43,7 +43,7 @@ import org.kiwix.kiwixmobile.R
|
|||||||
import org.kiwix.kiwixmobile.core.utils.LanguageUtils.Companion.handleLocaleChange
|
import org.kiwix.kiwixmobile.core.utils.LanguageUtils.Companion.handleLocaleChange
|
||||||
import org.kiwix.kiwixmobile.core.utils.SharedPreferenceUtil
|
import org.kiwix.kiwixmobile.core.utils.SharedPreferenceUtil
|
||||||
import org.kiwix.kiwixmobile.main.KiwixMainActivity
|
import org.kiwix.kiwixmobile.main.KiwixMainActivity
|
||||||
import org.kiwix.kiwixmobile.nav.destination.library.LocalLibraryFragmentDirections
|
import org.kiwix.kiwixmobile.nav.destination.library.local.LocalLibraryFragmentDirections
|
||||||
import org.kiwix.kiwixmobile.testutils.RetryRule
|
import org.kiwix.kiwixmobile.testutils.RetryRule
|
||||||
import org.kiwix.kiwixmobile.testutils.TestUtils
|
import org.kiwix.kiwixmobile.testutils.TestUtils
|
||||||
import org.kiwix.kiwixmobile.testutils.TestUtils.closeSystemDialogs
|
import org.kiwix.kiwixmobile.testutils.TestUtils.closeSystemDialogs
|
||||||
|
@ -45,7 +45,7 @@ import org.kiwix.kiwixmobile.R
|
|||||||
import org.kiwix.kiwixmobile.core.utils.LanguageUtils.Companion.handleLocaleChange
|
import org.kiwix.kiwixmobile.core.utils.LanguageUtils.Companion.handleLocaleChange
|
||||||
import org.kiwix.kiwixmobile.core.utils.SharedPreferenceUtil
|
import org.kiwix.kiwixmobile.core.utils.SharedPreferenceUtil
|
||||||
import org.kiwix.kiwixmobile.main.KiwixMainActivity
|
import org.kiwix.kiwixmobile.main.KiwixMainActivity
|
||||||
import org.kiwix.kiwixmobile.nav.destination.library.LocalLibraryFragmentDirections
|
import org.kiwix.kiwixmobile.nav.destination.library.local.LocalLibraryFragmentDirections
|
||||||
import org.kiwix.kiwixmobile.testutils.RetryRule
|
import org.kiwix.kiwixmobile.testutils.RetryRule
|
||||||
import org.kiwix.kiwixmobile.testutils.TestUtils
|
import org.kiwix.kiwixmobile.testutils.TestUtils
|
||||||
import org.kiwix.kiwixmobile.testutils.TestUtils.closeSystemDialogs
|
import org.kiwix.kiwixmobile.testutils.TestUtils.closeSystemDialogs
|
||||||
|
@ -47,7 +47,7 @@ import org.kiwix.kiwixmobile.core.reader.ZimReaderSource
|
|||||||
import org.kiwix.kiwixmobile.core.utils.LanguageUtils.Companion.handleLocaleChange
|
import org.kiwix.kiwixmobile.core.utils.LanguageUtils.Companion.handleLocaleChange
|
||||||
import org.kiwix.kiwixmobile.core.utils.SharedPreferenceUtil
|
import org.kiwix.kiwixmobile.core.utils.SharedPreferenceUtil
|
||||||
import org.kiwix.kiwixmobile.main.KiwixMainActivity
|
import org.kiwix.kiwixmobile.main.KiwixMainActivity
|
||||||
import org.kiwix.kiwixmobile.nav.destination.library.LocalLibraryFragmentDirections
|
import org.kiwix.kiwixmobile.nav.destination.library.local.LocalLibraryFragmentDirections
|
||||||
import org.kiwix.kiwixmobile.page.history.navigationHistory
|
import org.kiwix.kiwixmobile.page.history.navigationHistory
|
||||||
import org.kiwix.kiwixmobile.testutils.RetryRule
|
import org.kiwix.kiwixmobile.testutils.RetryRule
|
||||||
import org.kiwix.kiwixmobile.testutils.TestUtils
|
import org.kiwix.kiwixmobile.testutils.TestUtils
|
||||||
|
@ -52,7 +52,7 @@ import org.kiwix.kiwixmobile.core.search.viewmodel.Action
|
|||||||
import org.kiwix.kiwixmobile.core.utils.LanguageUtils.Companion.handleLocaleChange
|
import org.kiwix.kiwixmobile.core.utils.LanguageUtils.Companion.handleLocaleChange
|
||||||
import org.kiwix.kiwixmobile.core.utils.SharedPreferenceUtil
|
import org.kiwix.kiwixmobile.core.utils.SharedPreferenceUtil
|
||||||
import org.kiwix.kiwixmobile.main.KiwixMainActivity
|
import org.kiwix.kiwixmobile.main.KiwixMainActivity
|
||||||
import org.kiwix.kiwixmobile.nav.destination.library.LocalLibraryFragmentDirections.actionNavigationLibraryToNavigationReader
|
import org.kiwix.kiwixmobile.nav.destination.library.local.LocalLibraryFragmentDirections.actionNavigationLibraryToNavigationReader
|
||||||
import org.kiwix.kiwixmobile.testutils.RetryRule
|
import org.kiwix.kiwixmobile.testutils.RetryRule
|
||||||
import org.kiwix.kiwixmobile.testutils.TestUtils
|
import org.kiwix.kiwixmobile.testutils.TestUtils
|
||||||
import org.kiwix.kiwixmobile.testutils.TestUtils.closeSystemDialogs
|
import org.kiwix.kiwixmobile.testutils.TestUtils.closeSystemDialogs
|
||||||
|
@ -25,6 +25,10 @@ import android.content.pm.PackageManager
|
|||||||
import android.graphics.Bitmap
|
import android.graphics.Bitmap
|
||||||
import android.os.Build
|
import android.os.Build
|
||||||
import android.os.Environment
|
import android.os.Environment
|
||||||
|
import androidx.compose.ui.test.junit4.ComposeContentTestRule
|
||||||
|
import androidx.compose.ui.test.onNodeWithTag
|
||||||
|
import androidx.compose.ui.test.performTouchInput
|
||||||
|
import androidx.compose.ui.test.swipeDown
|
||||||
import androidx.core.content.ContextCompat
|
import androidx.core.content.ContextCompat
|
||||||
import androidx.test.core.app.canTakeScreenshot
|
import androidx.test.core.app.canTakeScreenshot
|
||||||
import androidx.test.core.app.takeScreenshot
|
import androidx.test.core.app.takeScreenshot
|
||||||
@ -45,6 +49,7 @@ import org.kiwix.kiwixmobile.core.di.modules.CONNECTION_TIMEOUT
|
|||||||
import org.kiwix.kiwixmobile.core.di.modules.READ_TIMEOUT
|
import org.kiwix.kiwixmobile.core.di.modules.READ_TIMEOUT
|
||||||
import org.kiwix.kiwixmobile.core.di.modules.USER_AGENT
|
import org.kiwix.kiwixmobile.core.di.modules.USER_AGENT
|
||||||
import org.kiwix.kiwixmobile.core.entity.LibraryNetworkEntity
|
import org.kiwix.kiwixmobile.core.entity.LibraryNetworkEntity
|
||||||
|
import org.kiwix.kiwixmobile.core.ui.components.SWIPE_REFRESH_TESTING_TAG
|
||||||
import org.kiwix.kiwixmobile.core.utils.files.Log
|
import org.kiwix.kiwixmobile.core.utils.files.Log
|
||||||
import java.io.File
|
import java.io.File
|
||||||
import java.io.FileNotFoundException
|
import java.io.FileNotFoundException
|
||||||
@ -252,4 +257,9 @@ object TestUtils {
|
|||||||
.callTimeout(CALL_TIMEOUT, TimeUnit.SECONDS)
|
.callTimeout(CALL_TIMEOUT, TimeUnit.SECONDS)
|
||||||
.addNetworkInterceptor(UserAgentInterceptor(USER_AGENT))
|
.addNetworkInterceptor(UserAgentInterceptor(USER_AGENT))
|
||||||
.build()
|
.build()
|
||||||
|
|
||||||
|
fun ComposeContentTestRule.refresh() {
|
||||||
|
onNodeWithTag(SWIPE_REFRESH_TESTING_TAG)
|
||||||
|
.performTouchInput { swipeDown() }
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -141,14 +141,14 @@ class ZimHostFragmentTest {
|
|||||||
// delete all the ZIM files showing in the LocalLibrary
|
// delete all the ZIM files showing in the LocalLibrary
|
||||||
// screen to properly test the scenario.
|
// screen to properly test the scenario.
|
||||||
library {
|
library {
|
||||||
refreshList()
|
refreshList(composeTestRule)
|
||||||
waitUntilZimFilesRefreshing()
|
waitUntilZimFilesRefreshing(composeTestRule)
|
||||||
deleteZimIfExists()
|
deleteZimIfExists(composeTestRule)
|
||||||
}
|
}
|
||||||
loadZimFileInApplication("testzim.zim")
|
loadZimFileInApplication("testzim.zim")
|
||||||
loadZimFileInApplication("small.zim")
|
loadZimFileInApplication("small.zim")
|
||||||
zimHost {
|
zimHost {
|
||||||
refreshLibraryList()
|
refreshLibraryList(composeTestRule)
|
||||||
assertZimFilesLoaded()
|
assertZimFilesLoaded()
|
||||||
openZimHostFragment()
|
openZimHostFragment()
|
||||||
|
|
||||||
|
@ -30,7 +30,6 @@ import androidx.test.espresso.action.ViewActions.click
|
|||||||
import androidx.test.espresso.matcher.ViewMatchers.withText
|
import androidx.test.espresso.matcher.ViewMatchers.withText
|
||||||
import applyWithViewHierarchyPrinting
|
import applyWithViewHierarchyPrinting
|
||||||
import com.adevinta.android.barista.interaction.BaristaSleepInteractions
|
import com.adevinta.android.barista.interaction.BaristaSleepInteractions
|
||||||
import com.adevinta.android.barista.interaction.BaristaSwipeRefreshInteractions.refresh
|
|
||||||
import junit.framework.AssertionFailedError
|
import junit.framework.AssertionFailedError
|
||||||
import org.kiwix.kiwixmobile.BaseRobot
|
import org.kiwix.kiwixmobile.BaseRobot
|
||||||
import org.kiwix.kiwixmobile.Findable.StringId.TextId
|
import org.kiwix.kiwixmobile.Findable.StringId.TextId
|
||||||
@ -38,6 +37,7 @@ import org.kiwix.kiwixmobile.Findable.Text
|
|||||||
import org.kiwix.kiwixmobile.core.R
|
import org.kiwix.kiwixmobile.core.R
|
||||||
import org.kiwix.kiwixmobile.core.utils.files.Log
|
import org.kiwix.kiwixmobile.core.utils.files.Log
|
||||||
import org.kiwix.kiwixmobile.testutils.TestUtils
|
import org.kiwix.kiwixmobile.testutils.TestUtils
|
||||||
|
import org.kiwix.kiwixmobile.testutils.TestUtils.refresh
|
||||||
import org.kiwix.kiwixmobile.testutils.TestUtils.testFlakyView
|
import org.kiwix.kiwixmobile.testutils.TestUtils.testFlakyView
|
||||||
import org.kiwix.kiwixmobile.ui.BOOK_ITEM_CHECKBOX_TESTING_TAG
|
import org.kiwix.kiwixmobile.ui.BOOK_ITEM_CHECKBOX_TESTING_TAG
|
||||||
import org.kiwix.kiwixmobile.utils.StandardActions.openDrawer
|
import org.kiwix.kiwixmobile.utils.StandardActions.openDrawer
|
||||||
@ -49,9 +49,11 @@ class ZimHostRobot : BaseRobot() {
|
|||||||
isVisible(TextId(R.string.menu_wifi_hotspot))
|
isVisible(TextId(R.string.menu_wifi_hotspot))
|
||||||
}
|
}
|
||||||
|
|
||||||
fun refreshLibraryList() {
|
fun refreshLibraryList(composeTestRule: ComposeContentTestRule) {
|
||||||
pauseForBetterTestPerformance()
|
pauseForBetterTestPerformance()
|
||||||
refresh(org.kiwix.kiwixmobile.R.id.zim_swiperefresh)
|
composeTestRule.runOnIdle {
|
||||||
|
composeTestRule.refresh()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun assertZimFilesLoaded() {
|
fun assertZimFilesLoaded() {
|
||||||
|
@ -45,6 +45,7 @@ import androidx.compose.ui.Alignment
|
|||||||
import androidx.compose.ui.Modifier
|
import androidx.compose.ui.Modifier
|
||||||
import androidx.compose.ui.input.nestedscroll.nestedScroll
|
import androidx.compose.ui.input.nestedscroll.nestedScroll
|
||||||
import androidx.compose.ui.platform.LocalDensity
|
import androidx.compose.ui.platform.LocalDensity
|
||||||
|
import androidx.compose.ui.platform.testTag
|
||||||
import androidx.compose.ui.res.painterResource
|
import androidx.compose.ui.res.painterResource
|
||||||
import androidx.compose.ui.res.stringResource
|
import androidx.compose.ui.res.stringResource
|
||||||
import androidx.compose.ui.text.font.FontWeight
|
import androidx.compose.ui.text.font.FontWeight
|
||||||
@ -74,6 +75,12 @@ import org.kiwix.kiwixmobile.ui.BookItem
|
|||||||
import org.kiwix.kiwixmobile.ui.ZimFilesLanguageHeader
|
import org.kiwix.kiwixmobile.ui.ZimFilesLanguageHeader
|
||||||
import org.kiwix.kiwixmobile.zimManager.fileselectView.FileSelectListState
|
import org.kiwix.kiwixmobile.zimManager.fileselectView.FileSelectListState
|
||||||
|
|
||||||
|
const val NO_FILE_TEXT_TESTING_TAG = "noFileTextTestingTag"
|
||||||
|
const val DOWNLOAD_BUTTON_TESTING_TAG = "downloadButtonTestingTag"
|
||||||
|
const val BOOK_LIST_TESTING_TAG = "bookListTestingTag"
|
||||||
|
const val CONTENT_LOADING_PROGRESSBAR_TESTING_TAG = "contentLoadingProgressBarTestingTag"
|
||||||
|
const val SELECT_FILE_BUTTON_TESTING_TAG = "selectFileButtonTestingTag"
|
||||||
|
|
||||||
@OptIn(ExperimentalMaterial3Api::class)
|
@OptIn(ExperimentalMaterial3Api::class)
|
||||||
@Suppress("ComposableLambdaParameterNaming")
|
@Suppress("ComposableLambdaParameterNaming")
|
||||||
@Composable
|
@Composable
|
||||||
@ -112,6 +119,7 @@ fun LocalLibraryScreen(
|
|||||||
) {
|
) {
|
||||||
if (state.scanningProgressItem.first) {
|
if (state.scanningProgressItem.first) {
|
||||||
ContentLoadingProgressBar(
|
ContentLoadingProgressBar(
|
||||||
|
modifier = Modifier.testTag(CONTENT_LOADING_PROGRESSBAR_TESTING_TAG),
|
||||||
progressBarStyle = ProgressBarStyle.HORIZONTAL,
|
progressBarStyle = ProgressBarStyle.HORIZONTAL,
|
||||||
progress = state.scanningProgressItem.second
|
progress = state.scanningProgressItem.second
|
||||||
)
|
)
|
||||||
@ -167,7 +175,12 @@ private fun BookItemList(
|
|||||||
onMultiSelect: ((BookOnDisk) -> Unit)? = null,
|
onMultiSelect: ((BookOnDisk) -> Unit)? = null,
|
||||||
lazyListState: LazyListState,
|
lazyListState: LazyListState,
|
||||||
) {
|
) {
|
||||||
LazyColumn(modifier = Modifier.fillMaxSize(), state = lazyListState) {
|
LazyColumn(
|
||||||
|
modifier = Modifier
|
||||||
|
.fillMaxSize()
|
||||||
|
.testTag(BOOK_LIST_TESTING_TAG),
|
||||||
|
state = lazyListState
|
||||||
|
) {
|
||||||
itemsIndexed(state.bookOnDiskListItems) { index, bookItem ->
|
itemsIndexed(state.bookOnDiskListItems) { index, bookItem ->
|
||||||
when (bookItem) {
|
when (bookItem) {
|
||||||
is BooksOnDiskListItem.LanguageItem -> {
|
is BooksOnDiskListItem.LanguageItem -> {
|
||||||
@ -193,7 +206,9 @@ private fun BookItemList(
|
|||||||
private fun SelectFileButton(fabButtonClick: () -> Unit) {
|
private fun SelectFileButton(fabButtonClick: () -> Unit) {
|
||||||
FloatingActionButton(
|
FloatingActionButton(
|
||||||
onClick = fabButtonClick,
|
onClick = fabButtonClick,
|
||||||
modifier = Modifier.padding(bottom = FAB_ICON_BOTTOM_MARGIN),
|
modifier = Modifier
|
||||||
|
.padding(bottom = FAB_ICON_BOTTOM_MARGIN)
|
||||||
|
.testTag(SELECT_FILE_BUTTON_TESTING_TAG),
|
||||||
containerColor = Black,
|
containerColor = Black,
|
||||||
shape = MaterialTheme.shapes.extraLarge
|
shape = MaterialTheme.shapes.extraLarge
|
||||||
) {
|
) {
|
||||||
@ -219,11 +234,16 @@ fun NoFilesView(
|
|||||||
verticalArrangement = Arrangement.Center
|
verticalArrangement = Arrangement.Center
|
||||||
) {
|
) {
|
||||||
Text(
|
Text(
|
||||||
|
modifier = Modifier.testTag(NO_FILE_TEXT_TESTING_TAG),
|
||||||
text = noFilesViewItem.first,
|
text = noFilesViewItem.first,
|
||||||
style = MaterialTheme.typography.titleLarge.copy(fontWeight = FontWeight.Medium),
|
style = MaterialTheme.typography.titleLarge.copy(fontWeight = FontWeight.Medium),
|
||||||
textAlign = TextAlign.Center
|
textAlign = TextAlign.Center
|
||||||
)
|
)
|
||||||
Spacer(modifier = Modifier.height(EIGHT_DP))
|
Spacer(modifier = Modifier.height(EIGHT_DP))
|
||||||
KiwixButton(noFilesViewItem.second, onDownloadButtonClick)
|
KiwixButton(
|
||||||
|
buttonText = noFilesViewItem.second,
|
||||||
|
clickListener = onDownloadButtonClick,
|
||||||
|
modifier = Modifier.testTag(DOWNLOAD_BUTTON_TESTING_TAG)
|
||||||
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,116 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?><!--
|
|
||||||
~ Kiwix Android
|
|
||||||
~ Copyright (c) 2020 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/>.
|
|
||||||
~
|
|
||||||
-->
|
|
||||||
|
|
||||||
|
|
||||||
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
|
||||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
|
||||||
xmlns:tools="http://schemas.android.com/tools"
|
|
||||||
android:layout_width="match_parent"
|
|
||||||
android:layout_height="match_parent">
|
|
||||||
|
|
||||||
<org.kiwix.kiwixmobile.core.utils.NestedCoordinatorLayout
|
|
||||||
android:layout_width="match_parent"
|
|
||||||
android:layout_height="match_parent"
|
|
||||||
app:layout_constraintBottom_toBottomOf="parent"
|
|
||||||
app:layout_constraintEnd_toEndOf="parent"
|
|
||||||
app:layout_constraintStart_toStartOf="parent"
|
|
||||||
app:layout_constraintTop_toTopOf="parent">
|
|
||||||
|
|
||||||
<com.google.android.material.appbar.AppBarLayout
|
|
||||||
android:layout_width="match_parent"
|
|
||||||
android:layout_height="wrap_content">
|
|
||||||
|
|
||||||
<include layout="@layout/layout_scrolling_toolbar" />
|
|
||||||
|
|
||||||
</com.google.android.material.appbar.AppBarLayout>
|
|
||||||
|
|
||||||
|
|
||||||
<androidx.swiperefreshlayout.widget.SwipeRefreshLayout
|
|
||||||
android:id="@+id/zim_swiperefresh"
|
|
||||||
android:layout_width="match_parent"
|
|
||||||
android:layout_height="match_parent"
|
|
||||||
app:layout_behavior="@string/appbar_scrolling_view_behavior">
|
|
||||||
|
|
||||||
<androidx.constraintlayout.widget.ConstraintLayout
|
|
||||||
android:layout_width="match_parent"
|
|
||||||
android:layout_height="match_parent">
|
|
||||||
|
|
||||||
<androidx.recyclerview.widget.RecyclerView
|
|
||||||
android:id="@+id/zimfilelist"
|
|
||||||
android:layout_width="0dp"
|
|
||||||
android:layout_height="match_parent"
|
|
||||||
android:clipToPadding="false"
|
|
||||||
android:contentDescription="@string/crash_checkbox_zimfiles"
|
|
||||||
app:layout_constraintBottom_toBottomOf="parent"
|
|
||||||
app:layout_constraintEnd_toEndOf="parent"
|
|
||||||
app:layout_constraintStart_toStartOf="parent"
|
|
||||||
app:layout_constraintTop_toBottomOf="@+id/scanning_progress_view"
|
|
||||||
tools:listitem="@layout/item_book" />
|
|
||||||
|
|
||||||
<androidx.core.widget.ContentLoadingProgressBar
|
|
||||||
android:id="@+id/scanning_progress_view"
|
|
||||||
style="?android:attr/progressBarStyleHorizontal"
|
|
||||||
android:layout_width="match_parent"
|
|
||||||
android:layout_height="4dp"
|
|
||||||
android:indeterminate="false"
|
|
||||||
android:max="100"
|
|
||||||
android:theme="@style/ThemeOverlay.KiwixTheme.ProgressBar"
|
|
||||||
android:visibility="gone"
|
|
||||||
app:layout_constraintTop_toTopOf="parent"
|
|
||||||
tools:progress="0" />
|
|
||||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
|
||||||
</androidx.swiperefreshlayout.widget.SwipeRefreshLayout>
|
|
||||||
|
|
||||||
</org.kiwix.kiwixmobile.core.utils.NestedCoordinatorLayout>
|
|
||||||
|
|
||||||
<TextView
|
|
||||||
android:id="@+id/file_management_no_files"
|
|
||||||
style="@style/no_content"
|
|
||||||
android:text="@string/no_files_here"
|
|
||||||
app:layout_constraintBottom_toBottomOf="parent"
|
|
||||||
app:layout_constraintEnd_toEndOf="parent"
|
|
||||||
app:layout_constraintStart_toStartOf="parent"
|
|
||||||
app:layout_constraintTop_toTopOf="parent"
|
|
||||||
app:layout_constraintVertical_bias="0.45"
|
|
||||||
tools:ignore="RequiredSize" />
|
|
||||||
|
|
||||||
<Button
|
|
||||||
android:id="@+id/go_to_downloads_button_no_files"
|
|
||||||
android:layout_width="wrap_content"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:layout_marginTop="8dp"
|
|
||||||
android:text="@string/download_books"
|
|
||||||
android:visibility="gone"
|
|
||||||
app:layout_constraintEnd_toEndOf="@+id/file_management_no_files"
|
|
||||||
app:layout_constraintStart_toStartOf="@+id/file_management_no_files"
|
|
||||||
app:layout_constraintTop_toBottomOf="@+id/file_management_no_files" />
|
|
||||||
|
|
||||||
<com.google.android.material.floatingactionbutton.FloatingActionButton
|
|
||||||
android:id="@+id/select_file"
|
|
||||||
android:layout_width="wrap_content"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:layout_marginEnd="10dp"
|
|
||||||
android:layout_marginBottom="66dp"
|
|
||||||
android:contentDescription="@string/select_zim_file"
|
|
||||||
android:src="@drawable/ic_add_blue_24dp"
|
|
||||||
app:backgroundTint="@color/black"
|
|
||||||
app:fabSize="auto"
|
|
||||||
app:layout_constraintBottom_toBottomOf="parent"
|
|
||||||
app:layout_constraintEnd_toEndOf="parent" />
|
|
||||||
|
|
||||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
|
@ -29,10 +29,13 @@ import androidx.compose.runtime.Composable
|
|||||||
import androidx.compose.runtime.rememberCoroutineScope
|
import androidx.compose.runtime.rememberCoroutineScope
|
||||||
import androidx.compose.ui.Alignment
|
import androidx.compose.ui.Alignment
|
||||||
import androidx.compose.ui.Modifier
|
import androidx.compose.ui.Modifier
|
||||||
|
import androidx.compose.ui.platform.testTag
|
||||||
import kotlinx.coroutines.launch
|
import kotlinx.coroutines.launch
|
||||||
import org.kiwix.kiwixmobile.core.ui.theme.Black
|
import org.kiwix.kiwixmobile.core.ui.theme.Black
|
||||||
import org.kiwix.kiwixmobile.core.ui.theme.White
|
import org.kiwix.kiwixmobile.core.ui.theme.White
|
||||||
|
|
||||||
|
const val SWIPE_REFRESH_TESTING_TAG = "swipeRefreshTestingTag"
|
||||||
|
|
||||||
@OptIn(ExperimentalMaterial3Api::class)
|
@OptIn(ExperimentalMaterial3Api::class)
|
||||||
@Composable
|
@Composable
|
||||||
fun SwipeRefreshLayout(
|
fun SwipeRefreshLayout(
|
||||||
@ -55,7 +58,9 @@ fun SwipeRefreshLayout(
|
|||||||
) {
|
) {
|
||||||
val coroutineScope = rememberCoroutineScope()
|
val coroutineScope = rememberCoroutineScope()
|
||||||
Box(
|
Box(
|
||||||
modifier.pullToRefresh(
|
modifier
|
||||||
|
.testTag(SWIPE_REFRESH_TESTING_TAG)
|
||||||
|
.pullToRefresh(
|
||||||
state = state,
|
state = state,
|
||||||
isRefreshing = isRefreshing,
|
isRefreshing = isRefreshing,
|
||||||
onRefresh = {
|
onRefresh = {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user