For #25980: Use new backQueue instead of removed backStack.

pull/543/head
mcarare 2 years ago committed by mergify[bot]
parent 55724deda9
commit 8ed3bf704f

@ -917,7 +917,7 @@ class SearchDialogFragment : AppCompatDialogFragment(), UserInteractionHandler {
internal fun getPreviousDestination(): NavBackStackEntry? { internal fun getPreviousDestination(): NavBackStackEntry? {
// This duplicates the platform functionality for "previousBackStackEntry" but additionally skips this entry. // This duplicates the platform functionality for "previousBackStackEntry" but additionally skips this entry.
val descendingEntries = findNavController().backStack.descendingIterator() val descendingEntries = findNavController().backQueue.reversed().iterator()
// Throw the topmost destination away. // Throw the topmost destination away.
if (descendingEntries.hasNext()) { if (descendingEntries.hasNext()) {
descendingEntries.next() descendingEntries.next()

@ -17,7 +17,6 @@ import org.junit.Assert.assertNull
import org.junit.Assert.assertSame import org.junit.Assert.assertSame
import org.junit.Before import org.junit.Before
import org.junit.Test import org.junit.Test
import java.util.ArrayDeque
internal class SearchDialogFragmentTest { internal class SearchDialogFragmentTest {
private val navController: NavController = mockk() private val navController: NavController = mockk()
@ -36,14 +35,14 @@ internal class SearchDialogFragmentTest {
@Test @Test
fun `GIVEN this is the only visible fragment WHEN asking for the previous destination THEN return null`() { fun `GIVEN this is the only visible fragment WHEN asking for the previous destination THEN return null`() {
every { navController.backStack } returns ArrayDeque(listOf(getDestination(fragmentName))) every { navController.backQueue } returns ArrayDeque(listOf(getDestination(fragmentName)))
assertNull(fragment.getPreviousDestination()) assertNull(fragment.getPreviousDestination())
} }
@Test @Test
fun `GIVEN this and FragmentB on top of this are visible WHEN asking for the previous destination THEN return null`() { fun `GIVEN this and FragmentB on top of this are visible WHEN asking for the previous destination THEN return null`() {
every { navController.backStack } returns ArrayDeque( every { navController.backQueue } returns ArrayDeque(
listOf( listOf(
getDestination(fragmentName), getDestination(fragmentName),
getDestination("FragmentB"), getDestination("FragmentB"),
@ -56,7 +55,7 @@ internal class SearchDialogFragmentTest {
@Test @Test
fun `GIVEN FragmentA, this and FragmentB are visible WHEN asking for the previous destination THEN return FragmentA`() { fun `GIVEN FragmentA, this and FragmentB are visible WHEN asking for the previous destination THEN return FragmentA`() {
val fragmentADestination = getDestination("FragmentA") val fragmentADestination = getDestination("FragmentA")
every { navController.backStack } returns ArrayDeque( every { navController.backQueue } returns ArrayDeque(
listOf( listOf(
fragmentADestination, fragmentADestination,
getDestination(fragmentName), getDestination(fragmentName),
@ -70,7 +69,7 @@ internal class SearchDialogFragmentTest {
@Test @Test
fun `GIVEN FragmentA and this on top of it are visible WHEN asking for the previous destination THEN return FragmentA`() { fun `GIVEN FragmentA and this on top of it are visible WHEN asking for the previous destination THEN return FragmentA`() {
val fragmentADestination = getDestination("FragmentA") val fragmentADestination = getDestination("FragmentA")
every { navController.backStack } returns ArrayDeque( every { navController.backQueue } returns ArrayDeque(
listOf( listOf(
fragmentADestination, fragmentADestination,
getDestination(fragmentName), getDestination(fragmentName),

Loading…
Cancel
Save