Refactored the test cases according to compose UI.

This commit is contained in:
MohitMaliFtechiz 2025-03-21 18:12:01 +05:30
parent 7d7f726d51
commit 080e518d2b
22 changed files with 190 additions and 236 deletions

View File

@ -29,11 +29,8 @@ import androidx.test.ext.junit.runners.AndroidJUnit4
import androidx.test.platform.app.InstrumentationRegistry
import androidx.test.rule.GrantPermissionRule
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.BaristaSleepInteractions
import com.adevinta.android.barista.interaction.BaristaSwipeRefreshInteractions.refresh
import org.hamcrest.CoreMatchers
import org.junit.After
import org.junit.Before
import org.junit.BeforeClass
@ -110,8 +107,8 @@ class NetworkTest {
}
clickOn(string.local_zims)
try {
Espresso.onData(CoreMatchers.allOf(ViewMatchers.withId(R.id.zim_swiperefresh)))
refresh(R.id.zim_swiperefresh)
// Espresso.onData(CoreMatchers.allOf(ViewMatchers.withId(R.id.zim_swiperefresh)))
// refresh(R.id.zim_swiperefresh)
Thread.sleep(500)
} catch (e: InterruptedException) {
e.printStackTrace()
@ -122,21 +119,21 @@ class NetworkTest {
// onData(withContent("wikipedia_ab_all_2017-03")).inAdapterView(withId(R.id.zimfilelist)).perform(click());
// Find matching zim files on the device
try {
val dataInteraction =
Espresso.onData(TestUtils.withContent("wikipedia_ab_all_2017-03"))
.inAdapterView(ViewMatchers.withId(R.id.zimfilelist))
// TODO how can we get a count of the items matching the dataInteraction?
dataInteraction.atPosition(0).perform(ViewActions.click())
clickMenu(string.library)
val dataInteraction1 =
Espresso.onData(TestUtils.withContent("wikipedia_ab_all_2017-03"))
.inAdapterView(ViewMatchers.withId(R.id.zimfilelist))
dataInteraction1.atPosition(0).perform(ViewActions.longClick()) // to delete the zim file
BaristaDialogInteractions.clickDialogPositiveButton()
} catch (e: Exception) {
Log.w(NETWORK_TEST_TAG, "failed to interact with local ZIM file: " + e.localizedMessage)
}
// try {
// val dataInteraction =
// Espresso.onData(TestUtils.withContent("wikipedia_ab_all_2017-03"))
// .inAdapterView(ViewMatchers.withId(R.id.zimfilelist))
// // TODO how can we get a count of the items matching the dataInteraction?
// dataInteraction.atPosition(0).perform(ViewActions.click())
// clickMenu(string.library)
// val dataInteraction1 =
// Espresso.onData(TestUtils.withContent("wikipedia_ab_all_2017-03"))
// .inAdapterView(ViewMatchers.withId(R.id.zimfilelist))
// dataInteraction1.atPosition(0).perform(ViewActions.longClick()) // to delete the zim file
// BaristaDialogInteractions.clickDialogPositiveButton()
// } catch (e: Exception) {
// Log.w(NETWORK_TEST_TAG, "failed to interact with local ZIM file: " + e.localizedMessage)
// }
}
@After fun finish() {

View File

@ -19,6 +19,9 @@
package org.kiwix.kiwixmobile.download
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.test.espresso.Espresso.onView
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.download.DownloadTest.Companion.KIWIX_DOWNLOAD_TEST
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.testFlakyView
import org.kiwix.kiwixmobile.utils.RecyclerViewMatcher
@ -84,26 +88,28 @@ class DownloadRobot : BaseRobot() {
try {
onView(withText(string.swipe_down_for_library)).check(matches(isDisplayed()))
refreshOnlineList()
} catch (e: RuntimeException) {
} catch (_: RuntimeException) {
try {
// do nothing as currently downloading the online library.
onView(withId(R.id.onlineLibraryProgressLayout)).check(matches(isDisplayed()))
} catch (e: RuntimeException) {
} catch (_: RuntimeException) {
// if not visible try to get the online library.
refreshOnlineList()
}
}
}
fun checkIfZimFileDownloaded() {
fun checkIfZimFileDownloaded(composeTestRule: ComposeContentTestRule) {
pauseForBetterTestPerformance()
try {
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.
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
// screen that means zim file is downloaded successfully.
}
@ -175,9 +181,9 @@ class DownloadRobot : BaseRobot() {
try {
onView(withSubstring(context.getString(string.paused_state))).check(matches(isDisplayed()))
resumeDownload()
} catch (e: AssertionFailedError) {
} catch (_: AssertionFailedError) {
// do nothing since downloading is In Progress.
} catch (e: RuntimeException) {
} catch (_: RuntimeException) {
// do nothing since downloading is In Progress.
}
}
@ -194,7 +200,7 @@ class DownloadRobot : BaseRobot() {
private fun clickOnYesButton() {
try {
onView(withText("YES")).perform(click())
} catch (ignore: Exception) {
} catch (_: Exception) {
// stop the downloading for Albanian language
onView(withText("PO")).perform(click())
}
@ -208,7 +214,7 @@ class DownloadRobot : BaseRobot() {
assertStopDownloadDialogDisplayed()
clickOnYesButton()
pauseForBetterTestPerformance()
} catch (e: Exception) {
} catch (_: Exception) {
Log.e(
KIWIX_DOWNLOAD_TEST,
"Failed to stop downloading. Probably because it is not downloading the zim file"

View File

@ -18,6 +18,7 @@
package org.kiwix.kiwixmobile.download
import android.util.Log
import androidx.compose.ui.test.junit4.createComposeRule
import androidx.core.content.edit
import androidx.lifecycle.Lifecycle
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.main.KiwixMainActivity
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.library
import org.kiwix.kiwixmobile.testutils.RetryRule
@ -68,6 +68,9 @@ class DownloadTest : BaseActivityTest() {
@JvmField
var retryRule = RetryRule()
@get:Rule
val composeTestRule = createComposeRule()
private lateinit var kiwixMainActivity: KiwixMainActivity
init {
@ -128,9 +131,9 @@ class DownloadTest : BaseActivityTest() {
// delete all the ZIM files showing in the LocalLibrary
// screen to properly test the scenario.
library {
refreshList()
waitUntilZimFilesRefreshing()
deleteZimIfExists()
refreshList(composeTestRule)
waitUntilZimFilesRefreshing(composeTestRule)
deleteZimIfExists(composeTestRule)
}
downloadRobot {
clickDownloadOnBottomNav()
@ -158,8 +161,8 @@ class DownloadTest : BaseActivityTest() {
}
clickLibraryOnBottomNav()
// refresh the local library list to show the downloaded zim file
library(LibraryRobot::refreshList)
checkIfZimFileDownloaded()
library { refreshList(composeTestRule) }
checkIfZimFileDownloaded(composeTestRule)
}
} catch (e: Exception) {
Assert.fail(
@ -188,9 +191,9 @@ class DownloadTest : BaseActivityTest() {
// delete all the ZIM files showing in the LocalLibrary
// screen to properly test the scenario.
library {
refreshList()
waitUntilZimFilesRefreshing()
deleteZimIfExists()
refreshList(composeTestRule)
waitUntilZimFilesRefreshing(composeTestRule)
deleteZimIfExists(composeTestRule)
}
downloadRobot {
// change the application language

View File

@ -18,6 +18,7 @@
package org.kiwix.kiwixmobile.initial.download
import androidx.compose.ui.test.junit4.createComposeRule
import androidx.core.content.edit
import androidx.lifecycle.Lifecycle
import androidx.preference.PreferenceManager
@ -57,6 +58,9 @@ class InitialDownloadTest : BaseActivityTest() {
@JvmField
var retryRule = RetryRule()
@get:Rule
val composeTestRule = createComposeRule()
init {
AccessibilityChecks.enable().apply {
setRunChecksFromRootView(true)
@ -111,9 +115,9 @@ class InitialDownloadTest : BaseActivityTest() {
// delete all the ZIM files showing in the LocalLibrary
// screen to properly test the scenario.
library {
refreshList()
waitUntilZimFilesRefreshing()
deleteZimIfExists()
refreshList(composeTestRule)
waitUntilZimFilesRefreshing(composeTestRule)
deleteZimIfExists(composeTestRule)
}
initialDownload {
clickDownloadOnBottomNav()

View File

@ -18,11 +18,12 @@
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.action.ViewActions.click
import androidx.test.espresso.assertion.ViewAssertions
import androidx.test.espresso.assertion.ViewAssertions.doesNotExist
import androidx.test.espresso.matcher.ViewMatchers
import androidx.test.espresso.matcher.ViewMatchers.withText
import androidx.test.espresso.web.sugar.Web
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.R.id
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.testFlakyView
import org.kiwix.kiwixmobile.utils.RecyclerViewMatcher
@ -102,15 +104,11 @@ class CopyMoveFileHandlerRobot : BaseRobot() {
})
}
fun assertZimFileAddedInTheLocalLibrary() {
fun assertZimFileAddedInTheLocalLibrary(composeTestRule: ComposeContentTestRule) {
try {
onView(ViewMatchers.withId(id.file_management_no_files)).check(
ViewAssertions.matches(
ViewMatchers.isDisplayed()
)
)
composeTestRule.onNodeWithTag(NO_FILE_TEXT_TESTING_TAG).assertIsDisplayed()
throw RuntimeException("ZimFile not added in the local library")
} catch (e: AssertionFailedError) {
} catch (_: AssertionFailedError) {
// do nothing zim file is added in the local library
}
}

View File

@ -20,6 +20,7 @@ package org.kiwix.kiwixmobile.localLibrary
import android.net.Uri
import android.os.Build
import androidx.compose.ui.test.junit4.createComposeRule
import androidx.core.content.edit
import androidx.documentfile.provider.DocumentFile
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.main.KiwixMainActivity
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.TestUtils
import org.kiwix.kiwixmobile.zimManager.Fat32Checker
@ -62,6 +63,9 @@ class CopyMoveFileHandlerTest : BaseActivityTest() {
@JvmField
var retryRule = RetryRule()
@get:Rule
val composeTestRule = createComposeRule()
private lateinit var sharedPreferenceUtil: SharedPreferenceUtil
private lateinit var kiwixMainActivity: KiwixMainActivity
private lateinit var selectedFile: File
@ -191,7 +195,7 @@ class CopyMoveFileHandlerTest : BaseActivityTest() {
UiThreadStatement.runOnUiThread {
kiwixMainActivity.navigate(R.id.libraryFragment)
}
copyMoveFileHandler(CopyMoveFileHandlerRobot::assertZimFileAddedInTheLocalLibrary)
copyMoveFileHandler { assertZimFileAddedInTheLocalLibrary(composeTestRule) }
}
private fun showMoveFileToPublicDirectoryDialog() {

View File

@ -26,14 +26,14 @@ import android.net.Uri
import android.os.Build
import android.provider.MediaStore
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.lifecycle.Lifecycle
import androidx.preference.PreferenceManager
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.matcher.ViewMatchers.withId
import androidx.test.ext.junit.runners.AndroidJUnit4
import androidx.test.platform.app.InstrumentationRegistry
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.SharedPreferenceUtil
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.TestUtils
import java.io.File
@ -61,6 +62,9 @@ class OpeningFilesFromStorageTest : BaseActivityTest() {
@JvmField
var retryRule = RetryRule()
@get:Rule
val composeTestRule = createComposeRule()
private lateinit var sharedPreferenceUtil: SharedPreferenceUtil
private lateinit var kiwixMainActivity: KiwixMainActivity
private lateinit var uiDevice: UiDevice
@ -112,7 +116,7 @@ class OpeningFilesFromStorageTest : BaseActivityTest() {
try {
sharedPreferenceUtil.shouldShowStorageSelectionDialog = true
// 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()
copyMoveFileHandler {

View File

@ -41,7 +41,7 @@ import org.kiwix.kiwixmobile.BaseActivityTest
import org.kiwix.kiwixmobile.R
import org.kiwix.kiwixmobile.core.utils.LanguageUtils
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.settings.SettingsRobot
import org.kiwix.kiwixmobile.settings.settingsRobo

View File

@ -18,29 +18,33 @@
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.test.espresso.Espresso.onView
import androidx.test.espresso.action.ViewActions.click
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.scrollToPosition
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.withText
import applyWithViewHierarchyPrinting
import com.adevinta.android.barista.interaction.BaristaSleepInteractions
import com.adevinta.android.barista.interaction.BaristaSwipeRefreshInteractions.refresh
import junit.framework.AssertionFailedError
import org.hamcrest.Matchers.not
import org.kiwix.kiwixmobile.BaseRobot
import org.kiwix.kiwixmobile.Findable.ViewId
import org.kiwix.kiwixmobile.R
import org.kiwix.kiwixmobile.core.utils.files.Log
import org.kiwix.kiwixmobile.localFileTransfer.LocalFileTransferRobot
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.refresh
import org.kiwix.kiwixmobile.testutils.TestUtils.testFlakyView
import org.kiwix.kiwixmobile.utils.RecyclerViewItemCount
@ -58,46 +62,55 @@ class LibraryRobot : BaseRobot() {
localFileTransfer(func)
}
fun assertLibraryListDisplayed() {
isVisible(ViewId(R.id.zimfilelist))
fun assertLibraryListDisplayed(composeTestRule: ComposeContentTestRule) {
testFlakyView({
composeTestRule.runOnIdle {
composeTestRule.onNodeWithTag(BOOK_LIST_TESTING_TAG).assertIsDisplayed()
}
})
}
private fun assertNoFilesTextDisplayed() {
pauseForBetterTestPerformance()
testFlakyView({ isVisible(ViewId(R.id.file_management_no_files)) })
private fun assertNoFilesTextDisplayed(composeTestRule: ComposeContentTestRule) {
testFlakyView({
composeTestRule.runOnIdle {
composeTestRule.onNodeWithTag(NO_FILE_TEXT_TESTING_TAG).assertIsDisplayed()
}
})
}
fun refreshList() {
pauseForBetterTestPerformance()
try {
onView(withId(R.id.file_management_no_files)).check(matches(isDisplayed()))
refresh(R.id.zim_swiperefresh)
} catch (ignore: AssertionFailedError) {
fun refreshList(composeTestRule: ComposeContentTestRule) {
composeTestRule.runOnIdle {
try {
onView(withId(R.id.zimfilelist)).check(matches(isDisplayed()))
refresh(R.id.zim_swiperefresh)
} catch (e: AssertionFailedError) {
Log.i(
"LOCAL_LIBRARY",
"No need to refresh the data, since there is no files found"
)
composeTestRule.onNodeWithTag(NO_FILE_TEXT_TESTING_TAG).assertIsDisplayed()
composeTestRule.refresh()
} catch (_: AssertionFailedError) {
try {
composeTestRule.onNodeWithTag(BOOK_LIST_TESTING_TAG).assertIsDisplayed()
composeTestRule.refresh()
} catch (_: AssertionFailedError) {
Log.i(
"LOCAL_LIBRARY",
"No need to refresh the data, since there is no files found"
)
}
}
}
}
fun waitUntilZimFilesRefreshing() {
fun waitUntilZimFilesRefreshing(composeTestRule: ComposeContentTestRule) {
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 {
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.
return
} catch (e: AssertionFailedError) {
} catch (_: AssertionFailedError) {
Log.e("DELETE_ZIM_FILE", "Zim files found in local library so we are deleting them")
}
val recyclerViewId: Int = R.id.zimfilelist
@ -114,7 +127,7 @@ class LibraryRobot : BaseRobot() {
clickOnFileDeleteIcon()
clickOnDeleteZimFile()
pauseForBetterTestPerformance()
assertNoFilesTextDisplayed()
assertNoFilesTextDisplayed(composeTestRule)
} catch (e: Exception) {
Log.i(
"TEST_DELETE_ZIM",

View File

@ -18,6 +18,7 @@
package org.kiwix.kiwixmobile.nav.destination.library
import androidx.compose.ui.test.junit4.createComposeRule
import androidx.core.content.edit
import androidx.lifecycle.Lifecycle
import androidx.preference.PreferenceManager
@ -53,6 +54,9 @@ class LocalLibraryTest : BaseActivityTest() {
@JvmField
var retryRule = RetryRule()
@get:Rule
val composeTestRule = createComposeRule()
init {
AccessibilityChecks.enable().apply {
setRunChecksFromRootView(true)
@ -112,9 +116,9 @@ class LocalLibraryTest : BaseActivityTest() {
it.navigate(R.id.libraryFragment)
}
library {
refreshList()
waitUntilZimFilesRefreshing()
deleteZimIfExists()
refreshList(composeTestRule)
waitUntilZimFilesRefreshing(composeTestRule)
deleteZimIfExists(composeTestRule)
}
// load a zim file to test, After downloading zim file library list is visible or not
val loadFileStream =
@ -137,8 +141,8 @@ class LocalLibraryTest : BaseActivityTest() {
}
}
library {
refreshList()
assertLibraryListDisplayed()
refreshList(composeTestRule)
assertLibraryListDisplayed(composeTestRule)
}
LeakAssertions.assertNoLeaks()
}

View File

@ -48,7 +48,7 @@ import org.kiwix.kiwixmobile.R
import org.kiwix.kiwixmobile.core.utils.LanguageUtils.Companion.handleLocaleChange
import org.kiwix.kiwixmobile.core.utils.SharedPreferenceUtil
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.testutils.RetryRule
import org.kiwix.kiwixmobile.testutils.TestUtils
@ -161,9 +161,9 @@ class NoteFragmentTest : BaseActivityTest() {
}
library {
refreshList()
waitUntilZimFilesRefreshing()
deleteZimIfExists()
refreshList(composeTestRule)
waitUntilZimFilesRefreshing(composeTestRule)
deleteZimIfExists(composeTestRule)
}
note {

View File

@ -44,7 +44,7 @@ import org.kiwix.kiwixmobile.core.utils.LanguageUtils.Companion.handleLocaleChan
import org.kiwix.kiwixmobile.core.utils.SharedPreferenceUtil
import org.kiwix.kiwixmobile.main.KiwixMainActivity
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.TestUtils
import org.kiwix.libkiwix.Book

View File

@ -43,7 +43,7 @@ import org.kiwix.kiwixmobile.R
import org.kiwix.kiwixmobile.core.utils.LanguageUtils.Companion.handleLocaleChange
import org.kiwix.kiwixmobile.core.utils.SharedPreferenceUtil
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.TestUtils
import org.kiwix.kiwixmobile.testutils.TestUtils.closeSystemDialogs

View File

@ -45,7 +45,7 @@ import org.kiwix.kiwixmobile.R
import org.kiwix.kiwixmobile.core.utils.LanguageUtils.Companion.handleLocaleChange
import org.kiwix.kiwixmobile.core.utils.SharedPreferenceUtil
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.TestUtils
import org.kiwix.kiwixmobile.testutils.TestUtils.closeSystemDialogs

View File

@ -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.SharedPreferenceUtil
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.testutils.RetryRule
import org.kiwix.kiwixmobile.testutils.TestUtils

View File

@ -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.SharedPreferenceUtil
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.TestUtils
import org.kiwix.kiwixmobile.testutils.TestUtils.closeSystemDialogs

View File

@ -25,6 +25,10 @@ import android.content.pm.PackageManager
import android.graphics.Bitmap
import android.os.Build
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.test.core.app.canTakeScreenshot
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.USER_AGENT
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 java.io.File
import java.io.FileNotFoundException
@ -252,4 +257,9 @@ object TestUtils {
.callTimeout(CALL_TIMEOUT, TimeUnit.SECONDS)
.addNetworkInterceptor(UserAgentInterceptor(USER_AGENT))
.build()
fun ComposeContentTestRule.refresh() {
onNodeWithTag(SWIPE_REFRESH_TESTING_TAG)
.performTouchInput { swipeDown() }
}
}

View File

@ -141,14 +141,14 @@ class ZimHostFragmentTest {
// delete all the ZIM files showing in the LocalLibrary
// screen to properly test the scenario.
library {
refreshList()
waitUntilZimFilesRefreshing()
deleteZimIfExists()
refreshList(composeTestRule)
waitUntilZimFilesRefreshing(composeTestRule)
deleteZimIfExists(composeTestRule)
}
loadZimFileInApplication("testzim.zim")
loadZimFileInApplication("small.zim")
zimHost {
refreshLibraryList()
refreshLibraryList(composeTestRule)
assertZimFilesLoaded()
openZimHostFragment()

View File

@ -30,7 +30,6 @@ import androidx.test.espresso.action.ViewActions.click
import androidx.test.espresso.matcher.ViewMatchers.withText
import applyWithViewHierarchyPrinting
import com.adevinta.android.barista.interaction.BaristaSleepInteractions
import com.adevinta.android.barista.interaction.BaristaSwipeRefreshInteractions.refresh
import junit.framework.AssertionFailedError
import org.kiwix.kiwixmobile.BaseRobot
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.utils.files.Log
import org.kiwix.kiwixmobile.testutils.TestUtils
import org.kiwix.kiwixmobile.testutils.TestUtils.refresh
import org.kiwix.kiwixmobile.testutils.TestUtils.testFlakyView
import org.kiwix.kiwixmobile.ui.BOOK_ITEM_CHECKBOX_TESTING_TAG
import org.kiwix.kiwixmobile.utils.StandardActions.openDrawer
@ -49,9 +49,11 @@ class ZimHostRobot : BaseRobot() {
isVisible(TextId(R.string.menu_wifi_hotspot))
}
fun refreshLibraryList() {
fun refreshLibraryList(composeTestRule: ComposeContentTestRule) {
pauseForBetterTestPerformance()
refresh(org.kiwix.kiwixmobile.R.id.zim_swiperefresh)
composeTestRule.runOnIdle {
composeTestRule.refresh()
}
}
fun assertZimFilesLoaded() {

View File

@ -45,6 +45,7 @@ import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.input.nestedscroll.nestedScroll
import androidx.compose.ui.platform.LocalDensity
import androidx.compose.ui.platform.testTag
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.res.stringResource
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.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)
@Suppress("ComposableLambdaParameterNaming")
@Composable
@ -112,6 +119,7 @@ fun LocalLibraryScreen(
) {
if (state.scanningProgressItem.first) {
ContentLoadingProgressBar(
modifier = Modifier.testTag(CONTENT_LOADING_PROGRESSBAR_TESTING_TAG),
progressBarStyle = ProgressBarStyle.HORIZONTAL,
progress = state.scanningProgressItem.second
)
@ -167,7 +175,12 @@ private fun BookItemList(
onMultiSelect: ((BookOnDisk) -> Unit)? = null,
lazyListState: LazyListState,
) {
LazyColumn(modifier = Modifier.fillMaxSize(), state = lazyListState) {
LazyColumn(
modifier = Modifier
.fillMaxSize()
.testTag(BOOK_LIST_TESTING_TAG),
state = lazyListState
) {
itemsIndexed(state.bookOnDiskListItems) { index, bookItem ->
when (bookItem) {
is BooksOnDiskListItem.LanguageItem -> {
@ -193,7 +206,9 @@ private fun BookItemList(
private fun SelectFileButton(fabButtonClick: () -> Unit) {
FloatingActionButton(
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,
shape = MaterialTheme.shapes.extraLarge
) {
@ -219,11 +234,16 @@ fun NoFilesView(
verticalArrangement = Arrangement.Center
) {
Text(
modifier = Modifier.testTag(NO_FILE_TEXT_TESTING_TAG),
text = noFilesViewItem.first,
style = MaterialTheme.typography.titleLarge.copy(fontWeight = FontWeight.Medium),
textAlign = TextAlign.Center
)
Spacer(modifier = Modifier.height(EIGHT_DP))
KiwixButton(noFilesViewItem.second, onDownloadButtonClick)
KiwixButton(
buttonText = noFilesViewItem.second,
clickListener = onDownloadButtonClick,
modifier = Modifier.testTag(DOWNLOAD_BUTTON_TESTING_TAG)
)
}
}

View File

@ -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>

View File

@ -29,10 +29,13 @@ import androidx.compose.runtime.Composable
import androidx.compose.runtime.rememberCoroutineScope
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.platform.testTag
import kotlinx.coroutines.launch
import org.kiwix.kiwixmobile.core.ui.theme.Black
import org.kiwix.kiwixmobile.core.ui.theme.White
const val SWIPE_REFRESH_TESTING_TAG = "swipeRefreshTestingTag"
@OptIn(ExperimentalMaterial3Api::class)
@Composable
fun SwipeRefreshLayout(
@ -55,17 +58,19 @@ fun SwipeRefreshLayout(
) {
val coroutineScope = rememberCoroutineScope()
Box(
modifier.pullToRefresh(
state = state,
isRefreshing = isRefreshing,
onRefresh = {
coroutineScope.launch {
state.animateToHidden()
onRefresh.invoke()
}
},
enabled = isEnabled
),
modifier
.testTag(SWIPE_REFRESH_TESTING_TAG)
.pullToRefresh(
state = state,
isRefreshing = isRefreshing,
onRefresh = {
coroutineScope.launch {
state.animateToHidden()
onRefresh.invoke()
}
},
enabled = isEnabled
),
contentAlignment = contentAlignment
) {
content()