Refactored the test cases according to savedStateHandle approach.

This commit is contained in:
MohitMaliFtechiz 2025-09-02 19:04:58 +05:30
parent 00e62eb807
commit 8fa15c12bd
7 changed files with 42 additions and 28 deletions

View File

@ -40,7 +40,9 @@ import org.junit.Before
import org.junit.Rule import org.junit.Rule
import org.junit.Test import org.junit.Test
import org.kiwix.kiwixmobile.BaseActivityTest import org.kiwix.kiwixmobile.BaseActivityTest
import org.kiwix.kiwixmobile.core.extensions.ActivityExtensions.setNavigationResultOnCurrent
import org.kiwix.kiwixmobile.core.main.CoreMainActivity import org.kiwix.kiwixmobile.core.main.CoreMainActivity
import org.kiwix.kiwixmobile.core.main.ZIM_FILE_URI_KEY
import org.kiwix.kiwixmobile.core.ui.components.NAVIGATION_ICON_TESTING_TAG import org.kiwix.kiwixmobile.core.ui.components.NAVIGATION_ICON_TESTING_TAG
import org.kiwix.kiwixmobile.core.utils.LanguageUtils import org.kiwix.kiwixmobile.core.utils.LanguageUtils
import org.kiwix.kiwixmobile.core.utils.SharedPreferenceUtil import org.kiwix.kiwixmobile.core.utils.SharedPreferenceUtil
@ -206,10 +208,10 @@ class DarkModeViewPainterTest : BaseActivityTest() {
val navOptions = NavOptions.Builder() val navOptions = NavOptions.Builder()
.setPopUpTo(KiwixDestination.Reader.route, false) .setPopUpTo(KiwixDestination.Reader.route, false)
.build() .build()
composeTestRule.activity.navigate( composeTestRule.activity.apply {
KiwixDestination.Reader.createRoute(zimFileUri = zimFile.toUri().toString()), navigate(KiwixDestination.Reader.route, navOptions)
navOptions setNavigationResultOnCurrent(zimFile.toUri().toString(), ZIM_FILE_URI_KEY)
) }
} }
composeTestRule.waitForIdle() composeTestRule.waitForIdle()
} }

View File

@ -43,7 +43,9 @@ import org.junit.Before
import org.junit.Rule import org.junit.Rule
import org.junit.Test import org.junit.Test
import org.kiwix.kiwixmobile.BaseActivityTest import org.kiwix.kiwixmobile.BaseActivityTest
import org.kiwix.kiwixmobile.core.extensions.ActivityExtensions.setNavigationResultOnCurrent
import org.kiwix.kiwixmobile.core.main.CoreMainActivity import org.kiwix.kiwixmobile.core.main.CoreMainActivity
import org.kiwix.kiwixmobile.core.main.ZIM_FILE_URI_KEY
import org.kiwix.kiwixmobile.core.utils.LanguageUtils.Companion.handleLocaleChange import org.kiwix.kiwixmobile.core.utils.LanguageUtils.Companion.handleLocaleChange
import org.kiwix.kiwixmobile.core.utils.SharedPreferenceUtil import org.kiwix.kiwixmobile.core.utils.SharedPreferenceUtil
import org.kiwix.kiwixmobile.core.utils.TestingUtils.COMPOSE_TEST_RULE_ORDER import org.kiwix.kiwixmobile.core.utils.TestingUtils.COMPOSE_TEST_RULE_ORDER
@ -295,10 +297,10 @@ class NoteFragmentTest : BaseActivityTest() {
val navOptions = NavOptions.Builder() val navOptions = NavOptions.Builder()
.setPopUpTo(KiwixDestination.Reader.route, false) .setPopUpTo(KiwixDestination.Reader.route, false)
.build() .build()
kiwixMainActivity.navigate( kiwixMainActivity.apply {
KiwixDestination.Reader.createRoute(zimFileUri = zimFile.toUri().toString()), kiwixMainActivity.navigate(KiwixDestination.Reader.route, navOptions)
navOptions setNavigationResultOnCurrent(zimFile.toUri().toString(), ZIM_FILE_URI_KEY)
) }
} }
} }

View File

@ -42,7 +42,9 @@ import org.junit.Before
import org.junit.Rule import org.junit.Rule
import org.junit.Test import org.junit.Test
import org.kiwix.kiwixmobile.BaseActivityTest import org.kiwix.kiwixmobile.BaseActivityTest
import org.kiwix.kiwixmobile.core.extensions.ActivityExtensions.setNavigationResultOnCurrent
import org.kiwix.kiwixmobile.core.main.CoreMainActivity import org.kiwix.kiwixmobile.core.main.CoreMainActivity
import org.kiwix.kiwixmobile.core.main.ZIM_FILE_URI_KEY
import org.kiwix.kiwixmobile.core.main.reader.CoreReaderFragment import org.kiwix.kiwixmobile.core.main.reader.CoreReaderFragment
import org.kiwix.kiwixmobile.core.page.bookmark.adapter.LibkiwixBookmarkItem import org.kiwix.kiwixmobile.core.page.bookmark.adapter.LibkiwixBookmarkItem
import org.kiwix.kiwixmobile.core.utils.LanguageUtils.Companion.handleLocaleChange import org.kiwix.kiwixmobile.core.utils.LanguageUtils.Companion.handleLocaleChange
@ -259,10 +261,10 @@ class LibkiwixBookmarkTest : BaseActivityTest() {
val navOptions = NavOptions.Builder() val navOptions = NavOptions.Builder()
.setPopUpTo(KiwixDestination.Reader.route, false) .setPopUpTo(KiwixDestination.Reader.route, false)
.build() .build()
kiwixMainActivity.navigate( kiwixMainActivity.apply {
KiwixDestination.Reader.createRoute(zimFileUri = zimFile.toUri().toString()), kiwixMainActivity.navigate(KiwixDestination.Reader.route, navOptions)
navOptions setNavigationResultOnCurrent(zimFile.toUri().toString(), ZIM_FILE_URI_KEY)
) }
} }
waitComposeToSettleViews() waitComposeToSettleViews()
} }

View File

@ -42,7 +42,9 @@ import org.junit.Before
import org.junit.Rule import org.junit.Rule
import org.junit.Test import org.junit.Test
import org.kiwix.kiwixmobile.BaseActivityTest import org.kiwix.kiwixmobile.BaseActivityTest
import org.kiwix.kiwixmobile.core.extensions.ActivityExtensions.setNavigationResultOnCurrent
import org.kiwix.kiwixmobile.core.main.CoreMainActivity import org.kiwix.kiwixmobile.core.main.CoreMainActivity
import org.kiwix.kiwixmobile.core.main.ZIM_FILE_URI_KEY
import org.kiwix.kiwixmobile.core.utils.LanguageUtils.Companion.handleLocaleChange import org.kiwix.kiwixmobile.core.utils.LanguageUtils.Companion.handleLocaleChange
import org.kiwix.kiwixmobile.core.utils.SharedPreferenceUtil import org.kiwix.kiwixmobile.core.utils.SharedPreferenceUtil
import org.kiwix.kiwixmobile.core.utils.TestingUtils.COMPOSE_TEST_RULE_ORDER import org.kiwix.kiwixmobile.core.utils.TestingUtils.COMPOSE_TEST_RULE_ORDER
@ -152,10 +154,10 @@ class NavigationHistoryTest : BaseActivityTest() {
val navOptions = NavOptions.Builder() val navOptions = NavOptions.Builder()
.setPopUpTo(KiwixDestination.Reader.route, false) .setPopUpTo(KiwixDestination.Reader.route, false)
.build() .build()
kiwixMainActivity.navigate( kiwixMainActivity.apply {
KiwixDestination.Reader.createRoute(zimFileUri = zimFile.toUri().toString()), kiwixMainActivity.navigate(KiwixDestination.Reader.route, navOptions)
navOptions setNavigationResultOnCurrent(zimFile.toUri().toString(), ZIM_FILE_URI_KEY)
) }
} }
waitForIdle() waitForIdle()
} }

View File

@ -46,7 +46,9 @@ import org.junit.Before
import org.junit.Rule import org.junit.Rule
import org.junit.Test import org.junit.Test
import org.kiwix.kiwixmobile.BaseActivityTest import org.kiwix.kiwixmobile.BaseActivityTest
import org.kiwix.kiwixmobile.core.extensions.ActivityExtensions.setNavigationResultOnCurrent
import org.kiwix.kiwixmobile.core.main.CoreMainActivity import org.kiwix.kiwixmobile.core.main.CoreMainActivity
import org.kiwix.kiwixmobile.core.main.ZIM_FILE_URI_KEY
import org.kiwix.kiwixmobile.core.utils.LanguageUtils.Companion.handleLocaleChange import org.kiwix.kiwixmobile.core.utils.LanguageUtils.Companion.handleLocaleChange
import org.kiwix.kiwixmobile.core.utils.SharedPreferenceUtil import org.kiwix.kiwixmobile.core.utils.SharedPreferenceUtil
import org.kiwix.kiwixmobile.core.utils.TestingUtils.COMPOSE_TEST_RULE_ORDER import org.kiwix.kiwixmobile.core.utils.TestingUtils.COMPOSE_TEST_RULE_ORDER
@ -338,10 +340,10 @@ class KiwixReaderFragmentTest : BaseActivityTest() {
val navOptions = NavOptions.Builder() val navOptions = NavOptions.Builder()
.setPopUpTo(KiwixDestination.Reader.route, false) .setPopUpTo(KiwixDestination.Reader.route, false)
.build() .build()
kiwixMainActivity.navigate( kiwixMainActivity.apply {
KiwixDestination.Reader.createRoute(zimFileUri = zimFile.toUri().toString()), kiwixMainActivity.navigate(KiwixDestination.Reader.route, navOptions)
navOptions setNavigationResultOnCurrent(zimFile.toUri().toString(), ZIM_FILE_URI_KEY)
) }
} }
} }

View File

@ -45,6 +45,8 @@ import org.junit.Test
import org.junit.jupiter.api.fail import org.junit.jupiter.api.fail
import org.kiwix.kiwixmobile.BaseActivityTest import org.kiwix.kiwixmobile.BaseActivityTest
import org.kiwix.kiwixmobile.core.DarkModeConfig import org.kiwix.kiwixmobile.core.DarkModeConfig
import org.kiwix.kiwixmobile.core.extensions.ActivityExtensions.setNavigationResultOnCurrent
import org.kiwix.kiwixmobile.core.main.ZIM_FILE_URI_KEY
import org.kiwix.kiwixmobile.core.reader.ZimFileReader import org.kiwix.kiwixmobile.core.reader.ZimFileReader
import org.kiwix.kiwixmobile.core.reader.ZimReaderSource import org.kiwix.kiwixmobile.core.reader.ZimReaderSource
import org.kiwix.kiwixmobile.core.utils.LanguageUtils.Companion.handleLocaleChange import org.kiwix.kiwixmobile.core.utils.LanguageUtils.Companion.handleLocaleChange
@ -125,10 +127,10 @@ class ZimFileReaderWithSplittedZimFileTest : BaseActivityTest() {
val navOptions = NavOptions.Builder() val navOptions = NavOptions.Builder()
.setPopUpTo(KiwixDestination.Reader.route, false) .setPopUpTo(KiwixDestination.Reader.route, false)
.build() .build()
kiwixMainActivity.navigate( kiwixMainActivity.apply {
KiwixDestination.Reader.createRoute(zimFileUri = it.toUri().toString()), kiwixMainActivity.navigate(KiwixDestination.Reader.route, navOptions)
navOptions setNavigationResultOnCurrent(it.toUri().toString(), ZIM_FILE_URI_KEY)
) }
} }
composeTestRule.waitForIdle() composeTestRule.waitForIdle()
navigationHistory { navigationHistory {

View File

@ -46,6 +46,8 @@ import org.junit.Before
import org.junit.Rule import org.junit.Rule
import org.junit.Test import org.junit.Test
import org.kiwix.kiwixmobile.BaseActivityTest import org.kiwix.kiwixmobile.BaseActivityTest
import org.kiwix.kiwixmobile.core.extensions.ActivityExtensions.setNavigationResultOnCurrent
import org.kiwix.kiwixmobile.core.main.ZIM_FILE_URI_KEY
import org.kiwix.kiwixmobile.core.search.SearchFragment import org.kiwix.kiwixmobile.core.search.SearchFragment
import org.kiwix.kiwixmobile.core.search.viewmodel.Action import org.kiwix.kiwixmobile.core.search.viewmodel.Action
import org.kiwix.kiwixmobile.core.utils.LanguageUtils.Companion.handleLocaleChange import org.kiwix.kiwixmobile.core.utils.LanguageUtils.Companion.handleLocaleChange
@ -317,10 +319,10 @@ class SearchFragmentTest : BaseActivityTest() {
val navOptions = NavOptions.Builder() val navOptions = NavOptions.Builder()
.setPopUpTo(KiwixDestination.Reader.route, false) .setPopUpTo(KiwixDestination.Reader.route, false)
.build() .build()
kiwixMainActivity.navigate( kiwixMainActivity.apply {
KiwixDestination.Reader.createRoute(zimFileUri = zimFile.toUri().toString()), kiwixMainActivity.navigate(KiwixDestination.Reader.route, navOptions)
navOptions setNavigationResultOnCurrent(zimFile.toUri().toString(), ZIM_FILE_URI_KEY)
) }
} }
} }