diff --git a/app/src/androidTest/java/org/kiwix/kiwixmobile/error/ErrorActivityRobot.kt b/app/src/androidTest/java/org/kiwix/kiwixmobile/error/ErrorActivityRobot.kt index 66a1b2b32..0bb489cda 100644 --- a/app/src/androidTest/java/org/kiwix/kiwixmobile/error/ErrorActivityRobot.kt +++ b/app/src/androidTest/java/org/kiwix/kiwixmobile/error/ErrorActivityRobot.kt @@ -20,25 +20,32 @@ package org.kiwix.kiwixmobile.error import androidx.compose.ui.test.assertIsDisplayed import androidx.compose.ui.test.junit4.ComposeContentTestRule +import androidx.compose.ui.test.onNodeWithTag import androidx.compose.ui.test.onNodeWithText import androidx.compose.ui.test.performClick import com.adevinta.android.barista.interaction.BaristaSleepInteractions import org.kiwix.kiwixmobile.BaseRobot -import org.kiwix.kiwixmobile.Findable.StringId.TextId import org.kiwix.kiwixmobile.core.R +import org.kiwix.kiwixmobile.core.help.SEND_DIAGNOSTIC_REPORT_TESTING_TAG import org.kiwix.kiwixmobile.testutils.TestUtils fun errorActivity(func: ErrorActivityRobot.() -> Unit) = ErrorActivityRobot().apply(func) class ErrorActivityRobot : BaseRobot() { - fun assertSendDiagnosticReportDisplayed() { + fun assertSendDiagnosticReportDisplayed(composeTestRule: ComposeContentTestRule) { // Wait a bit for properly visible the HelpFragment. BaristaSleepInteractions.sleep(TestUtils.TEST_PAUSE_MS.toLong()) - isVisible(TextId(R.string.send_report)) + composeTestRule.apply { + waitForIdle() + onNodeWithTag(SEND_DIAGNOSTIC_REPORT_TESTING_TAG).assertIsDisplayed() + } } - fun clickOnSendDiagnosticReport() { - clickOn(TextId(R.string.send_report)) + fun clickOnSendDiagnosticReport(composeTestRule: ComposeContentTestRule) { + composeTestRule.apply { + waitForIdle() + onNodeWithTag(SEND_DIAGNOSTIC_REPORT_TESTING_TAG).performClick() + } } fun assertErrorActivityDisplayed(composeTestRule: ComposeContentTestRule) { diff --git a/app/src/androidTest/java/org/kiwix/kiwixmobile/error/ErrorActivityTest.kt b/app/src/androidTest/java/org/kiwix/kiwixmobile/error/ErrorActivityTest.kt index 13b683765..d4ae7474a 100644 --- a/app/src/androidTest/java/org/kiwix/kiwixmobile/error/ErrorActivityTest.kt +++ b/app/src/androidTest/java/org/kiwix/kiwixmobile/error/ErrorActivityTest.kt @@ -91,8 +91,8 @@ class ErrorActivityTest : BaseActivityTest() { it.navigate(R.id.helpFragment) } errorActivity { - assertSendDiagnosticReportDisplayed() - clickOnSendDiagnosticReport() + assertSendDiagnosticReportDisplayed(composeTestRule) + clickOnSendDiagnosticReport(composeTestRule) assertErrorActivityDisplayed(composeTestRule) // Click on "No, Thanks" button to see it's functionality working or not. clickOnNoThanksButton(composeTestRule) @@ -101,9 +101,9 @@ class ErrorActivityTest : BaseActivityTest() { it.navigate(R.id.helpFragment) } // Assert HelpFragment is visible or not after clicking on the "No, Thanks" button. - assertSendDiagnosticReportDisplayed() + assertSendDiagnosticReportDisplayed(composeTestRule) // Again click on "Send diagnostic report" button to open the ErrorActivity. - clickOnSendDiagnosticReport() + clickOnSendDiagnosticReport(composeTestRule) assertErrorActivityDisplayed(composeTestRule) // Check check boxes are displayed or not. assertCheckBoxesDisplayed(composeTestRule) diff --git a/app/src/androidTest/java/org/kiwix/kiwixmobile/help/HelpFragmentTest.kt b/app/src/androidTest/java/org/kiwix/kiwixmobile/help/HelpFragmentTest.kt index ad09c89ea..f3b3b2385 100644 --- a/app/src/androidTest/java/org/kiwix/kiwixmobile/help/HelpFragmentTest.kt +++ b/app/src/androidTest/java/org/kiwix/kiwixmobile/help/HelpFragmentTest.kt @@ -18,6 +18,7 @@ package org.kiwix.kiwixmobile.help import android.os.Build +import androidx.compose.ui.test.junit4.createComposeRule import androidx.lifecycle.Lifecycle import androidx.test.core.app.ActivityScenario import androidx.test.espresso.IdlingRegistry @@ -33,6 +34,7 @@ import org.kiwix.kiwixmobile.BaseActivityTest 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.core.utils.TestingUtils.COMPOSE_TEST_RULE_ORDER import org.kiwix.kiwixmobile.core.utils.TestingUtils.RETRY_RULE_ORDER import org.kiwix.kiwixmobile.main.KiwixMainActivity import org.kiwix.kiwixmobile.testutils.RetryRule @@ -43,6 +45,13 @@ import org.kiwix.kiwixmobile.utils.KiwixIdlingResource class HelpFragmentTest : BaseActivityTest() { private lateinit var sharedPreferenceUtil: SharedPreferenceUtil + @Rule(order = RETRY_RULE_ORDER) + @JvmField + val retryRule = RetryRule() + + @get:Rule(order = COMPOSE_TEST_RULE_ORDER) + val composeTestRule = createComposeRule() + @Before override fun waitForIdle() { UiDevice.getInstance(InstrumentationRegistry.getInstrumentation()).apply { @@ -66,10 +75,6 @@ class HelpFragmentTest : BaseActivityTest() { } } - @Rule(order = RETRY_RULE_ORDER) - @JvmField - val retryRule = RetryRule() - init { AccessibilityChecks.enable().setRunChecksFromRootView(true) } @@ -81,16 +86,16 @@ class HelpFragmentTest : BaseActivityTest() { it.navigate(R.id.helpFragment) } help { - clickOnWhatDoesKiwixDo() - assertWhatDoesKiwixDoIsExpanded() - clickOnWhatDoesKiwixDo() - clickOnWhereIsContent() - assertWhereIsContentIsExpanded() - clickOnWhereIsContent() - clickOnHowToUpdateContent() - assertHowToUpdateContentIsExpanded() - clickOnHowToUpdateContent() - assertWhyCopyMoveFilesToAppPublicDirectoryIsNotVisible() + clickOnWhatDoesKiwixDo(composeTestRule) + assertWhatDoesKiwixDoIsExpanded(composeTestRule) + clickOnWhatDoesKiwixDo(composeTestRule) + clickOnWhereIsContent(composeTestRule) + assertWhereIsContentIsExpanded(composeTestRule) + clickOnWhereIsContent(composeTestRule) + clickOnHowToUpdateContent(composeTestRule) + assertHowToUpdateContentIsExpanded(composeTestRule) + clickOnHowToUpdateContent(composeTestRule) + assertWhyCopyMoveFilesToAppPublicDirectoryIsNotVisible(composeTestRule) } LeakAssertions.assertNoLeaks() } @@ -103,18 +108,18 @@ class HelpFragmentTest : BaseActivityTest() { it.navigate(R.id.helpFragment) } help { - clickOnWhatDoesKiwixDo() - assertWhatDoesKiwixDoIsExpanded() - clickOnWhatDoesKiwixDo() - clickOnWhereIsContent() - assertWhereIsContentIsExpanded() - clickOnWhereIsContent() - clickOnHowToUpdateContent() - assertHowToUpdateContentIsExpanded() - clickOnHowToUpdateContent() - clickWhyCopyMoveFilesToAppPublicDirectory() - assertWhyCopyMoveFilesToAppPublicDirectoryIsExpanded() - clickWhyCopyMoveFilesToAppPublicDirectory() + clickOnWhatDoesKiwixDo(composeTestRule) + assertWhatDoesKiwixDoIsExpanded(composeTestRule) + clickOnWhatDoesKiwixDo(composeTestRule) + clickOnWhereIsContent(composeTestRule) + assertWhereIsContentIsExpanded(composeTestRule) + clickOnWhereIsContent(composeTestRule) + clickOnHowToUpdateContent(composeTestRule) + assertHowToUpdateContentIsExpanded(composeTestRule) + clickOnHowToUpdateContent(composeTestRule) + clickWhyCopyMoveFilesToAppPublicDirectory(composeTestRule) + assertWhyCopyMoveFilesToAppPublicDirectoryIsExpanded(composeTestRule) + clickWhyCopyMoveFilesToAppPublicDirectory(composeTestRule) } LeakAssertions.assertNoLeaks() } diff --git a/app/src/androidTest/java/org/kiwix/kiwixmobile/help/HelpRobot.kt b/app/src/androidTest/java/org/kiwix/kiwixmobile/help/HelpRobot.kt index 63a96e654..a9a07687c 100644 --- a/app/src/androidTest/java/org/kiwix/kiwixmobile/help/HelpRobot.kt +++ b/app/src/androidTest/java/org/kiwix/kiwixmobile/help/HelpRobot.kt @@ -17,16 +17,21 @@ */ package org.kiwix.kiwixmobile.help +import androidx.compose.ui.test.assertContentDescriptionEquals +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 -import androidx.test.espresso.action.ViewActions.click import androidx.test.espresso.assertion.ViewAssertions.doesNotExist import androidx.test.espresso.matcher.ViewMatchers.withText import org.kiwix.kiwixmobile.BaseRobot -import org.kiwix.kiwixmobile.Findable.StringId.TextId -import org.kiwix.kiwixmobile.Findable.Text import org.kiwix.kiwixmobile.Findable.ViewId import org.kiwix.kiwixmobile.core.R.id import org.kiwix.kiwixmobile.core.R.string +import org.kiwix.kiwixmobile.core.help.HELP_SCREEN_ITEM_DESCRIPTION_TESTING_TAG +import org.kiwix.kiwixmobile.core.help.HELP_SCREEN_ITEM_TITLE_TESTING_TAG import org.kiwix.kiwixmobile.testutils.TestUtils.testFlakyView fun help(func: HelpRobot.() -> Unit) = HelpRobot().apply(func) @@ -36,61 +41,100 @@ class HelpRobot : BaseRobot() { isVisible(ViewId(id.toolbar)) } - fun clickOnWhatDoesKiwixDo() { - testFlakyView({ onView(withText(string.help_2)).perform(click()) }) + fun clickOnWhatDoesKiwixDo(composeTestRule: ComposeContentTestRule) { + clickOnHelpScreenItemTitle(0, composeTestRule) } - fun assertWhatDoesKiwixDoIsExpanded() { - isVisible( - Text( - helpTextFormat( - string.help_3, - string.help_4 - ) - ) + fun assertWhatDoesKiwixDoIsExpanded(composeTestRule: ComposeContentTestRule) { + assertHelpScreenDescriptionDisplayed( + helpTextFormat(string.help_3, string.help_4), + composeTestRule ) } - fun clickOnWhereIsContent() { - clickOn(TextId(string.help_5)) + fun clickOnWhereIsContent(composeTestRule: ComposeContentTestRule) { + clickOnHelpScreenItemTitle(1, composeTestRule) } - fun assertWhereIsContentIsExpanded() { - isVisible( - Text( - helpTextFormat( - string.help_6, - string.help_7, - string.help_8, - string.help_9, - string.help_10, - string.help_11 - ) - ) + fun assertWhereIsContentIsExpanded(composeTestRule: ComposeContentTestRule) { + assertHelpScreenDescriptionDisplayed( + helpTextFormat( + string.help_6, + string.help_7, + string.help_8, + string.help_9, + string.help_10, + string.help_11 + ), + composeTestRule ) } - fun clickOnHowToUpdateContent() { - clickOn(TextId(string.how_to_update_content)) + fun clickOnHowToUpdateContent(composeTestRule: ComposeContentTestRule) { + clickOnHelpScreenItemTitle(2, composeTestRule) } - fun assertHowToUpdateContentIsExpanded() { - isVisible(TextId(string.update_content_description)) + fun assertHowToUpdateContentIsExpanded(composeTestRule: ComposeContentTestRule) { + assertHelpScreenDescriptionDisplayed( + context.getString(string.update_content_description), + composeTestRule + ) } - fun clickWhyCopyMoveFilesToAppPublicDirectory() { - clickOn(TextId(string.why_copy_move_files_to_app_directory)) + fun clickWhyCopyMoveFilesToAppPublicDirectory(composeTestRule: ComposeContentTestRule) { + clickOnHelpScreenItemTitle(3, composeTestRule) } - fun assertWhyCopyMoveFilesToAppPublicDirectoryIsExpanded() { - isVisible(Text(context.getString(string.copy_move_files_to_app_directory_description))) + fun assertWhyCopyMoveFilesToAppPublicDirectoryIsExpanded(composeTestRule: ComposeContentTestRule) { + assertHelpScreenDescriptionDisplayed( + context.getString(string.copy_move_files_to_app_directory_description), + composeTestRule + ) } - fun assertWhyCopyMoveFilesToAppPublicDirectoryIsNotVisible() { + fun assertWhyCopyMoveFilesToAppPublicDirectoryIsNotVisible(composeTestRule: ComposeContentTestRule) { + composeTestRule.apply { + waitForIdle() + val itemTitleList = onAllNodesWithTag(HELP_SCREEN_ITEM_TITLE_TESTING_TAG) + val itemCount = itemTitleList.fetchSemanticsNodes().size + repeat(itemCount) { index -> + try { + itemTitleList[index] + .assertTextEquals(context.getString(string.why_copy_move_files_to_app_directory)) + // If "Why copy/move files to app public directory?" item is visible throw the error. + throw RuntimeException("\"Why copy/move files to app public directory?\" help item is visible in non-playStore variant") + } catch (_: AssertionError) { + // If not found then nothing will do. + } + } + } onView(withText(string.why_copy_move_files_to_app_directory)) .check(doesNotExist()) } + private fun clickOnHelpScreenItemTitle(index: Int, composeTestRule: ComposeContentTestRule) { + testFlakyView({ + composeTestRule.apply { + waitForIdle() + val itemTitleList = onAllNodesWithTag(HELP_SCREEN_ITEM_TITLE_TESTING_TAG) + itemTitleList[index].performClick() + } + }) + } + + private fun assertHelpScreenDescriptionDisplayed( + description: String, + composeTestRule: ComposeContentTestRule + ) { + testFlakyView({ + composeTestRule.apply { + waitForIdle() + onNodeWithTag(HELP_SCREEN_ITEM_DESCRIPTION_TESTING_TAG) + .assertContentDescriptionEquals(description) + } + }) + } + private fun helpTextFormat(vararg stringIds: Int) = stringIds.joinToString(separator = "\n", transform = context::getString) } diff --git a/core/src/main/java/org/kiwix/kiwixmobile/core/help/HelpScreen.kt b/core/src/main/java/org/kiwix/kiwixmobile/core/help/HelpScreen.kt index 2ebbce795..0b06bde81 100644 --- a/core/src/main/java/org/kiwix/kiwixmobile/core/help/HelpScreen.kt +++ b/core/src/main/java/org/kiwix/kiwixmobile/core/help/HelpScreen.kt @@ -29,6 +29,7 @@ import androidx.compose.foundation.layout.fillMaxWidth import androidx.compose.foundation.layout.padding import androidx.compose.foundation.lazy.LazyColumn import androidx.compose.foundation.lazy.itemsIndexed +import androidx.compose.material3.ExperimentalMaterial3Api import androidx.compose.material3.HorizontalDivider import androidx.compose.material3.MaterialTheme import androidx.compose.material3.Scaffold @@ -39,6 +40,7 @@ import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier import androidx.compose.ui.graphics.Color import androidx.compose.ui.platform.LocalContext +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 @@ -52,6 +54,11 @@ import org.kiwix.kiwixmobile.core.ui.theme.MineShaftGray600 import org.kiwix.kiwixmobile.core.utils.ComposeDimens.HELP_SCREEN_DIVIDER_HEIGHT import org.kiwix.kiwixmobile.core.utils.ComposeDimens.SIXTEEN_DP +const val SEND_DIAGNOSTIC_REPORT_TESTING_TAG = "sendDiagnosticReportTestingTag" +const val HELP_SCREEN_ITEM_TITLE_TESTING_TAG = "helpScreenItemTitleTestingTag" +const val HELP_SCREEN_ITEM_DESCRIPTION_TESTING_TAG = "helpScreenItemDescriptionTestingTag" + +@OptIn(ExperimentalMaterial3Api::class) @Suppress("ComposableLambdaParameterNaming") @Composable fun HelpScreen( @@ -86,7 +93,8 @@ fun SendReportRow() { Row( modifier = Modifier .fillMaxWidth() - .clickable { (context as? Activity)?.start() }, + .clickable { (context as? Activity)?.start() } + .testTag(SEND_DIAGNOSTIC_REPORT_TESTING_TAG), verticalAlignment = Alignment.CenterVertically, horizontalArrangement = Arrangement.Start ) { diff --git a/core/src/main/java/org/kiwix/kiwixmobile/core/help/HelpScreenItem.kt b/core/src/main/java/org/kiwix/kiwixmobile/core/help/HelpScreenItem.kt index 2e754499e..d2f921307 100644 --- a/core/src/main/java/org/kiwix/kiwixmobile/core/help/HelpScreenItem.kt +++ b/core/src/main/java/org/kiwix/kiwixmobile/core/help/HelpScreenItem.kt @@ -56,7 +56,10 @@ import androidx.compose.ui.graphics.ColorFilter import androidx.compose.ui.graphics.graphicsLayer import androidx.compose.ui.graphics.toArgb import androidx.compose.ui.platform.LocalContext +import androidx.compose.ui.platform.testTag import androidx.compose.ui.res.stringResource +import androidx.compose.ui.semantics.contentDescription +import androidx.compose.ui.semantics.semantics import androidx.compose.ui.text.font.FontWeight import androidx.compose.ui.viewinterop.AndroidView import androidx.core.text.util.LinkifyCompat @@ -114,6 +117,7 @@ fun HelpItemHeader( modifier = Modifier .fillMaxWidth() .clickable(interactionSource = interactionSource, indication = null, onClick = onToggle) + .testTag(HELP_SCREEN_ITEM_TITLE_TESTING_TAG) ) { Text( text = title, @@ -156,6 +160,8 @@ fun HelpItemDescription(context: Context, description: String) { AndroidView( factory = { helpItemDescription }, modifier = Modifier.padding(bottom = SIXTEEN_DP) + .testTag(HELP_SCREEN_ITEM_DESCRIPTION_TESTING_TAG) + .semantics { contentDescription = description } ) { textView -> textView.apply { text = description diff --git a/lintConfig.xml b/lintConfig.xml index 5ef86f071..44af8acfc 100644 --- a/lintConfig.xml +++ b/lintConfig.xml @@ -1,6 +1,5 @@ -