Skip to content

Commit

Permalink
Improved test cases
Browse files Browse the repository at this point in the history
  • Loading branch information
MohitMaliDeveloper committed Feb 22, 2023
1 parent 389b31b commit 46d55bd
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@
*/
package org.kiwix.kiwixmobile.page.history

import androidx.test.espresso.web.sugar.Web.onWebView
import androidx.test.espresso.web.webdriver.DriverAtoms.findElement
import androidx.test.espresso.web.webdriver.DriverAtoms.webClick
import androidx.test.espresso.web.webdriver.Locator
import applyWithViewHierarchyPrinting
import com.adevinta.android.barista.interaction.BaristaSleepInteractions
import org.kiwix.kiwixmobile.BaseRobot
Expand All @@ -35,6 +39,18 @@ class NavigationHistoryRobot : BaseRobot() {
isVisible(ViewId(readerFragment))
}

fun clickOnAndroidArticle() {
BaristaSleepInteractions.sleep(TestUtils.TEST_PAUSE_MS_FOR_SEARCH_TEST.toLong())
onWebView()
.withElement(
findElement(
Locator.XPATH,
"//*[contains(text(), 'Android_(operating_system)')]"
)
)
.perform(webClick())
}

fun longClickOnBackwardButton() {
BaristaSleepInteractions.sleep(TestUtils.TEST_PAUSE_MS_FOR_SEARCH_TEST.toLong())
longClickOn(ViewId(R.id.bottom_toolbar_arrow_back))
Expand All @@ -45,8 +61,18 @@ class NavigationHistoryRobot : BaseRobot() {
longClickOn(ViewId(R.id.bottom_toolbar_arrow_forward))
}

fun assertNavigationHistoryDialogDisplayed() {
fun assertBackwardNavigationHistoryDialogDisplayed() {
BaristaSleepInteractions.sleep(TestUtils.TEST_PAUSE_MS_FOR_SEARCH_TEST.toLong())
isVisible(TextId(R.string.backward_history))
}

fun clickOnBackwardButton() {
BaristaSleepInteractions.sleep(TestUtils.TEST_PAUSE_MS_FOR_SEARCH_TEST.toLong())
clickOn(ViewId(R.id.bottom_toolbar_arrow_back))
}

fun assertForwardNavigationHistoryDialogDisplayed() {
BaristaSleepInteractions.sleep(TestUtils.TEST_PAUSE_MS_FOR_SEARCH_TEST.toLong())
isVisible(TextId(R.string.no_history))
isVisible(TextId(R.string.forward_history))
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -89,11 +89,13 @@ class NavigationHistoryTest : BaseActivityTest() {
}
navigationHistory {
checkZimFileLoadedSuccessful(R.id.readerFragment)
clickOnAndroidArticle()
longClickOnBackwardButton()
assertNavigationHistoryDialogDisplayed()
assertBackwardNavigationHistoryDialogDisplayed()
pressBack()
clickOnBackwardButton()
longClickOnForwardButton()
assertNavigationHistoryDialogDisplayed()
assertForwardNavigationHistoryDialogDisplayed()
pressBack()
}
LeakAssertions.assertNoLeaks()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -660,9 +660,7 @@ abstract class CoreReaderFragment :

@OnLongClick(R2.id.bottom_toolbar_arrow_back)
fun showBackwardHistory() {
if (getCurrentWebView()?.canGoBack() == true ||
sharedPreferenceUtil?.prefIsTest == true
) {
if (getCurrentWebView()?.canGoBack() == true) {
getCurrentWebView()?.copyBackForwardList()?.let { historyList ->
navigationHistoryList.clear()
(historyList.currentIndex downTo 0)
Expand All @@ -678,9 +676,7 @@ abstract class CoreReaderFragment :

@OnLongClick(R2.id.bottom_toolbar_arrow_forward)
fun showForwardHistory() {
if (getCurrentWebView()?.canGoForward() == true ||
sharedPreferenceUtil?.prefIsTest == true
) {
if (getCurrentWebView()?.canGoForward() == true) {
getCurrentWebView()?.copyBackForwardList()?.let { historyList ->
navigationHistoryList.clear()
(historyList.currentIndex until historyList.size)
Expand Down

0 comments on commit 46d55bd

Please sign in to comment.