Merge pull request #2431 from s-ayush2903/tests/s-ayush2903/#2359-Revamp-and-Refine-Instrumentation-Test-for-KiwixMainActivity

tests: Revamped and Added Tests in the KiwixMainActivityTest
This commit is contained in:
Seán Mac Gillicuddy 2020-11-06 11:10:02 +00:00 committed by GitHub
commit c93d581bc9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
11 changed files with 427 additions and 108 deletions

View File

@ -25,8 +25,8 @@ import org.kiwix.kiwixmobile.Findable.StringId.TextId
import org.kiwix.kiwixmobile.Findable.ViewId
import org.kiwix.kiwixmobile.LONG_WAIT
import org.kiwix.kiwixmobile.R
import org.kiwix.kiwixmobile.main.MainRobot
import org.kiwix.kiwixmobile.main.main
import org.kiwix.kiwixmobile.main.TopLevelDestinationRobot
import org.kiwix.kiwixmobile.main.topLevel
fun intro(func: IntroRobot.() -> Unit) = IntroRobot().applyWithViewHierarchyPrinting(func)
@ -49,8 +49,8 @@ class IntroRobot : BaseRobot() {
}
}
infix fun clickGetStarted(func: MainRobot.() -> Unit): MainRobot {
infix fun clickGetStarted(func: TopLevelDestinationRobot.() -> Unit): TopLevelDestinationRobot {
clickOn(getStarted)
return main(func)
return topLevel(func)
}
}

View File

@ -0,0 +1,38 @@
/*
* Kiwix Android
* Copyright (c) 2020 Kiwix <android.kiwix.org>
* 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 <http://www.gnu.org/licenses/>.
*
*/
package org.kiwix.kiwixmobile.localFileTransfer
import applyWithViewHierarchyPrinting
import org.kiwix.kiwixmobile.BaseRobot
import org.kiwix.kiwixmobile.Findable.StringId.TextId
import org.kiwix.kiwixmobile.R
/**
* Authored by Ayush Shrivastava on 29/10/20
*/
fun localFileTransfer(func: LocalFileTransferRobot.() -> Unit) =
LocalFileTransferRobot().applyWithViewHierarchyPrinting(func)
class LocalFileTransferRobot : BaseRobot() {
init {
isVisible(TextId(R.string.receive_files_title))
}
}

View File

@ -1,99 +0,0 @@
/*
* Kiwix Android
* Copyright (c) 2019 Kiwix <android.kiwix.org>
* 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 <http://www.gnu.org/licenses/>.
*
*/
package org.kiwix.kiwixmobile.main;
import android.Manifest;
import androidx.test.espresso.matcher.ViewMatchers;
import androidx.test.ext.junit.runners.AndroidJUnit4;
import androidx.test.filters.LargeTest;
import androidx.test.rule.ActivityTestRule;
import androidx.test.rule.GrantPermissionRule;
import com.schibsted.spain.barista.interaction.BaristaMenuClickInteractions;
import com.schibsted.spain.barista.interaction.BaristaSleepInteractions;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
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.matcher.ViewMatchers.withEffectiveVisibility;
import static androidx.test.espresso.matcher.ViewMatchers.withText;
import static com.schibsted.spain.barista.interaction.BaristaClickInteractions.clickOn;
import static org.hamcrest.CoreMatchers.allOf;
import static org.kiwix.kiwixmobile.testutils.TestUtils.TEST_PAUSE_MS;
import static org.kiwix.kiwixmobile.testutils.TestUtils.getResourceString;
import static org.kiwix.kiwixmobile.utils.StandardActions.enterSettings;
import static org.kiwix.kiwixmobile.utils.StandardActions.openDrawer;
@LargeTest
@RunWith(AndroidJUnit4.class)
public class MainActivityTest {
@Rule
public ActivityTestRule<KiwixMainActivity> activityTestRule =
new ActivityTestRule<>(KiwixMainActivity.class);
@Rule
public GrantPermissionRule readPermissionRule =
GrantPermissionRule.grant(Manifest.permission.READ_EXTERNAL_STORAGE);
@Rule
public GrantPermissionRule writePermissionRule =
GrantPermissionRule.grant(Manifest.permission.WRITE_EXTERNAL_STORAGE);
@Before
public void setup() {
BaristaSleepInteractions.sleep(TEST_PAUSE_MS);
onView(allOf(withText(R.string.reader),
withEffectiveVisibility(ViewMatchers.Visibility.VISIBLE))).perform(click());
BaristaSleepInteractions.sleep(TEST_PAUSE_MS);
}
@Test
public void navigateHelp() {
BaristaSleepInteractions.sleep(TEST_PAUSE_MS);
openDrawer();
clickOn(R.string.menu_help);
}
@Test
public void navigateSettings() {
BaristaSleepInteractions.sleep(TEST_PAUSE_MS);
openDrawer();
enterSettings();
}
@Test
public void navigateBookmarks() {
BaristaSleepInteractions.sleep(TEST_PAUSE_MS);
openDrawer();
BaristaMenuClickInteractions.clickMenu(getResourceString(R.string.bookmarks));
}
@Test
public void navigateDeviceContent() {
BaristaSleepInteractions.sleep(TEST_PAUSE_MS);
clickOn(R.string.library);
}
@Test
public void navigateOnlineContent() {
BaristaSleepInteractions.sleep(TEST_PAUSE_MS);
clickOn(R.string.download);
}
}

View File

@ -0,0 +1,121 @@
/*
* Kiwix Android
* Copyright (c) 2019 Kiwix <android.kiwix.org>
* 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 <http://www.gnu.org/licenses/>.
*
*/
package org.kiwix.kiwixmobile.main
import applyWithViewHierarchyPrinting
import org.kiwix.kiwixmobile.BaseRobot
import org.kiwix.kiwixmobile.Findable.StringId.TextId
import org.kiwix.kiwixmobile.Findable.ViewId
import org.kiwix.kiwixmobile.R
import org.kiwix.kiwixmobile.help.HelpRobot
import org.kiwix.kiwixmobile.help.help
import org.kiwix.kiwixmobile.nav.destination.library.LibraryRobot
import org.kiwix.kiwixmobile.nav.destination.library.OnlineLibraryRobot
import org.kiwix.kiwixmobile.nav.destination.library.library
import org.kiwix.kiwixmobile.nav.destination.library.onlineLibrary
import org.kiwix.kiwixmobile.nav.destination.reader.ReaderRobot
import org.kiwix.kiwixmobile.nav.destination.reader.reader
import org.kiwix.kiwixmobile.page.bookmarks.BookmarksRobot
import org.kiwix.kiwixmobile.page.bookmarks.bookmarks
import org.kiwix.kiwixmobile.page.history.HistoryRobot
import org.kiwix.kiwixmobile.page.history.history
import org.kiwix.kiwixmobile.settings.SettingsRobot
import org.kiwix.kiwixmobile.settings.settingsRobo
import org.kiwix.kiwixmobile.utils.StandardActions.openDrawer
import org.kiwix.kiwixmobile.webserver.ZimHostRobot
import org.kiwix.kiwixmobile.webserver.zimHost
fun topLevel(func: TopLevelDestinationRobot.() -> Unit) =
TopLevelDestinationRobot().applyWithViewHierarchyPrinting(func)
class TopLevelDestinationRobot : BaseRobot() {
init {
isVisible(ViewId(R.id.navigation_container))
}
fun clickReaderOnBottomNav(func: ReaderRobot.() -> Unit) {
clickOn(ViewId(R.id.readerFragment))
reader(func)
}
fun clickLibraryOnBottomNav(func: LibraryRobot.() -> Unit) {
clickOn(ViewId(R.id.libraryFragment))
library(func)
pressBack()
}
fun clickDownloadOnBottomNav(func: OnlineLibraryRobot.() -> Unit) {
clickOn(ViewId(R.id.downloadsFragment))
onlineLibrary(func)
pressBack()
}
private fun inNavDrawer(navDrawerAction: () -> Unit) {
openDrawer()
navDrawerAction.invoke()
pressBack()
}
fun clickBookmarksOnNavDrawer(func: BookmarksRobot.() -> Unit) {
inNavDrawer {
clickOn(TextId(R.string.bookmarks))
bookmarks(func)
pressBack()
}
}
fun clickHistoryOnSideNav(func: HistoryRobot.() -> Unit) {
inNavDrawer {
clickOn(TextId(R.string.history))
history(func)
pressBack()
}
}
fun clickHostBooksOnSideNav(func: ZimHostRobot.() -> Unit) {
inNavDrawer {
clickOn(TextId(R.string.menu_host_books))
zimHost(func)
}
}
fun clickSettingsOnSideNav(func: SettingsRobot.() -> Unit) {
inNavDrawer {
clickOn(TextId(R.string.menu_settings))
settingsRobo(func)
}
}
fun clickHelpOnSideNav(func: HelpRobot.() -> Unit) {
inNavDrawer {
clickOn(TextId(R.string.menu_help))
help(func)
}
}
fun clickSupportKiwixOnSideNav() {
inNavDrawer {
clickOn(TextId(R.string.menu_support_kiwix))
}
}
fun assertExternalLinkDialogDisplayed() {
isVisible(TextId(R.string.external_link_popup_dialog_title))
}
}

View File

@ -0,0 +1,61 @@
/*
* Kiwix Android
* Copyright (c) 2019 Kiwix <android.kiwix.org>
* 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 <http://www.gnu.org/licenses/>.
*
*/
package org.kiwix.kiwixmobile.main
import androidx.test.rule.ActivityTestRule
import org.junit.Rule
import org.junit.Test
class TopLevelDestinationTest {
@Rule
@JvmField
var activityTestRule = ActivityTestRule(KiwixMainActivity::class.java)
@Test
fun testTopLevelDestination() {
topLevel {
clickReaderOnBottomNav {
}
clickLibraryOnBottomNav {
clickFileTransferIcon {
}
}
clickDownloadOnBottomNav {
clickOnGlobeIcon {
}
}
clickBookmarksOnNavDrawer {
clickOnTrashIcon()
assertDeleteBookmarksDialogDisplayed()
}
clickHistoryOnSideNav {
clickOnTrashIcon()
assertDeleteHistoryDialogDisplayed()
}
clickHostBooksOnSideNav {
}
clickSettingsOnSideNav {
}
clickHelpOnSideNav {
}
clickSupportKiwixOnSideNav()
assertExternalLinkDialogDisplayed()
pressBack()
}
}
}

View File

@ -0,0 +1,39 @@
/*
* Kiwix Android
* Copyright (c) 2020 Kiwix <android.kiwix.org>
* 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 <http://www.gnu.org/licenses/>.
*
*/
package org.kiwix.kiwixmobile.nav.destination.library
import applyWithViewHierarchyPrinting
import org.kiwix.kiwixmobile.BaseRobot
import org.kiwix.kiwixmobile.Findable.ViewId
import org.kiwix.kiwixmobile.R
import org.kiwix.kiwixmobile.localFileTransfer.LocalFileTransferRobot
import org.kiwix.kiwixmobile.localFileTransfer.localFileTransfer
fun library(func: LibraryRobot.() -> Unit) = LibraryRobot().applyWithViewHierarchyPrinting(func)
class LibraryRobot : BaseRobot() {
init {
isVisible(ViewId(R.id.get_zim_nearby_device))
}
fun clickFileTransferIcon(func: LocalFileTransferRobot.() -> Unit) {
clickOn(ViewId(R.id.get_zim_nearby_device))
localFileTransfer(func)
}
}

View File

@ -0,0 +1,40 @@
/*
* Kiwix Android
* Copyright (c) 2020 Kiwix <android.kiwix.org>
* 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 <http://www.gnu.org/licenses/>.
*
*/
package org.kiwix.kiwixmobile.nav.destination.library
import applyWithViewHierarchyPrinting
import org.kiwix.kiwixmobile.BaseRobot
import org.kiwix.kiwixmobile.Findable.ViewId
import org.kiwix.kiwixmobile.R
import org.kiwix.kiwixmobile.language.LanguageRobot
import org.kiwix.kiwixmobile.language.language
fun onlineLibrary(func: OnlineLibraryRobot.() -> Unit) =
OnlineLibraryRobot().applyWithViewHierarchyPrinting(func)
class OnlineLibraryRobot : BaseRobot() {
init {
isVisible(ViewId(R.id.libraryList))
}
fun clickOnGlobeIcon(func: LanguageRobot.() -> Unit) {
clickOn(ViewId(R.id.select_language))
language(func)
}
}

View File

@ -1,6 +1,6 @@
/*
* Kiwix Android
* Copyright (c) 2019 Kiwix <android.kiwix.org>
* Copyright (c) 2020 Kiwix <android.kiwix.org>
* 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
@ -15,16 +15,18 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
package org.kiwix.kiwixmobile.main
package org.kiwix.kiwixmobile.nav.destination.reader
import applyWithViewHierarchyPrinting
import org.kiwix.kiwixmobile.BaseRobot
import org.kiwix.kiwixmobile.Findable.ViewId
import org.kiwix.kiwixmobile.R
fun main(func: MainRobot.() -> Unit) = MainRobot().apply(func)
fun reader(func: ReaderRobot.() -> Unit) = ReaderRobot().applyWithViewHierarchyPrinting(func)
class MainRobot : BaseRobot() {
class ReaderRobot : BaseRobot() {
init {
isVisible(ViewId(R.id.navigation_container))
isVisible(ViewId(R.id.activity_main_root))
}
}

View File

@ -0,0 +1,43 @@
/*
* Kiwix Android
* Copyright (c) 2020 Kiwix <android.kiwix.org>
* 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 <http://www.gnu.org/licenses/>.
*
*/
package org.kiwix.kiwixmobile.page.bookmarks
import applyWithViewHierarchyPrinting
import com.schibsted.spain.barista.assertion.BaristaVisibilityAssertions.assertDisplayed
import org.kiwix.kiwixmobile.BaseRobot
import org.kiwix.kiwixmobile.Findable.StringId.ContentDesc
import org.kiwix.kiwixmobile.Findable.StringId.TextId
import org.kiwix.kiwixmobile.R
fun bookmarks(func: BookmarksRobot.() -> Unit) =
BookmarksRobot().applyWithViewHierarchyPrinting(func)
class BookmarksRobot : BaseRobot() {
init {
assertDisplayed(R.string.bookmarks_from_current_book)
}
fun clickOnTrashIcon() {
clickOn(ContentDesc(R.string.pref_clear_all_bookmarks_title))
}
fun assertDeleteBookmarksDialogDisplayed() {
isVisible(TextId(R.string.delete_bookmarks))
}
}

View File

@ -0,0 +1,42 @@
/*
* Kiwix Android
* Copyright (c) 2020 Kiwix <android.kiwix.org>
* 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 <http://www.gnu.org/licenses/>.
*
*/
package org.kiwix.kiwixmobile.page.history
import applyWithViewHierarchyPrinting
import com.schibsted.spain.barista.assertion.BaristaVisibilityAssertions.assertDisplayed
import org.kiwix.kiwixmobile.BaseRobot
import org.kiwix.kiwixmobile.Findable.StringId.ContentDesc
import org.kiwix.kiwixmobile.Findable.StringId.TextId
import org.kiwix.kiwixmobile.R
fun history(func: HistoryRobot.() -> Unit) = HistoryRobot().applyWithViewHierarchyPrinting(func)
class HistoryRobot : BaseRobot() {
init {
assertDisplayed(R.string.history_from_current_book)
}
fun clickOnTrashIcon() {
clickOn(ContentDesc(R.string.pref_clear_all_bookmarks_title))
}
fun assertDeleteHistoryDialogDisplayed() {
isVisible(TextId(R.string.delete_history))
}
}

View File

@ -0,0 +1,32 @@
/*
* Kiwix Android
* Copyright (c) 2020 Kiwix <android.kiwix.org>
* 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 <http://www.gnu.org/licenses/>.
*
*/
package org.kiwix.kiwixmobile.webserver
import applyWithViewHierarchyPrinting
import org.kiwix.kiwixmobile.BaseRobot
import org.kiwix.kiwixmobile.Findable.StringId.TextId
import org.kiwix.kiwixmobile.R
fun zimHost(func: ZimHostRobot.() -> Unit) = ZimHostRobot().applyWithViewHierarchyPrinting(func)
class ZimHostRobot : BaseRobot() {
init {
isVisible(TextId(R.string.menu_host_books))
}
}