diff --git a/app/build.gradle.kts b/app/build.gradle.kts index 805350b16..edf461992 100644 --- a/app/build.gradle.kts +++ b/app/build.gradle.kts @@ -127,6 +127,7 @@ androidComponents { } dependencies { + androidTestImplementation(Libs.ANDROIDX_COMPOSE_UI_TEST_JUNIT4) androidTestImplementation(Libs.leakcanary_android_instrumentation) testImplementation(Libs.kotlinx_coroutines_test) } diff --git a/app/src/androidTest/java/org/kiwix/kiwixmobile/error/ErrorActivityRobot.kt b/app/src/androidTest/java/org/kiwix/kiwixmobile/error/ErrorActivityRobot.kt new file mode 100644 index 000000000..a11b3f738 --- /dev/null +++ b/app/src/androidTest/java/org/kiwix/kiwixmobile/error/ErrorActivityRobot.kt @@ -0,0 +1,68 @@ +/* + * Kiwix Android + * Copyright (c) 2025 Kiwix + * 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 . + * + */ + +package org.kiwix.kiwixmobile.error + +import androidx.compose.ui.test.assertIsDisplayed +import androidx.compose.ui.test.junit4.ComposeContentTestRule +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.testutils.TestUtils + +fun errorActivity(func: ErrorActivityRobot.() -> Unit) = ErrorActivityRobot().apply(func) + +class ErrorActivityRobot : BaseRobot() { + fun assertSendDiagnosticReportDisplayed() { + // Wait a bit for properly visible the HelpFragment. + BaristaSleepInteractions.sleep(TestUtils.TEST_PAUSE_MS.toLong()) + isVisible(TextId(R.string.send_report)) + } + + fun clickOnSendDiagnosticReport() { + clickOn(TextId(R.string.send_report)) + } + + fun assertErrorActivityDisplayed(composeTestRule: ComposeContentTestRule) { + // Wait a bit for properly visible the ErrorActivity. + BaristaSleepInteractions.sleep(TestUtils.TEST_PAUSE_MS.toLong()) + composeTestRule.onNodeWithText(context.getString(R.string.diagnostic_report)) + .assertIsDisplayed() + } + + fun clickOnNoThanksButton(composeTestRule: ComposeContentTestRule) { + composeTestRule.onNodeWithText(context.getString(R.string.no_thanks).uppercase()).performClick() + } + + fun assertCheckBoxesDisplayed(composeTestRule: ComposeContentTestRule) { + composeTestRule.onNodeWithText(context.getString(R.string.crash_checkbox_language)) + .assertIsDisplayed() + composeTestRule.onNodeWithText(context.getString(R.string.crash_checkbox_logs)) + .assertIsDisplayed() + composeTestRule.onNodeWithText(context.getString(R.string.crash_checkbox_zimfiles)) + .assertIsDisplayed() + } + + fun clickOnSendDetailsButton(composeTestRule: ComposeContentTestRule) { + composeTestRule.onNodeWithText(context.getString(R.string.crash_button_confirm).uppercase()) + .performClick() + } +} diff --git a/app/src/androidTest/java/org/kiwix/kiwixmobile/error/ErrorActivityTest.kt b/app/src/androidTest/java/org/kiwix/kiwixmobile/error/ErrorActivityTest.kt new file mode 100644 index 000000000..a69c357ca --- /dev/null +++ b/app/src/androidTest/java/org/kiwix/kiwixmobile/error/ErrorActivityTest.kt @@ -0,0 +1,108 @@ +/* + * Kiwix Android + * Copyright (c) 2025 Kiwix + * 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 . + * + */ + +package org.kiwix.kiwixmobile.error + +import androidx.compose.ui.test.junit4.createComposeRule +import androidx.core.content.edit +import androidx.lifecycle.Lifecycle +import androidx.preference.PreferenceManager +import androidx.test.core.app.ActivityScenario +import androidx.test.espresso.accessibility.AccessibilityChecks +import androidx.test.platform.app.InstrumentationRegistry +import androidx.test.uiautomator.UiDevice +import org.junit.Before +import org.junit.Rule +import org.junit.Test +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.main.KiwixMainActivity +import org.kiwix.kiwixmobile.testutils.RetryRule +import org.kiwix.kiwixmobile.testutils.TestUtils.closeSystemDialogs +import org.kiwix.kiwixmobile.testutils.TestUtils.isSystemUINotRespondingDialogVisible + +class ErrorActivityTest : BaseActivityTest() { + @Rule + @JvmField + var retryRule = RetryRule() + + @get:Rule + val composeTestRule = createComposeRule() + + @Before + override fun waitForIdle() { + UiDevice.getInstance(InstrumentationRegistry.getInstrumentation()).apply { + if (isSystemUINotRespondingDialogVisible(this)) { + closeSystemDialogs(context, this) + } + waitForIdle() + } + PreferenceManager.getDefaultSharedPreferences(context) + .edit { + putBoolean(SharedPreferenceUtil.PREF_SHOW_INTRO, false) + putBoolean(SharedPreferenceUtil.PREF_WIFI_ONLY, false) + putString(SharedPreferenceUtil.PREF_LANG, "en") + putLong( + SharedPreferenceUtil.PREF_LAST_DONATION_POPUP_SHOWN_IN_MILLISECONDS, + System.currentTimeMillis() + ) + } + activityScenario = + ActivityScenario.launch(KiwixMainActivity::class.java).apply { + moveToState(Lifecycle.State.RESUMED) + onActivity { + handleLocaleChange( + it, + "en", + SharedPreferenceUtil(context).apply { + lastDonationPopupShownInMilliSeconds = System.currentTimeMillis() + } + ) + } + } + } + + init { + AccessibilityChecks.enable().setRunChecksFromRootView(true) + } + + @Test + fun verifyErrorActivity() { + activityScenario.onActivity { + it.navigate(R.id.helpFragment) + } + errorActivity { + assertSendDiagnosticReportDisplayed() + clickOnSendDiagnosticReport() + assertErrorActivityDisplayed(composeTestRule) + // Click on "No, Thanks" button to see it's functionality working or not. + clickOnNoThanksButton(composeTestRule) + // Assert HelpFragment is visible or not after clicking on the "No, Thanks" button. + assertSendDiagnosticReportDisplayed() + // Again click on "Send diagnostic report" button to open the ErrorActivity. + clickOnSendDiagnosticReport() + assertErrorActivityDisplayed(composeTestRule) + // Check check boxes are displayed or not. + assertCheckBoxesDisplayed(composeTestRule) + // Click on "Send details" button. + clickOnSendDetailsButton(composeTestRule) + } + } +} diff --git a/buildSrc/src/main/kotlin/Libs.kt b/buildSrc/src/main/kotlin/Libs.kt index 357f88556..5c6b7f7c7 100644 --- a/buildSrc/src/main/kotlin/Libs.kt +++ b/buildSrc/src/main/kotlin/Libs.kt @@ -401,8 +401,11 @@ object Libs { * testing libraries for compose */ const val ANDROIDX_COMPOSE_UI_TEST_JUNIT4: String = - "androidx.compose.ui:ui-test-junit4" + "androidx.compose.ui:ui-test-junit4:${Versions.ANDROIDX_COMPOSE_UI_VERSION}" const val ANDROIDX_COMPOSE_UI_TOOLING: String = "androidx.compose.ui:ui-tooling" + + const val ANDROIDX_COMPOSE_UI_TEST_MANIFEST = + "androidx.compose.ui:ui-test-manifest:${Versions.ANDROIDX_COMPOSE_UI_VERSION}" } diff --git a/core/build.gradle.kts b/core/build.gradle.kts index 290c42ae7..04a8ee7ff 100644 --- a/core/build.gradle.kts +++ b/core/build.gradle.kts @@ -65,6 +65,6 @@ dependencies { implementation(Libs.zxing) implementation(platform(Libs.ANDROIDX_COMPOSE_BOM)) // For Compose UI Testing - androidTestImplementation(Libs.ANDROIDX_COMPOSE_UI_TEST_JUNIT4) debugImplementation(Libs.ANDROIDX_COMPOSE_UI_TOOLING) + debugImplementation(Libs.ANDROIDX_COMPOSE_UI_TEST_MANIFEST) } diff --git a/core/src/main/res/layout/activity_kiwix_error.xml b/core/src/main/res/layout/activity_kiwix_error.xml deleted file mode 100644 index 9568ead4a..000000000 --- a/core/src/main/res/layout/activity_kiwix_error.xml +++ /dev/null @@ -1,169 +0,0 @@ - - - - - -