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 9380894d6..21e4a7955 100644 --- a/app/src/androidTest/java/org/kiwix/kiwixmobile/download/DownloadRobot.kt +++ b/app/src/androidTest/java/org/kiwix/kiwixmobile/download/DownloadRobot.kt @@ -42,7 +42,6 @@ import junit.framework.AssertionFailedError import junit.framework.TestCase.assertEquals import org.hamcrest.CoreMatchers.containsString import org.hamcrest.Matcher -import org.junit.Assert import org.kiwix.kiwixmobile.BaseRobot import org.kiwix.kiwixmobile.Findable.StringId.TextId import org.kiwix.kiwixmobile.Findable.ViewId @@ -100,16 +99,14 @@ class DownloadRobot : BaseRobot() { } fun checkIfZimFileDownloaded(composeTestRule: ComposeContentTestRule) { - pauseForBetterTestPerformance() try { testFlakyView({ - composeTestRule.runOnIdle { - composeTestRule.onNodeWithTag(NO_FILE_TEXT_TESTING_TAG).assertIsDisplayed() - } + composeTestRule.waitForIdle() + 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 (_: AssertionFailedError) { + throw RuntimeException("Couldn't download the zim file. The [No files here] text is visible on screen") + } catch (_: AssertionError) { // check if "No files here" text is not visible on // screen that means zim file is downloaded successfully. } 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 c55d684db..be3ff0106 100644 --- a/app/src/androidTest/java/org/kiwix/kiwixmobile/download/DownloadTest.kt +++ b/app/src/androidTest/java/org/kiwix/kiwixmobile/download/DownloadTest.kt @@ -27,17 +27,12 @@ import androidx.test.core.app.ActivityScenario import androidx.test.espresso.IdlingPolicies import androidx.test.espresso.IdlingRegistry import androidx.test.espresso.accessibility.AccessibilityChecks -import androidx.test.espresso.matcher.ViewMatchers import androidx.test.ext.junit.runners.AndroidJUnit4 import androidx.test.filters.LargeTest import androidx.test.platform.app.InstrumentationRegistry import androidx.test.uiautomator.UiDevice import com.adevinta.android.barista.interaction.BaristaSleepInteractions -import com.google.android.apps.common.testing.accessibility.framework.AccessibilityCheckResultUtils.matchesCheck -import com.google.android.apps.common.testing.accessibility.framework.AccessibilityCheckResultUtils.matchesViews -import com.google.android.apps.common.testing.accessibility.framework.checks.DuplicateClickableBoundsCheck import leakcanary.LeakAssertions -import org.hamcrest.Matchers.allOf import org.junit.After import org.junit.Assert import org.junit.Before @@ -76,12 +71,6 @@ class DownloadTest : BaseActivityTest() { init { AccessibilityChecks.enable().apply { setRunChecksFromRootView(true) - setSuppressingResultMatcher( - allOf( - matchesCheck(DuplicateClickableBoundsCheck::class.java), - matchesViews(ViewMatchers.withId(R.id.get_zim_nearby_device)) - ) - ) } } 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 5127d9f89..1f0866730 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 @@ -24,17 +24,12 @@ import androidx.lifecycle.Lifecycle import androidx.preference.PreferenceManager import androidx.test.core.app.ActivityScenario import androidx.test.espresso.accessibility.AccessibilityChecks -import androidx.test.espresso.matcher.ViewMatchers import androidx.test.ext.junit.runners.AndroidJUnit4 import androidx.test.filters.LargeTest import androidx.test.platform.app.InstrumentationRegistry import androidx.test.uiautomator.UiDevice import com.adevinta.android.barista.interaction.BaristaSleepInteractions -import com.google.android.apps.common.testing.accessibility.framework.AccessibilityCheckResultUtils.matchesCheck -import com.google.android.apps.common.testing.accessibility.framework.AccessibilityCheckResultUtils.matchesViews -import com.google.android.apps.common.testing.accessibility.framework.checks.DuplicateClickableBoundsCheck import leakcanary.LeakAssertions -import org.hamcrest.Matchers.allOf import org.junit.After import org.junit.Before import org.junit.Rule @@ -64,12 +59,6 @@ class InitialDownloadTest : BaseActivityTest() { init { AccessibilityChecks.enable().apply { setRunChecksFromRootView(true) - setSuppressingResultMatcher( - allOf( - matchesCheck(DuplicateClickableBoundsCheck::class.java), - matchesViews(ViewMatchers.withId(R.id.get_zim_nearby_device)) - ) - ) } } diff --git a/app/src/androidTest/java/org/kiwix/kiwixmobile/localFileTransfer/LocalFileTransferTest.kt b/app/src/androidTest/java/org/kiwix/kiwixmobile/localFileTransfer/LocalFileTransferTest.kt index 1b123b975..33752cdeb 100644 --- a/app/src/androidTest/java/org/kiwix/kiwixmobile/localFileTransfer/LocalFileTransferTest.kt +++ b/app/src/androidTest/java/org/kiwix/kiwixmobile/localFileTransfer/LocalFileTransferTest.kt @@ -22,6 +22,7 @@ import android.Manifest import android.app.Instrumentation import android.content.Context import android.os.Build +import androidx.compose.ui.test.junit4.createComposeRule import androidx.core.content.edit import androidx.lifecycle.Lifecycle import androidx.preference.PreferenceManager @@ -55,6 +56,9 @@ class LocalFileTransferTest { @JvmField var retryRule = RetryRule() + @get:Rule + val composeTestRule = createComposeRule() + private lateinit var context: Context private lateinit var activityScenario: ActivityScenario @@ -133,8 +137,8 @@ class LocalFileTransferTest { it.navigate(R.id.libraryFragment) } library { - assertGetZimNearbyDeviceDisplayed() - clickFileTransferIcon { + assertGetZimNearbyDeviceDisplayed(composeTestRule) + clickFileTransferIcon(composeTestRule) { assertReceiveFileTitleVisible() assertSearchDeviceMenuItemVisible() clickOnSearchDeviceMenuItem() @@ -164,8 +168,8 @@ class LocalFileTransferTest { } StandardActions.closeDrawer() library { - assertGetZimNearbyDeviceDisplayed() - clickFileTransferIcon { + assertGetZimNearbyDeviceDisplayed(composeTestRule) + clickFileTransferIcon(composeTestRule) { assertClickNearbyDeviceMessageVisible() clickOnGotItButton() assertDeviceNameMessageVisible() @@ -175,7 +179,7 @@ class LocalFileTransferTest { assertTransferZimFilesListMessageVisible() clickOnGotItButton() pressBack() - assertGetZimNearbyDeviceDisplayed() + assertGetZimNearbyDeviceDisplayed(composeTestRule) } } LeakAssertions.assertNoLeaks() @@ -194,7 +198,9 @@ class LocalFileTransferTest { StandardActions.closeDrawer() library { // test show case view show once. - clickFileTransferIcon(LocalFileTransferRobot::assertClickNearbyDeviceMessageNotVisible) + clickFileTransferIcon(composeTestRule) { + LocalFileTransferRobot::assertClickNearbyDeviceMessageNotVisible + } } } 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 b26f8002c..c43c653a8 100644 --- a/app/src/androidTest/java/org/kiwix/kiwixmobile/localLibrary/CopyMoveFileHandlerRobot.kt +++ b/app/src/androidTest/java/org/kiwix/kiwixmobile/localLibrary/CopyMoveFileHandlerRobot.kt @@ -30,7 +30,6 @@ import androidx.test.espresso.web.webdriver.DriverAtoms import androidx.test.espresso.web.webdriver.Locator import applyWithViewHierarchyPrinting import com.adevinta.android.barista.interaction.BaristaSleepInteractions -import junit.framework.AssertionFailedError import org.kiwix.kiwixmobile.BaseRobot import org.kiwix.kiwixmobile.Findable import org.kiwix.kiwixmobile.Findable.StringId.TextId @@ -108,7 +107,7 @@ class CopyMoveFileHandlerRobot : BaseRobot() { try { composeTestRule.onNodeWithTag(NO_FILE_TEXT_TESTING_TAG).assertIsDisplayed() throw RuntimeException("ZimFile not added in the local library") - } catch (_: AssertionFailedError) { + } catch (_: AssertionError) { // do nothing zim file is added in the local library } } diff --git a/app/src/androidTest/java/org/kiwix/kiwixmobile/main/TopLevelDestinationTest.kt b/app/src/androidTest/java/org/kiwix/kiwixmobile/main/TopLevelDestinationTest.kt index a565d5f54..87c9d9595 100644 --- a/app/src/androidTest/java/org/kiwix/kiwixmobile/main/TopLevelDestinationTest.kt +++ b/app/src/androidTest/java/org/kiwix/kiwixmobile/main/TopLevelDestinationTest.kt @@ -17,6 +17,7 @@ */ package org.kiwix.kiwixmobile.main +import androidx.compose.ui.test.junit4.createComposeRule import androidx.core.content.edit import androidx.lifecycle.Lifecycle import androidx.preference.PreferenceManager @@ -50,6 +51,9 @@ class TopLevelDestinationTest : BaseActivityTest() { @JvmField var retryRule = RetryRule() + @get:Rule + val composeTestRule = createComposeRule() + @Before override fun waitForIdle() { UiDevice.getInstance(InstrumentationRegistry.getInstrumentation()).apply { @@ -106,8 +110,10 @@ class TopLevelDestinationTest : BaseActivityTest() { } clickDownloadOnBottomNav(OnlineLibraryRobot::assertLibraryListDisplayed) clickLibraryOnBottomNav { - assertGetZimNearbyDeviceDisplayed() - clickFileTransferIcon(LocalFileTransferRobot::assertReceiveFileTitleVisible) + assertGetZimNearbyDeviceDisplayed(composeTestRule) + clickFileTransferIcon(composeTestRule) { + LocalFileTransferRobot::assertReceiveFileTitleVisible + } } clickBookmarksOnNavDrawer { assertBookMarksDisplayed() 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 7dc967254..f423b4eb3 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 @@ -21,19 +21,17 @@ 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.longClick +import androidx.compose.ui.test.onAllNodesWithTag import androidx.compose.ui.test.onNodeWithTag -import androidx.recyclerview.widget.RecyclerView.ViewHolder +import androidx.compose.ui.test.performClick +import androidx.compose.ui.test.performTouchInput import androidx.test.espresso.Espresso.onView import androidx.test.espresso.action.ViewActions.click -import androidx.test.espresso.action.ViewActions.longClick -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.withId import androidx.test.espresso.matcher.ViewMatchers.withText import applyWithViewHierarchyPrinting import com.adevinta.android.barista.interaction.BaristaSleepInteractions -import junit.framework.AssertionFailedError import org.kiwix.kiwixmobile.BaseRobot import org.kiwix.kiwixmobile.Findable.ViewId import org.kiwix.kiwixmobile.R @@ -42,62 +40,71 @@ 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.LOCAL_FILE_TRANSFER_MENU_BUTTON_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 +import org.kiwix.kiwixmobile.ui.BOOK_ITEM_TESTING_TAG +import java.lang.AssertionError fun library(func: LibraryRobot.() -> Unit) = LibraryRobot().applyWithViewHierarchyPrinting(func) class LibraryRobot : BaseRobot() { private val zimFileTitle = "Test_Zim" - fun assertGetZimNearbyDeviceDisplayed() { - isVisible(ViewId(R.id.get_zim_nearby_device)) + fun assertGetZimNearbyDeviceDisplayed(composeTestRule: ComposeContentTestRule) { + composeTestRule.apply { + waitForIdle() + onNodeWithTag(LOCAL_FILE_TRANSFER_MENU_BUTTON_TESTING_TAG).assertIsDisplayed() + } } - fun clickFileTransferIcon(func: LocalFileTransferRobot.() -> Unit) { - clickOn(ViewId(R.id.get_zim_nearby_device)) + fun clickFileTransferIcon( + composeTestRule: ComposeContentTestRule, + func: LocalFileTransferRobot.() -> Unit + ) { + composeTestRule.apply { + waitForIdle() + onNodeWithTag(LOCAL_FILE_TRANSFER_MENU_BUTTON_TESTING_TAG).performClick() + } localFileTransfer(func) } fun assertLibraryListDisplayed(composeTestRule: ComposeContentTestRule) { testFlakyView({ - composeTestRule.runOnIdle { - composeTestRule.onNodeWithTag(BOOK_LIST_TESTING_TAG).assertIsDisplayed() - } + composeTestRule.waitForIdle() + composeTestRule.onNodeWithTag(BOOK_LIST_TESTING_TAG).assertIsDisplayed() }) } private fun assertNoFilesTextDisplayed(composeTestRule: ComposeContentTestRule) { testFlakyView({ - composeTestRule.runOnIdle { - composeTestRule.onNodeWithTag(NO_FILE_TEXT_TESTING_TAG).assertIsDisplayed() - } + composeTestRule.waitForIdle() + composeTestRule.onNodeWithTag(NO_FILE_TEXT_TESTING_TAG).assertIsDisplayed() }) } fun refreshList(composeTestRule: ComposeContentTestRule) { - composeTestRule.runOnIdle { + try { + composeTestRule.waitForIdle() + composeTestRule.onNodeWithTag(NO_FILE_TEXT_TESTING_TAG).assertIsDisplayed() + composeTestRule.refresh() + } catch (_: AssertionError) { try { - composeTestRule.onNodeWithTag(NO_FILE_TEXT_TESTING_TAG).assertIsDisplayed() + composeTestRule.onNodeWithTag(BOOK_LIST_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" - ) - } + } catch (_: AssertionError) { + Log.i( + "LOCAL_LIBRARY", + "No need to refresh the data, since there is no files found" + ) } } } fun waitUntilZimFilesRefreshing(composeTestRule: ComposeContentTestRule) { + pauseForBetterTestPerformance() testFlakyView({ composeTestRule.onNodeWithTag(CONTENT_LOADING_PROGRESSBAR_TESTING_TAG) .assertIsNotDisplayed() @@ -110,19 +117,13 @@ class LibraryRobot : BaseRobot() { 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 (_: AssertionFailedError) { + } catch (_: AssertionError) { Log.e("DELETE_ZIM_FILE", "Zim files found in local library so we are deleting them") } - val recyclerViewId: Int = R.id.zimfilelist - val recyclerViewItemsCount = RecyclerViewItemCount(recyclerViewId).checkRecyclerViewCount() - // Scroll to the end of the RecyclerView to ensure all items are visible - onView(withId(recyclerViewId)) - .perform(scrollToPosition(recyclerViewItemsCount - 1)) - - for (position in 0 until recyclerViewItemsCount) { - // Long-click the item to select it - onView(withId(recyclerViewId)) - .perform(actionOnItemAtPosition(position, longClick())) + val zimFileNodes = composeTestRule.onAllNodesWithTag(BOOK_ITEM_TESTING_TAG) + val itemCount = zimFileNodes.fetchSemanticsNodes().size + repeat(itemCount) { index -> + zimFileNodes[index].performTouchInput { longClick() } } clickOnFileDeleteIcon() clickOnDeleteZimFile() 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 872202364..c06adb7b9 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 @@ -24,14 +24,9 @@ import androidx.lifecycle.Lifecycle import androidx.preference.PreferenceManager import androidx.test.core.app.ActivityScenario import androidx.test.espresso.accessibility.AccessibilityChecks -import androidx.test.espresso.matcher.ViewMatchers import androidx.test.platform.app.InstrumentationRegistry import androidx.test.uiautomator.UiDevice -import com.google.android.apps.common.testing.accessibility.framework.AccessibilityCheckResultUtils.matchesCheck -import com.google.android.apps.common.testing.accessibility.framework.AccessibilityCheckResultUtils.matchesViews -import com.google.android.apps.common.testing.accessibility.framework.checks.DuplicateClickableBoundsCheck import leakcanary.LeakAssertions -import org.hamcrest.Matchers.allOf import org.junit.After import org.junit.Before import org.junit.Rule @@ -60,12 +55,6 @@ class LocalLibraryTest : BaseActivityTest() { init { AccessibilityChecks.enable().apply { setRunChecksFromRootView(true) - setSuppressingResultMatcher( - allOf( - matchesCheck(DuplicateClickableBoundsCheck::class.java), - matchesViews(ViewMatchers.withId(R.id.get_zim_nearby_device)) - ) - ) } } @@ -142,6 +131,7 @@ class LocalLibraryTest : BaseActivityTest() { } library { refreshList(composeTestRule) + waitUntilZimFilesRefreshing(composeTestRule) assertLibraryListDisplayed(composeTestRule) } LeakAssertions.assertNoLeaks() diff --git a/app/src/androidTest/java/org/kiwix/kiwixmobile/nav/destination/library/OnlineLibraryFragmentTest.kt b/app/src/androidTest/java/org/kiwix/kiwixmobile/nav/destination/library/OnlineLibraryFragmentTest.kt index e83c86a78..0cacf9048 100644 --- a/app/src/androidTest/java/org/kiwix/kiwixmobile/nav/destination/library/OnlineLibraryFragmentTest.kt +++ b/app/src/androidTest/java/org/kiwix/kiwixmobile/nav/destination/library/OnlineLibraryFragmentTest.kt @@ -23,14 +23,9 @@ import androidx.lifecycle.Lifecycle import androidx.preference.PreferenceManager import androidx.test.core.app.ActivityScenario import androidx.test.espresso.accessibility.AccessibilityChecks -import androidx.test.espresso.matcher.ViewMatchers import androidx.test.platform.app.InstrumentationRegistry import androidx.test.uiautomator.UiDevice import com.adevinta.android.barista.interaction.BaristaSleepInteractions -import com.google.android.apps.common.testing.accessibility.framework.AccessibilityCheckResultUtils.matchesCheck -import com.google.android.apps.common.testing.accessibility.framework.AccessibilityCheckResultUtils.matchesViews -import com.google.android.apps.common.testing.accessibility.framework.checks.DuplicateClickableBoundsCheck -import org.hamcrest.Matchers.allOf import org.junit.Before import org.junit.Rule import org.junit.Test @@ -55,12 +50,6 @@ class OnlineLibraryFragmentTest : BaseActivityTest() { init { AccessibilityChecks.enable().apply { setRunChecksFromRootView(true) - setSuppressingResultMatcher( - allOf( - matchesCheck(DuplicateClickableBoundsCheck::class.java), - matchesViews(ViewMatchers.withId(R.id.get_zim_nearby_device)) - ) - ) } } 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 ca110a4bd..7c86b46a5 100644 --- a/app/src/androidTest/java/org/kiwix/kiwixmobile/note/NoteFragmentTest.kt +++ b/app/src/androidTest/java/org/kiwix/kiwixmobile/note/NoteFragmentTest.kt @@ -26,14 +26,12 @@ import androidx.lifecycle.Lifecycle import androidx.preference.PreferenceManager import androidx.test.core.app.ActivityScenario import androidx.test.espresso.accessibility.AccessibilityChecks -import androidx.test.espresso.matcher.ViewMatchers import androidx.test.espresso.matcher.ViewMatchers.withContentDescription import androidx.test.internal.runner.junit4.statement.UiThreadStatement import androidx.test.platform.app.InstrumentationRegistry import androidx.test.uiautomator.UiDevice import com.google.android.apps.common.testing.accessibility.framework.AccessibilityCheckResultUtils.matchesCheck import com.google.android.apps.common.testing.accessibility.framework.AccessibilityCheckResultUtils.matchesViews -import com.google.android.apps.common.testing.accessibility.framework.checks.DuplicateClickableBoundsCheck import com.google.android.apps.common.testing.accessibility.framework.checks.SpeakableTextPresentCheck import com.google.android.apps.common.testing.accessibility.framework.checks.TouchTargetSizeCheck import leakcanary.LeakAssertions @@ -48,8 +46,8 @@ 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.local.LocalLibraryFragmentDirections import org.kiwix.kiwixmobile.nav.destination.library.library +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 @@ -105,10 +103,6 @@ class NoteFragmentTest : BaseActivityTest() { setRunChecksFromRootView(true) setSuppressingResultMatcher( anyOf( - allOf( - matchesCheck(DuplicateClickableBoundsCheck::class.java), - matchesViews(ViewMatchers.withId(R.id.get_zim_nearby_device)) - ), allOf( matchesCheck(TouchTargetSizeCheck::class.java), matchesViews(withContentDescription("More options")) diff --git a/app/src/androidTest/java/org/kiwix/kiwixmobile/shortcuts/GetContentShortcutTest.kt b/app/src/androidTest/java/org/kiwix/kiwixmobile/shortcuts/GetContentShortcutTest.kt index 0621a2ab5..f592d9080 100644 --- a/app/src/androidTest/java/org/kiwix/kiwixmobile/shortcuts/GetContentShortcutTest.kt +++ b/app/src/androidTest/java/org/kiwix/kiwixmobile/shortcuts/GetContentShortcutTest.kt @@ -20,6 +20,7 @@ package org.kiwix.kiwixmobile.shortcuts import android.app.Instrumentation import android.content.Intent +import androidx.compose.ui.test.junit4.createComposeRule import androidx.core.content.edit import androidx.lifecycle.Lifecycle import androidx.preference.PreferenceManager @@ -55,6 +56,9 @@ class GetContentShortcutTest { @JvmField val retryRule = RetryRule() + @get:Rule + val composeTestRule = createComposeRule() + init { AccessibilityChecks.enable().setRunChecksFromRootView(true) } @@ -111,8 +115,10 @@ class GetContentShortcutTest { } clickDownloadOnBottomNav(OnlineLibraryRobot::assertLibraryListDisplayed) clickLibraryOnBottomNav { - assertGetZimNearbyDeviceDisplayed() - clickFileTransferIcon(LocalFileTransferRobot::assertReceiveFileTitleVisible) + assertGetZimNearbyDeviceDisplayed(composeTestRule) + clickFileTransferIcon(composeTestRule) { + LocalFileTransferRobot::assertReceiveFileTitleVisible + } } clickBookmarksOnNavDrawer { assertBookMarksDisplayed() 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 d4a36ccb9..119d36852 100644 --- a/app/src/androidTest/java/org/kiwix/kiwixmobile/webserver/ZimHostFragmentTest.kt +++ b/app/src/androidTest/java/org/kiwix/kiwixmobile/webserver/ZimHostFragmentTest.kt @@ -25,14 +25,10 @@ import androidx.compose.ui.test.junit4.createComposeRule import androidx.lifecycle.Lifecycle import androidx.test.core.app.ActivityScenario import androidx.test.espresso.accessibility.AccessibilityChecks -import androidx.test.espresso.matcher.ViewMatchers.withId import androidx.test.platform.app.InstrumentationRegistry import androidx.test.rule.GrantPermissionRule import androidx.test.uiautomator.UiDevice -import com.google.android.apps.common.testing.accessibility.framework.AccessibilityCheckResultUtils.matchesCheck -import com.google.android.apps.common.testing.accessibility.framework.AccessibilityCheckResultUtils.matchesViews -import com.google.android.apps.common.testing.accessibility.framework.checks.DuplicateClickableBoundsCheck -import org.hamcrest.Matchers.allOf +import leakcanary.LeakAssertions import org.junit.After import org.junit.Before import org.junit.Rule @@ -87,12 +83,6 @@ class ZimHostFragmentTest { init { AccessibilityChecks.enable().apply { setRunChecksFromRootView(true) - setSuppressingResultMatcher( - allOf( - matchesCheck(DuplicateClickableBoundsCheck::class.java), - matchesViews(withId(R.id.get_zim_nearby_device)) - ) - ) } } @@ -149,7 +139,7 @@ class ZimHostFragmentTest { loadZimFileInApplication("small.zim") zimHost { refreshLibraryList(composeTestRule) - assertZimFilesLoaded() + assertZimFilesLoaded(composeTestRule) openZimHostFragment() // Check if server is already started @@ -200,6 +190,7 @@ class ZimHostFragmentTest { stopServer(composeTestRule) } } + LeakAssertions.assertNoLeaks() } private fun loadZimFileInApplication(zimFileName: String) { 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 fc322a770..24a63c537 100644 --- a/app/src/androidTest/java/org/kiwix/kiwixmobile/webserver/ZimHostRobot.kt +++ b/app/src/androidTest/java/org/kiwix/kiwixmobile/webserver/ZimHostRobot.kt @@ -18,11 +18,13 @@ package org.kiwix.kiwixmobile.webserver +import androidx.compose.ui.test.assertCountEquals import androidx.compose.ui.test.assertIsDisplayed import androidx.compose.ui.test.assertIsNotDisplayed import androidx.compose.ui.test.assertIsOn import androidx.compose.ui.test.assertTextEquals import androidx.compose.ui.test.junit4.ComposeContentTestRule +import androidx.compose.ui.test.onAllNodesWithTag import androidx.compose.ui.test.onNodeWithTag import androidx.compose.ui.test.performClick import androidx.test.espresso.Espresso.onView @@ -40,6 +42,7 @@ 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.ui.BOOK_ITEM_TESTING_TAG import org.kiwix.kiwixmobile.utils.StandardActions.openDrawer fun zimHost(func: ZimHostRobot.() -> Unit) = ZimHostRobot().applyWithViewHierarchyPrinting(func) @@ -50,15 +53,16 @@ class ZimHostRobot : BaseRobot() { } fun refreshLibraryList(composeTestRule: ComposeContentTestRule) { - pauseForBetterTestPerformance() - composeTestRule.runOnIdle { - composeTestRule.refresh() + composeTestRule.apply { + waitForIdle() + refresh() } } - fun assertZimFilesLoaded() { + fun assertZimFilesLoaded(composeTestRule: ComposeContentTestRule) { pauseForBetterTestPerformance() - isVisible(Text("Test_Zim")) + val zimFileNodes = composeTestRule.onAllNodesWithTag(BOOK_ITEM_TESTING_TAG) + zimFileNodes.assertCountEquals(2) } fun openZimHostFragment() { @@ -137,7 +141,7 @@ class ZimHostRobot : BaseRobot() { try { composeTestRule.onNodeWithTag("$BOOK_ITEM_CHECKBOX_TESTING_TAG$position") .assertIsOn() - } catch (_: AssertionFailedError) { + } catch (_: AssertionError) { composeTestRule.onNodeWithTag("$BOOK_ITEM_CHECKBOX_TESTING_TAG$position") .performClick() } diff --git a/app/src/main/java/org/kiwix/kiwixmobile/nav/destination/library/local/LocalLibraryFragment.kt b/app/src/main/java/org/kiwix/kiwixmobile/nav/destination/library/local/LocalLibraryFragment.kt index 39457c532..acffc6465 100644 --- a/app/src/main/java/org/kiwix/kiwixmobile/nav/destination/library/local/LocalLibraryFragment.kt +++ b/app/src/main/java/org/kiwix/kiwixmobile/nav/destination/library/local/LocalLibraryFragment.kt @@ -183,10 +183,12 @@ class LocalLibraryFragment : BaseFragment(), CopyMoveFileHandler.FileCopyMoveCal LaunchedEffect(isBottomNavVisible) { (requireActivity() as KiwixMainActivity).toggleBottomNavigation(isBottomNavVisible) } - updateLibraryScreenState( - bottomNavigationHeight = getBottomNavigationHeight(), - actionMenuItems = actionMenuItems() - ) + LaunchedEffect(Unit) { + updateLibraryScreenState( + bottomNavigationHeight = getBottomNavigationHeight(), + actionMenuItems = actionMenuItems() + ) + } LocalLibraryScreen( listState = lazyListState, state = libraryScreenState.value, diff --git a/app/src/main/java/org/kiwix/kiwixmobile/ui/BookItem.kt b/app/src/main/java/org/kiwix/kiwixmobile/ui/BookItem.kt index 34c43980e..5d758c8ff 100644 --- a/app/src/main/java/org/kiwix/kiwixmobile/ui/BookItem.kt +++ b/app/src/main/java/org/kiwix/kiwixmobile/ui/BookItem.kt @@ -58,6 +58,7 @@ import org.kiwix.kiwixmobile.core.zim_manager.fileselect_view.SelectionMode import org.kiwix.kiwixmobile.core.zim_manager.fileselect_view.adapter.BooksOnDiskListItem.BookOnDisk const val BOOK_ITEM_CHECKBOX_TESTING_TAG = "bookItemCheckboxTestingTag" +const val BOOK_ITEM_TESTING_TAG = "bookItemTestingTag" @OptIn(ExperimentalFoundationApi::class) @Composable @@ -86,7 +87,8 @@ fun BookItem( onLongClick?.invoke(bookOnDisk) } } - ), + ) + .testTag(BOOK_ITEM_TESTING_TAG), shape = MaterialTheme.shapes.extraSmall, elevation = CardDefaults.elevatedCardElevation(), colors = CardDefaults.cardColors(containerColor = MaterialTheme.colorScheme.surfaceContainer) diff --git a/buildSrc/src/main/kotlin/Versions.kt b/buildSrc/src/main/kotlin/Versions.kt index 5b34fa35e..562cf6cd1 100644 --- a/buildSrc/src/main/kotlin/Versions.kt +++ b/buildSrc/src/main/kotlin/Versions.kt @@ -56,7 +56,7 @@ object Versions { const val javax_annotation_api: String = "1.3.2" - const val leakcanary_android: String = "2.13" + const val leakcanary_android: String = "2.14" const val constraintlayout: String = "2.1.4" diff --git a/core/src/main/java/org/kiwix/kiwixmobile/core/main/CoreReaderFragment.kt b/core/src/main/java/org/kiwix/kiwixmobile/core/main/CoreReaderFragment.kt index 936cc2da1..884264883 100644 --- a/core/src/main/java/org/kiwix/kiwixmobile/core/main/CoreReaderFragment.kt +++ b/core/src/main/java/org/kiwix/kiwixmobile/core/main/CoreReaderFragment.kt @@ -1253,8 +1253,7 @@ abstract class CoreReaderFragment : ignore.printStackTrace() } if (sharedPreferenceUtil?.showIntro() == true) { - val activity = requireActivity() as AppCompatActivity? - activity?.setSupportActionBar(null) + (requireActivity() as? AppCompatActivity)?.setSupportActionBar(null) } repositoryActions?.dispose() safeDispose() @@ -1281,7 +1280,7 @@ abstract class CoreReaderFragment : // to fix IntroFragmentTest see https://github.com/kiwix/kiwix-android/pull/3217 try { requireActivity().unbindService(serviceConnection) - } catch (ignore: IllegalArgumentException) { + } catch (_: IllegalArgumentException) { // to handle if service is already unbounded } unRegisterReadAloudService() @@ -1291,6 +1290,7 @@ abstract class CoreReaderFragment : donationDialogHandler = null } + @SuppressLint("ClickableViewAccessibility") private fun unBindViewsAndBinding() { activityMainRoot = null noOpenBookButton = null @@ -1313,11 +1313,15 @@ abstract class CoreReaderFragment : videoView = null contentFrame = null toolbarContainer = null + compatCallback?.finish() + compatCallback = null + toolbar?.setOnTouchListener(null) toolbar = null progressBar = null drawerLayout = null closeAllTabsButton = null tableDrawerRightContainer = null + fragmentReaderBinding?.root?.removeAllViews() fragmentReaderBinding = null donationLayout?.removeAllViews() donationLayout = null @@ -2508,7 +2512,7 @@ abstract class CoreReaderFragment : repositoryActions?.clearWebViewPageHistory() } val coreApp = sharedPreferenceUtil?.context as CoreApp - val settings = coreApp.getMainActivity().getSharedPreferences( + val settings = coreApp.getSharedPreferences( SharedPreferenceUtil.PREF_KIWIX_MOBILE, 0 )