-
-
Notifications
You must be signed in to change notification settings - Fork 464
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
9e28505
commit f17911b
Showing
13 changed files
with
670 additions
and
1 deletion.
There are no files selected for viewing
92 changes: 92 additions & 0 deletions
92
app/src/androidTest/java/org/kiwix/kiwixmobile/page/history/NavigationHistoryRobot.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
/* | ||
* Kiwix Android | ||
* Copyright (c) 2023 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 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 | ||
import org.kiwix.kiwixmobile.Findable.StringId.TextId | ||
import org.kiwix.kiwixmobile.Findable.ViewId | ||
import org.kiwix.kiwixmobile.R | ||
import org.kiwix.kiwixmobile.testutils.TestUtils | ||
|
||
fun navigationHistory(func: NavigationHistoryRobot.() -> Unit) = | ||
NavigationHistoryRobot().applyWithViewHierarchyPrinting(func) | ||
|
||
class NavigationHistoryRobot : BaseRobot() { | ||
|
||
fun checkZimFileLoadedSuccessful(readerFragment: Int) { | ||
pauseForBetterTestPerformance() | ||
isVisible(ViewId(readerFragment)) | ||
} | ||
|
||
fun clickOnAndroidArticle() { | ||
pauseForBetterTestPerformance() | ||
onWebView() | ||
.withElement( | ||
findElement( | ||
Locator.XPATH, | ||
"//*[contains(text(), 'Android_(operating_system)')]" | ||
) | ||
) | ||
.perform(webClick()) | ||
} | ||
|
||
fun longClickOnBackwardButton() { | ||
pauseForBetterTestPerformance() | ||
longClickOn(ViewId(R.id.bottom_toolbar_arrow_back)) | ||
} | ||
|
||
fun longClickOnForwardButton() { | ||
pauseForBetterTestPerformance() | ||
longClickOn(ViewId(R.id.bottom_toolbar_arrow_forward)) | ||
} | ||
|
||
fun assertBackwardNavigationHistoryDialogDisplayed() { | ||
pauseForBetterTestPerformance() | ||
isVisible(TextId(R.string.backward_history)) | ||
} | ||
|
||
fun clickOnBackwardButton() { | ||
pauseForBetterTestPerformance() | ||
clickOn(ViewId(R.id.bottom_toolbar_arrow_back)) | ||
} | ||
|
||
fun assertForwardNavigationHistoryDialogDisplayed() { | ||
pauseForBetterTestPerformance() | ||
isVisible(TextId(R.string.forward_history)) | ||
} | ||
|
||
fun clickOnDeleteHistory() { | ||
pauseForBetterTestPerformance() | ||
clickOn(ViewId(R.id.menu_pages_clear)) | ||
} | ||
|
||
fun assertDeleteDialogDisplayed() { | ||
pauseForBetterTestPerformance() | ||
isVisible(TextId(R.string.clear_all_history_dialog_title)) | ||
} | ||
|
||
private fun pauseForBetterTestPerformance() { | ||
BaristaSleepInteractions.sleep(TestUtils.TEST_PAUSE_MS_FOR_SEARCH_TEST.toLong()) | ||
} | ||
} |
114 changes: 114 additions & 0 deletions
114
app/src/androidTest/java/org/kiwix/kiwixmobile/page/history/NavigationHistoryTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,114 @@ | ||
/* | ||
* Kiwix Android | ||
* Copyright (c) 2023 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 android.os.Build | ||
import androidx.core.content.edit | ||
import androidx.core.net.toUri | ||
import androidx.preference.PreferenceManager | ||
import androidx.test.core.app.ActivityScenario | ||
import androidx.test.internal.runner.junit4.statement.UiThreadStatement | ||
import androidx.test.platform.app.InstrumentationRegistry | ||
import androidx.test.uiautomator.UiDevice | ||
import leakcanary.LeakAssertions | ||
import org.junit.After | ||
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.SharedPreferenceUtil | ||
import org.kiwix.kiwixmobile.main.KiwixMainActivity | ||
import org.kiwix.kiwixmobile.nav.destination.library.LocalLibraryFragmentDirections | ||
import org.kiwix.kiwixmobile.testutils.RetryRule | ||
import java.io.File | ||
import java.io.FileOutputStream | ||
import java.io.OutputStream | ||
|
||
class NavigationHistoryTest : BaseActivityTest() { | ||
|
||
@Rule | ||
@JvmField | ||
var retryRule = RetryRule() | ||
|
||
private lateinit var kiwixMainActivity: KiwixMainActivity | ||
|
||
@Before | ||
override fun waitForIdle() { | ||
UiDevice.getInstance(InstrumentationRegistry.getInstrumentation()).waitForIdle() | ||
PreferenceManager.getDefaultSharedPreferences(context).edit { | ||
putBoolean(SharedPreferenceUtil.PREF_SHOW_INTRO, false) | ||
putBoolean(SharedPreferenceUtil.PREF_WIFI_ONLY, false) | ||
putBoolean(SharedPreferenceUtil.PREF_IS_TEST, true) | ||
} | ||
} | ||
|
||
@Test | ||
fun navigationHistoryDialogTest() { | ||
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.TIRAMISU) { | ||
ActivityScenario.launch(KiwixMainActivity::class.java).onActivity { | ||
kiwixMainActivity = it | ||
kiwixMainActivity.navigate(R.id.libraryFragment) | ||
} | ||
val loadFileStream = | ||
NavigationHistoryTest::class.java.classLoader.getResourceAsStream("testzim.zim") | ||
val zimFile = File(context.cacheDir, "testzim.zim") | ||
if (zimFile.exists()) zimFile.delete() | ||
zimFile.createNewFile() | ||
loadFileStream.use { inputStream -> | ||
val outputStream: OutputStream = FileOutputStream(zimFile) | ||
outputStream.use { it -> | ||
val buffer = ByteArray(inputStream.available()) | ||
var length: Int | ||
while (inputStream.read(buffer).also { length = it } > 0) { | ||
it.write(buffer, 0, length) | ||
} | ||
} | ||
} | ||
UiThreadStatement.runOnUiThread { | ||
kiwixMainActivity.navigate( | ||
LocalLibraryFragmentDirections.actionNavigationLibraryToNavigationReader() | ||
.apply { zimFileUri = zimFile.toUri().toString() } | ||
) | ||
} | ||
navigationHistory { | ||
checkZimFileLoadedSuccessful(R.id.readerFragment) | ||
clickOnAndroidArticle() | ||
longClickOnBackwardButton() | ||
assertBackwardNavigationHistoryDialogDisplayed() | ||
pressBack() | ||
clickOnBackwardButton() | ||
longClickOnForwardButton() | ||
assertForwardNavigationHistoryDialogDisplayed() | ||
clickOnDeleteHistory() | ||
assertDeleteDialogDisplayed() | ||
pressBack() | ||
pressBack() | ||
} | ||
LeakAssertions.assertNoLeaks() | ||
} | ||
} | ||
|
||
@After | ||
fun setIsTestPreference() { | ||
PreferenceManager.getDefaultSharedPreferences(context).edit { | ||
putBoolean(SharedPreferenceUtil.PREF_IS_TEST, false) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
26 changes: 26 additions & 0 deletions
26
core/src/main/java/org/kiwix/kiwixmobile/core/page/history/NavigationHistoryClickListener.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
/* | ||
* Kiwix Android | ||
* Copyright (c) 2023 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.core.page.history | ||
|
||
import org.kiwix.kiwixmobile.core.page.history.adapter.NavigationHistoryListItem | ||
|
||
interface NavigationHistoryClickListener { | ||
fun onItemClicked(navigationHistoryListItem: NavigationHistoryListItem) | ||
fun clearHistory() | ||
} |
Oops, something went wrong.