mirror of
https://github.com/kiwix/kiwix-android.git
synced 2025-08-03 02:36:24 -04:00
Refactored the LanguageFragmentTest
UI test to properly verify that the language filter is applied correctly and that content is fetched for the selected language.
* Fixed: some lint warnings.
This commit is contained in:
parent
60aeaaa67d
commit
95dddd470a
@ -44,6 +44,7 @@ import org.kiwix.kiwixmobile.nav.destination.library.online.DOWNLOADING_STATE_TE
|
||||
import org.kiwix.kiwixmobile.nav.destination.library.online.DOWNLOADING_STOP_BUTTON_TESTING_TAG
|
||||
import org.kiwix.kiwixmobile.nav.destination.library.online.NO_CONTENT_VIEW_TEXT_TESTING_TAG
|
||||
import org.kiwix.kiwixmobile.nav.destination.library.online.ONLINE_BOOK_ITEM_TESTING_TAG
|
||||
import org.kiwix.kiwixmobile.nav.destination.library.online.ONLINE_DIVIDER_ITEM_TEXT_TESTING_TAG
|
||||
import org.kiwix.kiwixmobile.nav.destination.library.online.ONLINE_LIBRARY_SEARCH_VIEW_CLOSE_BUTTON_TESTING_TAG
|
||||
import org.kiwix.kiwixmobile.nav.destination.library.online.ONLINE_LIBRARY_SEARCH_VIEW_TESTING_TAG
|
||||
import org.kiwix.kiwixmobile.nav.destination.library.online.SHOW_FETCHING_LIBRARY_LAYOUT_TESTING_TAG
|
||||
@ -86,6 +87,15 @@ class DownloadRobot : BaseRobot() {
|
||||
}
|
||||
}
|
||||
|
||||
fun checkLanguageFilterAppliedToOnlineContent(
|
||||
composeTestRule: ComposeContentTestRule,
|
||||
language: String
|
||||
) {
|
||||
composeTestRule.apply {
|
||||
onNodeWithTag(ONLINE_DIVIDER_ITEM_TEXT_TESTING_TAG).assertTextEquals(language)
|
||||
}
|
||||
}
|
||||
|
||||
private fun refreshOnlineListIfSwipeDownForLibraryTextVisible(composeTestRule: ComposeContentTestRule) {
|
||||
try {
|
||||
composeTestRule.onNodeWithTag(NO_CONTENT_VIEW_TEXT_TESTING_TAG).assertIsDisplayed()
|
||||
|
@ -43,6 +43,7 @@ import org.junit.Before
|
||||
import org.junit.Rule
|
||||
import org.junit.Test
|
||||
import org.junit.runner.RunWith
|
||||
import org.kiwix.kiwixmobile.core.R
|
||||
import org.kiwix.kiwixmobile.core.utils.LanguageUtils.Companion.handleLocaleChange
|
||||
import org.kiwix.kiwixmobile.core.utils.SharedPreferenceUtil
|
||||
import org.kiwix.kiwixmobile.core.utils.TestingUtils.COMPOSE_TEST_RULE_ORDER
|
||||
@ -50,8 +51,10 @@ import org.kiwix.kiwixmobile.core.utils.TestingUtils.RETRY_RULE_ORDER
|
||||
import org.kiwix.kiwixmobile.download.downloadRobot
|
||||
import org.kiwix.kiwixmobile.main.KiwixMainActivity
|
||||
import org.kiwix.kiwixmobile.testutils.RetryRule
|
||||
import org.kiwix.kiwixmobile.testutils.TestUtils
|
||||
import org.kiwix.kiwixmobile.testutils.TestUtils.closeSystemDialogs
|
||||
import org.kiwix.kiwixmobile.testutils.TestUtils.isSystemUINotRespondingDialogVisible
|
||||
import org.kiwix.kiwixmobile.testutils.TestUtils.waitUntilTimeout
|
||||
import org.kiwix.kiwixmobile.utils.StandardActions
|
||||
|
||||
@LargeTest
|
||||
@ -132,32 +135,7 @@ class LanguageFragmentTest {
|
||||
language {
|
||||
// search and de-select if german language already selected
|
||||
clickOnLanguageIcon(composeTestRule)
|
||||
clickOnLanguageSearchIcon(composeTestRule)
|
||||
searchLanguage(
|
||||
composeTestRule = composeTestRule,
|
||||
searchLanguage = "german"
|
||||
)
|
||||
deSelectLanguageIfAlreadySelected(
|
||||
composeTestRule = composeTestRule,
|
||||
matchLanguage = "German"
|
||||
)
|
||||
clickOnSaveLanguageIcon(composeTestRule)
|
||||
|
||||
// search and de-select if italian language already selected
|
||||
clickOnLanguageIcon(composeTestRule)
|
||||
clickOnLanguageSearchIcon(composeTestRule)
|
||||
searchLanguage(
|
||||
composeTestRule = composeTestRule,
|
||||
searchLanguage = "italiano"
|
||||
)
|
||||
deSelectLanguageIfAlreadySelected(
|
||||
composeTestRule = composeTestRule,
|
||||
matchLanguage = "Italian"
|
||||
)
|
||||
clickOnSaveLanguageIcon(composeTestRule)
|
||||
|
||||
// Search and save language for german
|
||||
clickOnLanguageIcon(composeTestRule)
|
||||
waitForLanguageToLoad(composeTestRule)
|
||||
clickOnLanguageSearchIcon(composeTestRule)
|
||||
searchLanguage(
|
||||
composeTestRule = composeTestRule,
|
||||
@ -168,9 +146,18 @@ class LanguageFragmentTest {
|
||||
matchLanguage = "German"
|
||||
)
|
||||
clickOnSaveLanguageIcon(composeTestRule)
|
||||
// test if the selected language filter is applied on the online library or not.
|
||||
downloadRobot {
|
||||
composeTestRule.waitUntilTimeout(TestUtils.TEST_PAUSE_MS_FOR_DOWNLOAD_TEST.toLong())
|
||||
waitForDataToLoad(composeTestRule = composeTestRule)
|
||||
checkLanguageFilterAppliedToOnlineContent(
|
||||
composeTestRule,
|
||||
context.getString(R.string.your_language, "German")
|
||||
)
|
||||
}
|
||||
|
||||
// Search and save language for italian
|
||||
clickOnLanguageIcon(composeTestRule)
|
||||
waitForLanguageToLoad(composeTestRule)
|
||||
clickOnLanguageSearchIcon(composeTestRule)
|
||||
searchLanguage(
|
||||
composeTestRule = composeTestRule,
|
||||
@ -182,31 +169,15 @@ class LanguageFragmentTest {
|
||||
)
|
||||
clickOnSaveLanguageIcon(composeTestRule)
|
||||
|
||||
// verify is german language selected
|
||||
clickOnLanguageIcon(composeTestRule)
|
||||
clickOnLanguageSearchIcon(composeTestRule)
|
||||
searchLanguage(
|
||||
composeTestRule = composeTestRule,
|
||||
searchLanguage = "german"
|
||||
)
|
||||
checkIsLanguageSelected(
|
||||
composeTestRule = composeTestRule,
|
||||
matchLanguage = "German"
|
||||
)
|
||||
clickOnSaveLanguageIcon(composeTestRule)
|
||||
|
||||
// verify is italian language selected
|
||||
clickOnLanguageIcon(composeTestRule)
|
||||
clickOnLanguageSearchIcon(composeTestRule)
|
||||
searchLanguage(
|
||||
composeTestRule = composeTestRule,
|
||||
searchLanguage = "italiano"
|
||||
)
|
||||
checkIsLanguageSelected(
|
||||
composeTestRule = composeTestRule,
|
||||
matchLanguage = "Italian"
|
||||
)
|
||||
clickOnSaveLanguageIcon(composeTestRule)
|
||||
// test if the selected language filter is applied on the online library or not.
|
||||
downloadRobot {
|
||||
composeTestRule.waitUntilTimeout(TestUtils.TEST_PAUSE_MS_FOR_DOWNLOAD_TEST.toLong())
|
||||
waitForDataToLoad(composeTestRule = composeTestRule)
|
||||
checkLanguageFilterAppliedToOnlineContent(
|
||||
composeTestRule,
|
||||
context.getString(R.string.your_language, "Italian")
|
||||
)
|
||||
}
|
||||
}
|
||||
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.TIRAMISU) {
|
||||
LeakAssertions.assertNoLeaks()
|
||||
|
@ -18,21 +18,21 @@
|
||||
|
||||
package org.kiwix.kiwixmobile.language
|
||||
|
||||
import androidx.compose.ui.test.assertIsOff
|
||||
import androidx.compose.ui.test.assertIsOn
|
||||
import androidx.compose.ui.test.ComposeTimeoutException
|
||||
import androidx.compose.ui.test.isDisplayed
|
||||
import androidx.compose.ui.test.junit4.ComposeContentTestRule
|
||||
import androidx.compose.ui.test.onAllNodesWithContentDescription
|
||||
import androidx.compose.ui.test.onNodeWithTag
|
||||
import androidx.compose.ui.test.onNodeWithText
|
||||
import androidx.compose.ui.test.performClick
|
||||
import androidx.compose.ui.test.performTextInput
|
||||
import applyWithViewHierarchyPrinting
|
||||
import com.adevinta.android.barista.interaction.BaristaSleepInteractions
|
||||
import org.kiwix.kiwixmobile.BaseRobot
|
||||
import org.kiwix.kiwixmobile.Findable.ViewId
|
||||
import org.kiwix.kiwixmobile.R
|
||||
import org.kiwix.kiwixmobile.core.R.string
|
||||
import org.kiwix.kiwixmobile.core.page.SEARCH_ICON_TESTING_TAG
|
||||
import org.kiwix.kiwixmobile.core.search.SEARCH_FIELD_TESTING_TAG
|
||||
import org.kiwix.kiwixmobile.language.composables.LANGUAGE_ITEM_CHECKBOX_TESTING_TAG
|
||||
import org.kiwix.kiwixmobile.nav.destination.library.online.LANGUAGE_MENU_ICON_TESTING_TAG
|
||||
import org.kiwix.kiwixmobile.testutils.TestUtils
|
||||
import org.kiwix.kiwixmobile.testutils.TestUtils.waitUntilTimeout
|
||||
@ -69,21 +69,6 @@ class LanguageRobot : BaseRobot() {
|
||||
searchField.performTextInput(text = searchLanguage)
|
||||
}
|
||||
|
||||
// error prone
|
||||
fun deSelectLanguageIfAlreadySelected(
|
||||
composeTestRule: ComposeContentTestRule,
|
||||
matchLanguage: String
|
||||
) {
|
||||
BaristaSleepInteractions.sleep(TestUtils.TEST_PAUSE_MS.toLong())
|
||||
try {
|
||||
composeTestRule.onNodeWithTag("$LANGUAGE_ITEM_CHECKBOX_TESTING_TAG$matchLanguage")
|
||||
.assertIsOff()
|
||||
} catch (_: AssertionError) {
|
||||
composeTestRule.onNodeWithTag("$LANGUAGE_ITEM_CHECKBOX_TESTING_TAG$matchLanguage")
|
||||
.performClick()
|
||||
}
|
||||
}
|
||||
|
||||
fun selectLanguage(
|
||||
composeTestRule: ComposeContentTestRule,
|
||||
matchLanguage: String
|
||||
@ -92,12 +77,27 @@ class LanguageRobot : BaseRobot() {
|
||||
.performClick()
|
||||
}
|
||||
|
||||
fun checkIsLanguageSelected(
|
||||
fun waitForLanguageToLoad(
|
||||
composeTestRule: ComposeContentTestRule,
|
||||
matchLanguage: String
|
||||
retryCountForDataToLoad: Int = 20
|
||||
) {
|
||||
BaristaSleepInteractions.sleep(TestUtils.TEST_PAUSE_MS.toLong())
|
||||
composeTestRule.onNodeWithTag("$LANGUAGE_ITEM_CHECKBOX_TESTING_TAG$matchLanguage")
|
||||
.assertIsOn()
|
||||
try {
|
||||
composeTestRule.waitUntil(TestUtils.TEST_PAUSE_MS_FOR_DOWNLOAD_TEST.toLong()) {
|
||||
composeTestRule
|
||||
.onAllNodesWithContentDescription(
|
||||
context.getString(string.select_language_content_description)
|
||||
)[0].isDisplayed()
|
||||
}
|
||||
} catch (e: ComposeTimeoutException) {
|
||||
if (retryCountForDataToLoad > 0) {
|
||||
waitForLanguageToLoad(
|
||||
retryCountForDataToLoad = retryCountForDataToLoad - 1,
|
||||
composeTestRule = composeTestRule
|
||||
)
|
||||
return
|
||||
}
|
||||
// throw the exception when there is no more retry left.
|
||||
throw RuntimeException("Couldn't load the language list.\n Original exception = $e")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -40,7 +40,7 @@ import org.kiwix.kiwixmobile.core.R
|
||||
import org.kiwix.kiwixmobile.core.utils.ComposeDimens
|
||||
import org.kiwix.kiwixmobile.language.composables.LanguageListItem.LanguageItem
|
||||
|
||||
const val LANGUAGE_ITEM_CHECKBOX_TESTING_TAG = "languageItemCheckboxTestingTag"
|
||||
const val LANGUAGE_ITEM_RADIO_BUTTON_TESTING_TAG = "languageItemRadioButtonTestingTag"
|
||||
|
||||
@Composable
|
||||
fun LanguageItemRow(
|
||||
@ -66,7 +66,7 @@ fun LanguageItemRow(
|
||||
modifier = Modifier
|
||||
.padding(ComposeDimens.SIXTEEN_DP)
|
||||
.semantics {
|
||||
testTag = "$LANGUAGE_ITEM_CHECKBOX_TESTING_TAG${language.language}"
|
||||
testTag = "$LANGUAGE_ITEM_RADIO_BUTTON_TESTING_TAG${language.language}"
|
||||
},
|
||||
selected = language.active,
|
||||
onClick = {
|
||||
|
@ -89,6 +89,7 @@ const val ONLINE_LIBRARY_SEARCH_VIEW_CLOSE_BUTTON_TESTING_TAG =
|
||||
"onlineLibrarySearchViewCloseButtonTestingTag"
|
||||
const val NO_CONTENT_VIEW_TEXT_TESTING_TAG = "noContentViewTextTestingTag"
|
||||
const val SHOW_FETCHING_LIBRARY_LAYOUT_TESTING_TAG = "showFetchingLibraryLayoutTestingTag"
|
||||
const val ONLINE_DIVIDER_ITEM_TEXT_TESTING_TAG = "onlineDividerItemTextTag"
|
||||
|
||||
@OptIn(ExperimentalMaterial3Api::class)
|
||||
@Suppress("ComposableLambdaParameterNaming")
|
||||
@ -256,7 +257,8 @@ private fun ShowDividerItem(dividerItem: DividerItem) {
|
||||
Text(
|
||||
text = dividerItem.sectionTitle,
|
||||
textAlign = TextAlign.Center,
|
||||
style = MaterialTheme.typography.titleMedium.copy(fontWeight = FontWeight.Normal)
|
||||
style = MaterialTheme.typography.titleMedium.copy(fontWeight = FontWeight.Normal),
|
||||
modifier = Modifier.semantics { testTag = ONLINE_DIVIDER_ITEM_TEXT_TESTING_TAG }
|
||||
)
|
||||
}
|
||||
}
|
||||
|
@ -126,7 +126,6 @@ const val MAX_PROGRESS = 100
|
||||
const val THREE = 3
|
||||
const val FOUR = 4
|
||||
|
||||
@Suppress("LargeClass", "UnusedPrivateProperty")
|
||||
class ZimManageViewModel @Inject constructor(
|
||||
private val downloadDao: DownloadRoomDao,
|
||||
private val libkiwixBookOnDisk: LibkiwixBookOnDisk,
|
||||
|
Loading…
x
Reference in New Issue
Block a user