Skip to content

Commit

Permalink
Added Notification permission in our test cases for API level 33.
Browse files Browse the repository at this point in the history
* Improved our `ZimHostFragmentTest` test to boost the test case speed. It was running in 2 minutes, but after this change, it now completes in 27 seconds.
  • Loading branch information
MohitMaliDeveloper committed Mar 13, 2024
1 parent 6c2bbdb commit e3cc91b
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 8 deletions.
23 changes: 18 additions & 5 deletions app/src/androidTest/java/org/kiwix/kiwixmobile/BaseActivityTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,9 @@

package org.kiwix.kiwixmobile

import android.Manifest.permission
import android.Manifest
import android.content.Context
import android.os.Build
import androidx.test.core.app.ActivityScenario
import androidx.test.ext.junit.runners.AndroidJUnit4
import androidx.test.platform.app.InstrumentationRegistry.getInstrumentation
Expand All @@ -34,10 +35,22 @@ import org.kiwix.kiwixmobile.main.KiwixMainActivity
abstract class BaseActivityTest {
open lateinit var activityScenario: ActivityScenario<KiwixMainActivity>

private val permissions = arrayOf(
permission.READ_EXTERNAL_STORAGE,
permission.WRITE_EXTERNAL_STORAGE
)
private val permissions = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
arrayOf(
Manifest.permission.POST_NOTIFICATIONS,
Manifest.permission.READ_EXTERNAL_STORAGE,
Manifest.permission.WRITE_EXTERNAL_STORAGE,
Manifest.permission.NEARBY_WIFI_DEVICES,
Manifest.permission.ACCESS_NETWORK_STATE
)
} else {
arrayOf(
Manifest.permission.READ_EXTERNAL_STORAGE,
Manifest.permission.WRITE_EXTERNAL_STORAGE,
Manifest.permission.ACCESS_FINE_LOCATION,
Manifest.permission.ACCESS_NETWORK_STATE
)
}

@get:Rule
var permissionRules: GrantPermissionRule =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ class LocalFileTransferTest {

private val permissions = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
arrayOf(
Manifest.permission.POST_NOTIFICATIONS,
Manifest.permission.NEARBY_WIFI_DEVICES
)
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ class PlayStoreRestrictionDialogTest {

private val permissions = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
arrayOf(
Manifest.permission.POST_NOTIFICATIONS,
Manifest.permission.READ_EXTERNAL_STORAGE,
Manifest.permission.WRITE_EXTERNAL_STORAGE,
Manifest.permission.NEARBY_WIFI_DEVICES
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ class ZimHostFragmentTest {

private val permissions = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
arrayOf(
Manifest.permission.POST_NOTIFICATIONS,
Manifest.permission.READ_EXTERNAL_STORAGE,
Manifest.permission.WRITE_EXTERNAL_STORAGE,
Manifest.permission.NEARBY_WIFI_DEVICES,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,12 +82,18 @@ class ZimHostRobot : BaseRobot() {

fun stopServerIfAlreadyStarted() {
try {
assertServerStarted()
stopServer()
// Check if the "START SERVER" button is visible because, in most scenarios,
// this button will appear when the server is already stopped.
// This will expedite our test case, as verifying the visibility of
// non-visible views takes more time due to the try mechanism needed
// to properly retrieve the view.
assertServerStopped()
} catch (exception: Exception) {
// if "START SERVER" button is not visible it means server is started so close it.
stopServer()
Log.i(
"ZIM_HOST_FRAGMENT",
"Failed to stop the server, Probably because server is not running"
"Stopped the server to perform our test case since it was already running"
)
}
}
Expand Down

0 comments on commit e3cc91b

Please sign in to comment.