Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master'
Browse files Browse the repository at this point in the history
  • Loading branch information
mert.yuksel committed Oct 2, 2024
2 parents 2246287 + 10518de commit 99db321
Show file tree
Hide file tree
Showing 4 changed files with 101 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ class TestChildFragment : Fragment() {
}
}

fun requireArgumentTitle() = requireArguments().getString(KEY_TITLE)!!

companion object {
fun newInstance(title: String): TestChildFragment {
return TestChildFragment().apply {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
package com.trendyol.medusalib

import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.FrameLayout
import androidx.fragment.app.Fragment
import com.trendyol.medusalib.navigator.MultipleStackNavigator
import com.trendyol.medusalib.navigator.Navigator
import com.trendyol.medusalib.navigator.NavigatorConfiguration
import com.trendyol.medusalib.navigator.transaction.NavigatorTransaction
import com.trendyol.medusalib.navigator.transaction.TransactionType

class TestParentWithNavigatorFragment : Fragment() {

lateinit var navigator: Navigator

override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
navigator = createNavigator(
{ TestChildFragment.newInstance("Root1") },
{ TestChildFragment.newInstance("Root2") },
{ TestChildFragment.newInstance("Root3") }
)
navigator.initialize(savedInstanceState)
return FrameLayout(requireContext()).apply { id = CONTAINER_ID }
}

fun createNavigator(
vararg rootFragments: () -> TestChildFragment
): MultipleStackNavigator {
return MultipleStackNavigator(
fragmentManager = this.childFragmentManager,
containerId = TestParentFragment.CONTAINER_ID,
rootFragmentProvider = rootFragments.toList(),
navigatorConfiguration = NavigatorConfiguration(
defaultNavigatorTransaction = NavigatorTransaction(TransactionType.SHOW_HIDE)
)
)
}

override fun onSaveInstanceState(outState: Bundle) {
navigator.onSaveInstanceState(outState)
super.onSaveInstanceState(outState)
}

companion object {
const val CONTAINER_ID = 1_000
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
package com.trendyol.medusalib.navigator

import androidx.fragment.app.testing.launchFragmentInContainer
import androidx.lifecycle.Lifecycle
import androidx.test.ext.junit.runners.AndroidJUnit4
import com.google.common.truth.Truth
import com.trendyol.medusalib.TestChildFragment
import com.trendyol.medusalib.TestParentWithNavigatorFragment
import org.junit.Test
import org.junit.runner.RunWith


@RunWith(AndroidJUnit4::class)
class ActivityRecreationResetTabTest {

@Test
fun givenWithMultipleStackNavigatorWhenresetCurrentTabIsCalledAfterActionRecreationThenRootFragmentMustBevVisible() {
// Given
launchFragmentInContainer<TestParentWithNavigatorFragment>(
initialState = Lifecycle.State.INITIALIZED
)
.moveToState(Lifecycle.State.RESUMED)
.onFragment {
it.navigator.switchTab(2)
it.childFragmentManager.executePendingTransactions()

it.navigator.start(TestChildFragment.newInstance("Root3-1"))
it.childFragmentManager.executePendingTransactions()

it.navigator.start(TestChildFragment.newInstance("Root3-2"))
it.childFragmentManager.executePendingTransactions()
}
// When
.recreate()
// Then
.onFragment {
it.navigator.resetCurrentTab(resetRootFragment = false)
it.childFragmentManager.executePendingTransactions()
Truth.assertThat(
it
.childFragmentManager
.fragments.first { (it as TestChildFragment).requireArgumentTitle() == "Root3" }
.isVisible
).isTrue()
}

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ open class MultipleStackNavigator(
val upperFragment: Fragment? = fragmentManagerController.getFragment(upperFragmentTag)

val newDestination: Fragment = upperFragment ?: getRootFragment(currentTabIndex)
val newDestinationTag: String = tagCreator.create(newDestination)
val newDestinationTag: String = newDestination.tag ?: tagCreator.create(newDestination)

newDestination.observeFragmentLifecycle(
onViewCreated = ::onFragmentViewCreated,
Expand Down

0 comments on commit 99db321

Please sign in to comment.