-
Notifications
You must be signed in to change notification settings - Fork 59
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'origin/master'
- Loading branch information
Showing
4 changed files
with
101 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
50 changes: 50 additions & 0 deletions
50
medusalib/src/androidTest/java/com/trendyol/medusalib/TestParentWithNavigatorFragment.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} | ||
} |
48 changes: 48 additions & 0 deletions
48
...b/src/androidTest/java/com/trendyol/medusalib/navigator/ActivityRecreationResetTabTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() | ||
} | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters