mirror of
https://github.com/kiwix/kiwix-android.git
synced 2025-09-09 23:40:26 -04:00
Merge pull request #3659 from kiwix/Fix#3627
Fixed: Nowdays CI frequently failing on API level 24, and 33.
This commit is contained in:
commit
3f19f55b99
@ -53,14 +53,16 @@ class ZimHostFragmentTest {
|
|||||||
arrayOf(
|
arrayOf(
|
||||||
Manifest.permission.READ_EXTERNAL_STORAGE,
|
Manifest.permission.READ_EXTERNAL_STORAGE,
|
||||||
Manifest.permission.WRITE_EXTERNAL_STORAGE,
|
Manifest.permission.WRITE_EXTERNAL_STORAGE,
|
||||||
Manifest.permission.NEARBY_WIFI_DEVICES
|
Manifest.permission.NEARBY_WIFI_DEVICES,
|
||||||
|
Manifest.permission.ACCESS_NETWORK_STATE
|
||||||
)
|
)
|
||||||
} else {
|
} else {
|
||||||
arrayOf(
|
arrayOf(
|
||||||
Manifest.permission.READ_EXTERNAL_STORAGE,
|
Manifest.permission.READ_EXTERNAL_STORAGE,
|
||||||
Manifest.permission.WRITE_EXTERNAL_STORAGE,
|
Manifest.permission.WRITE_EXTERNAL_STORAGE,
|
||||||
Manifest.permission.ACCESS_COARSE_LOCATION,
|
Manifest.permission.ACCESS_COARSE_LOCATION,
|
||||||
Manifest.permission.ACCESS_FINE_LOCATION
|
Manifest.permission.ACCESS_FINE_LOCATION,
|
||||||
|
Manifest.permission.ACCESS_NETWORK_STATE
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -24,6 +24,7 @@ import androidx.test.espresso.action.ViewActions.click
|
|||||||
import androidx.test.espresso.assertion.ViewAssertions.matches
|
import androidx.test.espresso.assertion.ViewAssertions.matches
|
||||||
import androidx.test.espresso.matcher.ViewMatchers
|
import androidx.test.espresso.matcher.ViewMatchers
|
||||||
import androidx.test.espresso.matcher.ViewMatchers.assertThat
|
import androidx.test.espresso.matcher.ViewMatchers.assertThat
|
||||||
|
import androidx.test.espresso.matcher.ViewMatchers.withText
|
||||||
import applyWithViewHierarchyPrinting
|
import applyWithViewHierarchyPrinting
|
||||||
import com.adevinta.android.barista.interaction.BaristaSleepInteractions
|
import com.adevinta.android.barista.interaction.BaristaSleepInteractions
|
||||||
import com.adevinta.android.barista.interaction.BaristaSwipeRefreshInteractions.refresh
|
import com.adevinta.android.barista.interaction.BaristaSwipeRefreshInteractions.refresh
|
||||||
@ -64,14 +65,21 @@ class ZimHostRobot : BaseRobot() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fun clickOnTestZim() {
|
fun clickOnTestZim() {
|
||||||
|
pauseForBetterTestPerformance()
|
||||||
clickOn(Text("Test_Zim"))
|
clickOn(Text("Test_Zim"))
|
||||||
}
|
}
|
||||||
|
|
||||||
fun startServer() {
|
fun startServer() {
|
||||||
|
// stop the server if it is already running.
|
||||||
|
stopServerIfAlreadyStarted()
|
||||||
clickOn(ViewId(R.id.startServerButton))
|
clickOn(ViewId(R.id.startServerButton))
|
||||||
|
assetWifiDialogDisplayed()
|
||||||
|
onView(withText("PROCEED")).perform(click())
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun assetWifiDialogDisplayed() {
|
||||||
pauseForBetterTestPerformance()
|
pauseForBetterTestPerformance()
|
||||||
isVisible(TextId(R.string.wifi_dialog_title))
|
isVisible(Text("WiFi connection detected"))
|
||||||
clickOn(TextId(R.string.hotspot_dialog_neutral_button))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fun assertServerStarted() {
|
fun assertServerStarted() {
|
||||||
@ -110,7 +118,6 @@ class ZimHostRobot : BaseRobot() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun selectZimFile(position: Int) {
|
private fun selectZimFile(position: Int) {
|
||||||
pauseForBetterTestPerformance()
|
|
||||||
try {
|
try {
|
||||||
onView(
|
onView(
|
||||||
RecyclerViewMatcher(R.id.recyclerViewZimHost).atPositionOnView(
|
RecyclerViewMatcher(R.id.recyclerViewZimHost).atPositionOnView(
|
||||||
@ -119,7 +126,6 @@ class ZimHostRobot : BaseRobot() {
|
|||||||
)
|
)
|
||||||
).check(matches(ViewMatchers.isChecked()))
|
).check(matches(ViewMatchers.isChecked()))
|
||||||
} catch (assertionError: AssertionFailedError) {
|
} catch (assertionError: AssertionFailedError) {
|
||||||
pauseForBetterTestPerformance()
|
|
||||||
onView(
|
onView(
|
||||||
RecyclerViewMatcher(R.id.recyclerViewZimHost).atPositionOnView(
|
RecyclerViewMatcher(R.id.recyclerViewZimHost).atPositionOnView(
|
||||||
position,
|
position,
|
||||||
@ -148,6 +154,6 @@ class ZimHostRobot : BaseRobot() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun pauseForBetterTestPerformance() {
|
private fun pauseForBetterTestPerformance() {
|
||||||
BaristaSleepInteractions.sleep(TestUtils.TEST_PAUSE_MS_FOR_DOWNLOAD_TEST.toLong())
|
BaristaSleepInteractions.sleep(TestUtils.TEST_PAUSE_MS.toLong())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,7 +1,10 @@
|
|||||||
#!/usr/bin/env bash
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
|
# Enable Wi-Fi on the emulator
|
||||||
|
adb shell svc wifi enable
|
||||||
adb logcat -c
|
adb logcat -c
|
||||||
adb logcat ./*:E -v color &
|
# shellcheck disable=SC2035
|
||||||
|
adb logcat *:E -v color &
|
||||||
retry=0
|
retry=0
|
||||||
while [ $retry -le 3 ]
|
while [ $retry -le 3 ]
|
||||||
do
|
do
|
||||||
@ -11,8 +14,11 @@ do
|
|||||||
else
|
else
|
||||||
adb kill-server
|
adb kill-server
|
||||||
adb start-server
|
adb start-server
|
||||||
|
# Enable Wi-Fi on the emulator
|
||||||
|
adb shell svc wifi enable
|
||||||
adb logcat -c
|
adb logcat -c
|
||||||
adb logcat ./*:E -v color &
|
# shellcheck disable=SC2035
|
||||||
|
adb logcat *:E -v color &
|
||||||
./gradlew clean
|
./gradlew clean
|
||||||
retry=$(( retry + 1 ))
|
retry=$(( retry + 1 ))
|
||||||
if [ $retry -eq 3 ]; then
|
if [ $retry -eq 3 ]; then
|
||||||
|
@ -22,20 +22,23 @@ import androidx.appcompat.app.AppCompatActivity
|
|||||||
import io.mockk.Called
|
import io.mockk.Called
|
||||||
import io.mockk.mockk
|
import io.mockk.mockk
|
||||||
import io.mockk.verify
|
import io.mockk.verify
|
||||||
import kotlinx.coroutines.CoroutineScope
|
import kotlinx.coroutines.ExperimentalCoroutinesApi
|
||||||
import kotlinx.coroutines.Dispatchers
|
import kotlinx.coroutines.test.TestScope
|
||||||
|
import kotlinx.coroutines.test.advanceUntilIdle
|
||||||
|
import kotlinx.coroutines.test.runTest
|
||||||
import org.junit.jupiter.api.Test
|
import org.junit.jupiter.api.Test
|
||||||
import org.kiwix.kiwixmobile.core.dao.NewRecentSearchDao
|
import org.kiwix.kiwixmobile.core.dao.NewRecentSearchDao
|
||||||
import org.kiwix.kiwixmobile.core.reader.ZimFileReader
|
import org.kiwix.kiwixmobile.core.reader.ZimFileReader
|
||||||
import org.kiwix.kiwixmobile.core.search.adapter.SearchListItem.RecentSearchListItem
|
import org.kiwix.kiwixmobile.core.search.adapter.SearchListItem.RecentSearchListItem
|
||||||
|
|
||||||
|
@OptIn(ExperimentalCoroutinesApi::class)
|
||||||
internal class SaveSearchToRecentsTest {
|
internal class SaveSearchToRecentsTest {
|
||||||
|
|
||||||
private val newRecentSearchDao: NewRecentSearchDao = mockk()
|
private val newRecentSearchDao: NewRecentSearchDao = mockk()
|
||||||
private val searchListItem = RecentSearchListItem("", ZimFileReader.CONTENT_PREFIX)
|
private val searchListItem = RecentSearchListItem("", ZimFileReader.CONTENT_PREFIX)
|
||||||
|
|
||||||
private val activity: AppCompatActivity = mockk()
|
private val activity: AppCompatActivity = mockk()
|
||||||
private val viewModelScope = CoroutineScope(Dispatchers.IO)
|
private val testDispatcher = TestScope()
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun `invoke with null Id does nothing`() {
|
fun `invoke with null Id does nothing`() {
|
||||||
@ -43,7 +46,7 @@ internal class SaveSearchToRecentsTest {
|
|||||||
newRecentSearchDao,
|
newRecentSearchDao,
|
||||||
searchListItem,
|
searchListItem,
|
||||||
null,
|
null,
|
||||||
viewModelScope
|
testDispatcher
|
||||||
).invokeWith(
|
).invokeWith(
|
||||||
activity
|
activity
|
||||||
)
|
)
|
||||||
@ -51,14 +54,15 @@ internal class SaveSearchToRecentsTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun `invoke with non null Id saves search`() {
|
fun `invoke with non null Id saves search`() = testDispatcher.runTest {
|
||||||
val id = "id"
|
val id = "id"
|
||||||
SaveSearchToRecents(
|
SaveSearchToRecents(
|
||||||
newRecentSearchDao,
|
newRecentSearchDao,
|
||||||
searchListItem,
|
searchListItem,
|
||||||
id,
|
id,
|
||||||
viewModelScope
|
testDispatcher
|
||||||
).invokeWith(activity)
|
).invokeWith(activity)
|
||||||
|
testDispatcher.advanceUntilIdle()
|
||||||
verify { newRecentSearchDao.saveSearch(searchListItem.value, id, ZimFileReader.CONTENT_PREFIX) }
|
verify { newRecentSearchDao.saveSearch(searchListItem.value, id, ZimFileReader.CONTENT_PREFIX) }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user