mirror of
https://github.com/kiwix/kiwix-android.git
synced 2025-09-20 10:23:30 -04:00
added a test case to evaluate the functionality of LocalFileTransferFragment
.
* This test case is designed to verify that the functionality works correctly, especially addressing the issue where `LocalFileTransferFragment` would shut down when attempting to search nearby devices for connection.
This commit is contained in:
parent
e4d27e19a1
commit
530faa46bb
@ -19,9 +19,12 @@
|
||||
package org.kiwix.kiwixmobile.localFileTransfer
|
||||
|
||||
import applyWithViewHierarchyPrinting
|
||||
import com.adevinta.android.barista.interaction.BaristaSleepInteractions
|
||||
import org.kiwix.kiwixmobile.BaseRobot
|
||||
import org.kiwix.kiwixmobile.Findable.ViewId
|
||||
import org.kiwix.kiwixmobile.Findable.StringId.TextId
|
||||
import org.kiwix.kiwixmobile.R
|
||||
import org.kiwix.kiwixmobile.testutils.TestUtils
|
||||
|
||||
/**
|
||||
* Authored by Ayush Shrivastava on 29/10/20
|
||||
@ -32,7 +35,24 @@ fun localFileTransfer(func: LocalFileTransferRobot.() -> Unit) =
|
||||
|
||||
class LocalFileTransferRobot : BaseRobot() {
|
||||
|
||||
init {
|
||||
fun assertReceiveFileTitleVisible() {
|
||||
isVisible(TextId(R.string.receive_files_title))
|
||||
}
|
||||
|
||||
fun assertSearchDeviceMenuItemVisible() {
|
||||
isVisible(ViewId(R.id.menu_item_search_devices))
|
||||
}
|
||||
|
||||
fun clickOnSearchDeviceMenuItem() {
|
||||
clickOn(ViewId(R.id.menu_item_search_devices))
|
||||
}
|
||||
|
||||
fun assertLocalFileTransferScreenVisible() {
|
||||
BaristaSleepInteractions.sleep(TestUtils.TEST_PAUSE_MS_FOR_DOWNLOAD_TEST.toLong())
|
||||
assertReceiveFileTitleVisible()
|
||||
}
|
||||
|
||||
fun assertLocalLibraryVisible() {
|
||||
isVisible(TextId(R.string.library))
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,120 @@
|
||||
/*
|
||||
* 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.localFileTransfer
|
||||
|
||||
import android.Manifest
|
||||
import android.app.Instrumentation
|
||||
import android.content.Context
|
||||
import android.os.Build
|
||||
import androidx.core.content.edit
|
||||
import androidx.lifecycle.Lifecycle
|
||||
import androidx.preference.PreferenceManager
|
||||
import androidx.test.core.app.ActivityScenario
|
||||
import androidx.test.platform.app.InstrumentationRegistry
|
||||
import androidx.test.rule.GrantPermissionRule
|
||||
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.R
|
||||
import org.kiwix.kiwixmobile.core.utils.SharedPreferenceUtil
|
||||
import org.kiwix.kiwixmobile.main.KiwixMainActivity
|
||||
import org.kiwix.kiwixmobile.nav.destination.library.library
|
||||
import org.kiwix.kiwixmobile.testutils.RetryRule
|
||||
import org.kiwix.kiwixmobile.testutils.TestUtils
|
||||
|
||||
class LocalFileTransferTest {
|
||||
@Rule
|
||||
@JvmField
|
||||
var retryRule = RetryRule()
|
||||
|
||||
private var context: Context? = null
|
||||
private lateinit var activityScenario: ActivityScenario<KiwixMainActivity>
|
||||
|
||||
private val permissions = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
|
||||
arrayOf(
|
||||
Manifest.permission.NEARBY_WIFI_DEVICES
|
||||
)
|
||||
} else {
|
||||
arrayOf(
|
||||
Manifest.permission.READ_EXTERNAL_STORAGE,
|
||||
Manifest.permission.WRITE_EXTERNAL_STORAGE,
|
||||
Manifest.permission.ACCESS_COARSE_LOCATION,
|
||||
Manifest.permission.ACCESS_FINE_LOCATION
|
||||
)
|
||||
}
|
||||
|
||||
@Rule
|
||||
@JvmField
|
||||
var permissionRules: GrantPermissionRule =
|
||||
GrantPermissionRule.grant(*permissions)
|
||||
|
||||
private val instrumentation: Instrumentation by lazy {
|
||||
InstrumentationRegistry.getInstrumentation()
|
||||
}
|
||||
|
||||
@Before
|
||||
fun setup() {
|
||||
context = instrumentation.targetContext.applicationContext
|
||||
UiDevice.getInstance(instrumentation).apply {
|
||||
if (TestUtils.isSystemUINotRespondingDialogVisible(this)) {
|
||||
TestUtils.closeSystemDialogs(context)
|
||||
}
|
||||
waitForIdle()
|
||||
}
|
||||
PreferenceManager.getDefaultSharedPreferences(context).edit {
|
||||
putBoolean(SharedPreferenceUtil.PREF_SHOW_INTRO, false)
|
||||
putBoolean(SharedPreferenceUtil.PREF_WIFI_ONLY, false)
|
||||
putBoolean(SharedPreferenceUtil.PREF_IS_TEST, true)
|
||||
}
|
||||
activityScenario = ActivityScenario.launch(KiwixMainActivity::class.java).apply {
|
||||
moveToState(Lifecycle.State.RESUMED)
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun localFileTransfer() {
|
||||
if (Build.VERSION.SDK_INT > Build.VERSION_CODES.N_MR1) {
|
||||
activityScenario.onActivity {
|
||||
it.navigate(R.id.libraryFragment)
|
||||
}
|
||||
library {
|
||||
assertGetZimNearbyDeviceDisplayed()
|
||||
clickFileTransferIcon {
|
||||
assertReceiveFileTitleVisible()
|
||||
assertSearchDeviceMenuItemVisible()
|
||||
clickOnSearchDeviceMenuItem()
|
||||
assertLocalFileTransferScreenVisible()
|
||||
pressBack()
|
||||
assertLocalLibraryVisible()
|
||||
}
|
||||
}
|
||||
LeakAssertions.assertNoLeaks()
|
||||
}
|
||||
}
|
||||
|
||||
@After
|
||||
fun setIsTestPreference() {
|
||||
PreferenceManager.getDefaultSharedPreferences(context).edit {
|
||||
putBoolean(SharedPreferenceUtil.PREF_IS_TEST, false)
|
||||
}
|
||||
}
|
||||
}
|
@ -31,6 +31,7 @@ import org.junit.Test
|
||||
import org.kiwix.kiwixmobile.BaseActivityTest
|
||||
import org.kiwix.kiwixmobile.core.utils.SharedPreferenceUtil
|
||||
import org.kiwix.kiwixmobile.help.HelpRobot
|
||||
import org.kiwix.kiwixmobile.localFileTransfer.LocalFileTransferRobot
|
||||
import org.kiwix.kiwixmobile.nav.destination.library.OnlineLibraryRobot
|
||||
import org.kiwix.kiwixmobile.settings.SettingsRobot
|
||||
import org.kiwix.kiwixmobile.testutils.RetryRule
|
||||
@ -72,8 +73,7 @@ class TopLevelDestinationTest : BaseActivityTest() {
|
||||
}
|
||||
clickLibraryOnBottomNav {
|
||||
assertGetZimNearbyDeviceDisplayed()
|
||||
clickFileTransferIcon {
|
||||
}
|
||||
clickFileTransferIcon(LocalFileTransferRobot::assertReceiveFileTitleVisible)
|
||||
}
|
||||
clickDownloadOnBottomNav(OnlineLibraryRobot::assertLibraryListDisplayed)
|
||||
clickBookmarksOnNavDrawer {
|
||||
|
Loading…
x
Reference in New Issue
Block a user