diff --git a/app/src/androidTest/java/org/kiwix/kiwixmobile/settings/KiwixSettingsActivityTest.java b/app/src/androidTest/java/org/kiwix/kiwixmobile/settings/KiwixSettingsActivityTest.java deleted file mode 100644 index 6ba4c18a4..000000000 --- a/app/src/androidTest/java/org/kiwix/kiwixmobile/settings/KiwixSettingsActivityTest.java +++ /dev/null @@ -1,95 +0,0 @@ -/* - * Kiwix Android - * Copyright (c) 2019 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.settings; - -import android.view.View; -import androidx.annotation.StringRes; -import androidx.recyclerview.widget.RecyclerView; -import androidx.test.rule.ActivityTestRule; -import org.hamcrest.Matcher; -import org.jetbrains.annotations.NotNull; -import org.junit.Rule; -import org.junit.Test; -import org.kiwix.kiwixmobile.core.R; - -import static androidx.test.espresso.Espresso.onView; -import static androidx.test.espresso.action.ViewActions.click; -import static androidx.test.espresso.contrib.RecyclerViewActions.actionOnItem; -import static androidx.test.espresso.matcher.ViewMatchers.hasDescendant; -import static androidx.test.espresso.matcher.ViewMatchers.withClassName; -import static androidx.test.espresso.matcher.ViewMatchers.withText; -import static com.schibsted.spain.barista.assertion.BaristaVisibilityAssertions.assertDisplayed; -import static org.hamcrest.Matchers.anyOf; -import static org.hamcrest.Matchers.is; - -public class KiwixSettingsActivityTest { - @Rule - public ActivityTestRule activityTestRule = - new ActivityTestRule<>(KiwixSettingsActivity.class); - - @Test - public void testToggle() { - clickOn(R.string.pref_back_to_top); - clickOn(R.string.pref_newtab_background_title); - clickOn(R.string.pref_external_link_popup_title); - clickOn(R.string.pref_wifi_only); - } - - private void clickOn(@StringRes int... stringIds) { - Matcher[] matchers = new Matcher[stringIds.length]; - for (int i = 0; i < stringIds.length; i++) { - matchers[i] = withText(stringIds[i]); - } - onView(withClassName(is(RecyclerView.class.getName()))) - .perform(actionOnItem(hasDescendant(anyOf(matchers)), click())); - } - - @Test - public void testLanguageDialog() { - clickOn(R.string.device_default); - assertDisplayed(R.string.pref_language_title); - } - - @Test - public void testStorageDialog() { - clickOn(R.string.internal_storage, R.string.external_storage); - assertDisplayed(R.string.pref_storage); - } - - @Test - public void testHistoryDialog() { - clickOn(R.string.pref_clear_all_history_title); - assertDisplayed(R.string.clear_all_history_dialog_title); - } - - @Test - public void testNightModeDialog() { - clickOn(R.string.pref_night_mode); - for (String nightModeString : nightModeStrings()) { - assertDisplayed(nightModeString); - } - } - - @NotNull private String[] nightModeStrings() { - return activityTestRule.getActivity() - .getResources() - .getStringArray(R.array.pref_night_modes_entries); - } -} - diff --git a/app/src/androidTest/java/org/kiwix/kiwixmobile/settings/KiwixSettingsActivityTest.kt b/app/src/androidTest/java/org/kiwix/kiwixmobile/settings/KiwixSettingsActivityTest.kt new file mode 100644 index 000000000..834895b5a --- /dev/null +++ b/app/src/androidTest/java/org/kiwix/kiwixmobile/settings/KiwixSettingsActivityTest.kt @@ -0,0 +1,53 @@ +/* + * Kiwix Android + * Copyright (c) 2019 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.settings + +import org.junit.Test +import org.kiwix.kiwixmobile.BaseActivityTest + +class KiwixSettingsActivityTest : BaseActivityTest() { + + override var activityRule = activityTestRule() + + @Test + fun testSettingsActivity() { + settingsRobo { + assertZoomTextViewPresent() + assertVersionTextViewPresent() + clickLanguagePreference() + assertLanguagePrefDialogDisplayed() + dismissDialog() + toggleBackToTopPref() + toggleOpenNewTabInBackground() + toggleExternalLinkWarningPref() + toggleWifiDownloadsOnlyPref() + clickStoragePreference() + assertStorageDialogDisplayed() + dismissDialog() + clickClearHistoryPreference() + assertHistoryDialogDisplayed() + dismissDialog() + clickNightModePreference() + assertNightModeDialogDisplayed() + dismissDialog() + clickCredits() + assertContributorsDialogDisplayed() + dismissDialog() + } + } +} diff --git a/app/src/androidTest/java/org/kiwix/kiwixmobile/settings/SettingsRobot.kt b/app/src/androidTest/java/org/kiwix/kiwixmobile/settings/SettingsRobot.kt new file mode 100644 index 000000000..2e5330ed4 --- /dev/null +++ b/app/src/androidTest/java/org/kiwix/kiwixmobile/settings/SettingsRobot.kt @@ -0,0 +1,133 @@ +/* + * Kiwix Android + * Copyright (c) 2020 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.settings + +import androidx.annotation.StringRes +import androidx.recyclerview.widget.RecyclerView +import androidx.test.espresso.Espresso.onView +import androidx.test.espresso.action.ViewActions +import androidx.test.espresso.contrib.RecyclerViewActions.actionOnItem +import androidx.test.espresso.matcher.ViewMatchers.hasDescendant +import androidx.test.espresso.matcher.ViewMatchers.withClassName +import androidx.test.espresso.matcher.ViewMatchers.withText +import applyWithViewHierarchyPrinting +import com.schibsted.spain.barista.assertion.BaristaVisibilityAssertions.assertDisplayed +import org.hamcrest.Matchers +import org.kiwix.kiwixmobile.BaseRobot +import org.kiwix.kiwixmobile.Findable.Text +import org.kiwix.kiwixmobile.R + +/** + * Authored by Ayush Shrivastava on 25/8/20 + */ + +fun settingsRobo(func: SettingsRobot.() -> Unit) = + SettingsRobot().applyWithViewHierarchyPrinting(func) + +class SettingsRobot : BaseRobot() { + + init { + assertDisplayed(R.string.menu_settings) + } + + private fun clickRecyclerViewItems(@StringRes vararg stringIds: Int) { + onView( + withClassName(Matchers.`is`(RecyclerView::class.java.name)) + ).perform( + actionOnItem( + hasDescendant(Matchers.anyOf(*stringIds.matchers())), ViewActions.click() + ) + ) + } + + fun toggleBackToTopPref() { + clickRecyclerViewItems(R.string.pref_back_to_top) + } + + fun toggleOpenNewTabInBackground() { + clickRecyclerViewItems(R.string.pref_newtab_background_title) + } + + fun toggleExternalLinkWarningPref() { + clickRecyclerViewItems(R.string.pref_external_link_popup_title) + } + + fun toggleWifiDownloadsOnlyPref() { + clickRecyclerViewItems(R.string.pref_wifi_only) + } + + fun clickLanguagePreference() { + clickRecyclerViewItems(R.string.device_default) + } + + fun assertLanguagePrefDialogDisplayed() { + assertDisplayed(R.string.pref_language_title) + } + + fun clickStoragePreference() { + clickRecyclerViewItems(R.string.internal_storage, R.string.external_storage) + } + + fun assertStorageDialogDisplayed() { + assertDisplayed(R.string.pref_storage) + } + + fun clickClearHistoryPreference() { + clickRecyclerViewItems(R.string.pref_clear_all_history_title) + } + + fun assertHistoryDialogDisplayed() { + assertDisplayed(R.string.clear_all_history_dialog_title) + } + + fun clickNightModePreference() { + clickRecyclerViewItems(R.string.pref_night_mode) + } + + fun assertNightModeDialogDisplayed() { + for (nightModeString in nightModeStrings()) { + assertDisplayed(nightModeString) + } + } + + fun clickCredits() { + clickRecyclerViewItems(R.string.pref_credits_title) + } + + fun assertContributorsDialogDisplayed() { + isVisible(Text("OK")) + } + + fun assertZoomTextViewPresent() { + clickRecyclerViewItems(R.string.pref_text_zoom_title) + } + + fun assertVersionTextViewPresent() { + clickRecyclerViewItems(R.string.pref_info_version) + } + + fun dismissDialog() { + pressBack() + } + + private fun nightModeStrings(): Array = + context.resources.getStringArray(R.array.pref_night_modes_entries) + + private fun IntArray.matchers() = map(::withText).toTypedArray() +}