diff --git a/app/src/androidTest/java/org/kiwix/kiwixmobile/NetworkTest.kt b/app/src/androidTest/java/org/kiwix/kiwixmobile/NetworkTest.kt index 2c8bc3025..7bdf3b7fe 100644 --- a/app/src/androidTest/java/org/kiwix/kiwixmobile/NetworkTest.kt +++ b/app/src/androidTest/java/org/kiwix/kiwixmobile/NetworkTest.kt @@ -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() { diff --git a/app/src/androidTest/java/org/kiwix/kiwixmobile/download/DownloadRobot.kt b/app/src/androidTest/java/org/kiwix/kiwixmobile/download/DownloadRobot.kt index c30ab69c2..9380894d6 100644 --- a/app/src/androidTest/java/org/kiwix/kiwixmobile/download/DownloadRobot.kt +++ b/app/src/androidTest/java/org/kiwix/kiwixmobile/download/DownloadRobot.kt @@ -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" diff --git a/app/src/androidTest/java/org/kiwix/kiwixmobile/download/DownloadTest.kt b/app/src/androidTest/java/org/kiwix/kiwixmobile/download/DownloadTest.kt index 90b0b5057..c55d684db 100644 --- a/app/src/androidTest/java/org/kiwix/kiwixmobile/download/DownloadTest.kt +++ b/app/src/androidTest/java/org/kiwix/kiwixmobile/download/DownloadTest.kt @@ -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 diff --git a/app/src/androidTest/java/org/kiwix/kiwixmobile/initial/download/InitialDownloadTest.kt b/app/src/androidTest/java/org/kiwix/kiwixmobile/initial/download/InitialDownloadTest.kt index 02ba9de99..5127d9f89 100644 --- a/app/src/androidTest/java/org/kiwix/kiwixmobile/initial/download/InitialDownloadTest.kt +++ b/app/src/androidTest/java/org/kiwix/kiwixmobile/initial/download/InitialDownloadTest.kt @@ -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() diff --git a/app/src/androidTest/java/org/kiwix/kiwixmobile/localLibrary/CopyMoveFileHandlerRobot.kt b/app/src/androidTest/java/org/kiwix/kiwixmobile/localLibrary/CopyMoveFileHandlerRobot.kt index 34d06503f..b26f8002c 100644 --- a/app/src/androidTest/java/org/kiwix/kiwixmobile/localLibrary/CopyMoveFileHandlerRobot.kt +++ b/app/src/androidTest/java/org/kiwix/kiwixmobile/localLibrary/CopyMoveFileHandlerRobot.kt @@ -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 } } diff --git a/app/src/androidTest/java/org/kiwix/kiwixmobile/localLibrary/CopyMoveFileHandlerTest.kt b/app/src/androidTest/java/org/kiwix/kiwixmobile/localLibrary/CopyMoveFileHandlerTest.kt index a2fe4e7df..f9f305ddc 100644 --- a/app/src/androidTest/java/org/kiwix/kiwixmobile/localLibrary/CopyMoveFileHandlerTest.kt +++ b/app/src/androidTest/java/org/kiwix/kiwixmobile/localLibrary/CopyMoveFileHandlerTest.kt @@ -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() { diff --git a/app/src/androidTest/java/org/kiwix/kiwixmobile/localLibrary/OpeningFilesFromStorageTest.kt b/app/src/androidTest/java/org/kiwix/kiwixmobile/localLibrary/OpeningFilesFromStorageTest.kt index 76b0c3234..5866929f9 100644 --- a/app/src/androidTest/java/org/kiwix/kiwixmobile/localLibrary/OpeningFilesFromStorageTest.kt +++ b/app/src/androidTest/java/org/kiwix/kiwixmobile/localLibrary/OpeningFilesFromStorageTest.kt @@ -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 { diff --git a/app/src/androidTest/java/org/kiwix/kiwixmobile/main/DarkModeViewPainterTest.kt b/app/src/androidTest/java/org/kiwix/kiwixmobile/main/DarkModeViewPainterTest.kt index 99e50ccd5..50a4607c3 100644 --- a/app/src/androidTest/java/org/kiwix/kiwixmobile/main/DarkModeViewPainterTest.kt +++ b/app/src/androidTest/java/org/kiwix/kiwixmobile/main/DarkModeViewPainterTest.kt @@ -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 diff --git a/app/src/androidTest/java/org/kiwix/kiwixmobile/nav/destination/library/LibraryRobot.kt b/app/src/androidTest/java/org/kiwix/kiwixmobile/nav/destination/library/LibraryRobot.kt index e15e20c20..7dc967254 100644 --- a/app/src/androidTest/java/org/kiwix/kiwixmobile/nav/destination/library/LibraryRobot.kt +++ b/app/src/androidTest/java/org/kiwix/kiwixmobile/nav/destination/library/LibraryRobot.kt @@ -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", diff --git a/app/src/androidTest/java/org/kiwix/kiwixmobile/nav/destination/library/LocalLibraryTest.kt b/app/src/androidTest/java/org/kiwix/kiwixmobile/nav/destination/library/LocalLibraryTest.kt index 7a037fab9..872202364 100644 --- a/app/src/androidTest/java/org/kiwix/kiwixmobile/nav/destination/library/LocalLibraryTest.kt +++ b/app/src/androidTest/java/org/kiwix/kiwixmobile/nav/destination/library/LocalLibraryTest.kt @@ -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() } diff --git a/app/src/androidTest/java/org/kiwix/kiwixmobile/note/NoteFragmentTest.kt b/app/src/androidTest/java/org/kiwix/kiwixmobile/note/NoteFragmentTest.kt index a44f39d40..ca110a4bd 100644 --- a/app/src/androidTest/java/org/kiwix/kiwixmobile/note/NoteFragmentTest.kt +++ b/app/src/androidTest/java/org/kiwix/kiwixmobile/note/NoteFragmentTest.kt @@ -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 { diff --git a/app/src/androidTest/java/org/kiwix/kiwixmobile/page/bookmarks/LibkiwixBookmarkTest.kt b/app/src/androidTest/java/org/kiwix/kiwixmobile/page/bookmarks/LibkiwixBookmarkTest.kt index d6d1749f1..2704ddadc 100644 --- a/app/src/androidTest/java/org/kiwix/kiwixmobile/page/bookmarks/LibkiwixBookmarkTest.kt +++ b/app/src/androidTest/java/org/kiwix/kiwixmobile/page/bookmarks/LibkiwixBookmarkTest.kt @@ -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 diff --git a/app/src/androidTest/java/org/kiwix/kiwixmobile/page/history/NavigationHistoryTest.kt b/app/src/androidTest/java/org/kiwix/kiwixmobile/page/history/NavigationHistoryTest.kt index 5089fea8f..e4afdb81b 100644 --- a/app/src/androidTest/java/org/kiwix/kiwixmobile/page/history/NavigationHistoryTest.kt +++ b/app/src/androidTest/java/org/kiwix/kiwixmobile/page/history/NavigationHistoryTest.kt @@ -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 diff --git a/app/src/androidTest/java/org/kiwix/kiwixmobile/reader/KiwixReaderFragmentTest.kt b/app/src/androidTest/java/org/kiwix/kiwixmobile/reader/KiwixReaderFragmentTest.kt index 34b7107d1..81c7aaaf8 100644 --- a/app/src/androidTest/java/org/kiwix/kiwixmobile/reader/KiwixReaderFragmentTest.kt +++ b/app/src/androidTest/java/org/kiwix/kiwixmobile/reader/KiwixReaderFragmentTest.kt @@ -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 diff --git a/app/src/androidTest/java/org/kiwix/kiwixmobile/reader/ZimFileReaderWithSplittedZimFileTest.kt b/app/src/androidTest/java/org/kiwix/kiwixmobile/reader/ZimFileReaderWithSplittedZimFileTest.kt index 7ef7697c8..d646e99b2 100644 --- a/app/src/androidTest/java/org/kiwix/kiwixmobile/reader/ZimFileReaderWithSplittedZimFileTest.kt +++ b/app/src/androidTest/java/org/kiwix/kiwixmobile/reader/ZimFileReaderWithSplittedZimFileTest.kt @@ -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 diff --git a/app/src/androidTest/java/org/kiwix/kiwixmobile/search/SearchFragmentTest.kt b/app/src/androidTest/java/org/kiwix/kiwixmobile/search/SearchFragmentTest.kt index becb6461e..2b4a2be8f 100644 --- a/app/src/androidTest/java/org/kiwix/kiwixmobile/search/SearchFragmentTest.kt +++ b/app/src/androidTest/java/org/kiwix/kiwixmobile/search/SearchFragmentTest.kt @@ -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 diff --git a/app/src/androidTest/java/org/kiwix/kiwixmobile/testutils/TestUtils.kt b/app/src/androidTest/java/org/kiwix/kiwixmobile/testutils/TestUtils.kt index c08335f3a..04d1c2320 100644 --- a/app/src/androidTest/java/org/kiwix/kiwixmobile/testutils/TestUtils.kt +++ b/app/src/androidTest/java/org/kiwix/kiwixmobile/testutils/TestUtils.kt @@ -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() } + } } diff --git a/app/src/androidTest/java/org/kiwix/kiwixmobile/webserver/ZimHostFragmentTest.kt b/app/src/androidTest/java/org/kiwix/kiwixmobile/webserver/ZimHostFragmentTest.kt index 69d714e77..d4a36ccb9 100644 --- a/app/src/androidTest/java/org/kiwix/kiwixmobile/webserver/ZimHostFragmentTest.kt +++ b/app/src/androidTest/java/org/kiwix/kiwixmobile/webserver/ZimHostFragmentTest.kt @@ -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() diff --git a/app/src/androidTest/java/org/kiwix/kiwixmobile/webserver/ZimHostRobot.kt b/app/src/androidTest/java/org/kiwix/kiwixmobile/webserver/ZimHostRobot.kt index 992f6edb3..fc322a770 100644 --- a/app/src/androidTest/java/org/kiwix/kiwixmobile/webserver/ZimHostRobot.kt +++ b/app/src/androidTest/java/org/kiwix/kiwixmobile/webserver/ZimHostRobot.kt @@ -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() { diff --git a/app/src/main/java/org/kiwix/kiwixmobile/nav/destination/library/local/LocalLibraryScreen.kt b/app/src/main/java/org/kiwix/kiwixmobile/nav/destination/library/local/LocalLibraryScreen.kt index 2ebe06b12..b13ef4be2 100644 --- a/app/src/main/java/org/kiwix/kiwixmobile/nav/destination/library/local/LocalLibraryScreen.kt +++ b/app/src/main/java/org/kiwix/kiwixmobile/nav/destination/library/local/LocalLibraryScreen.kt @@ -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) + ) } } diff --git a/app/src/main/res/layout/fragment_destination_library.xml b/app/src/main/res/layout/fragment_destination_library.xml deleted file mode 100644 index 462076d01..000000000 --- a/app/src/main/res/layout/fragment_destination_library.xml +++ /dev/null @@ -1,116 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - -