This repository has been archived by the owner on Feb 20, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
For #27016 - Ensure smooth search UX after the MR onboarding is closed
If the app is opened from the search widget and the MR onboarding is shown then the backstack will have the following structure: - root, homeFragment, searchDialogFragment, onboardingFragment as opposed to otherwise - root, homeFragment, searchDialogFragment. This patch allows to avoid the MR onboarding fragment causing the SearchDialogFragment to not know that below it is the HomeFragment and consequently not applying transparency or propagate user touches to the parent Activity.
- Loading branch information
1 parent
6c6c3f5
commit 47b7336
Showing
2 changed files
with
130 additions
and
4 deletions.
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
92 changes: 92 additions & 0 deletions
92
app/src/test/java/org/mozilla/fenix/search/SearchDialogFragmentTest.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,92 @@ | ||
/* This Source Code Form is subject to the terms of the Mozilla Public | ||
* License, v. 2.0. If a copy of the MPL was not distributed with this | ||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */ | ||
|
||
package org.mozilla.fenix.search | ||
|
||
import androidx.fragment.app.Fragment | ||
import androidx.navigation.NavBackStackEntry | ||
import androidx.navigation.NavController | ||
import androidx.navigation.fragment.findNavController | ||
import io.mockk.every | ||
import io.mockk.mockk | ||
import io.mockk.mockkStatic | ||
import io.mockk.unmockkStatic | ||
import org.junit.After | ||
import org.junit.Assert.assertNull | ||
import org.junit.Assert.assertSame | ||
import org.junit.Before | ||
import org.junit.Test | ||
import java.util.ArrayDeque | ||
|
||
internal class SearchDialogFragmentTest { | ||
private val navController: NavController = mockk() | ||
private val fragment = SearchDialogFragment() | ||
|
||
@Before | ||
fun setup() { | ||
mockkStatic("androidx.navigation.fragment.FragmentKt") | ||
every { any<Fragment>().findNavController() } returns navController | ||
} | ||
|
||
@After | ||
fun teardown() { | ||
unmockkStatic("androidx.navigation.fragment.FragmentKt") | ||
} | ||
|
||
@Test | ||
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))) | ||
|
||
assertNull(fragment.getPreviousDestination()) | ||
} | ||
|
||
@Test | ||
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( | ||
listOf( | ||
getDestination(fragmentName), | ||
getDestination("FragmentB"), | ||
), | ||
) | ||
|
||
assertNull(fragment.getPreviousDestination()) | ||
} | ||
|
||
@Test | ||
fun `GIVEN FragmentA, this and FragmentB are visible WHEN asking for the previous destination THEN return FragmentA`() { | ||
val fragmentADestination = getDestination("FragmentA") | ||
every { navController.backStack } returns ArrayDeque( | ||
listOf( | ||
fragmentADestination, | ||
getDestination(fragmentName), | ||
getDestination("FragmentB"), | ||
), | ||
) | ||
|
||
assertSame(fragmentADestination, fragment.getPreviousDestination()) | ||
} | ||
|
||
@Test | ||
fun `GIVEN FragmentA and this on top of it are visible WHEN asking for the previous destination THEN return FragmentA`() { | ||
val fragmentADestination = getDestination("FragmentA") | ||
every { navController.backStack } returns ArrayDeque( | ||
listOf( | ||
fragmentADestination, | ||
getDestination(fragmentName), | ||
), | ||
) | ||
|
||
assertSame(fragmentADestination, fragment.getPreviousDestination()) | ||
} | ||
} | ||
|
||
private val fragmentName = SearchDialogFragment::class.java.canonicalName?.substringAfterLast('.')!! | ||
|
||
private fun getDestination(destinationName: String): NavBackStackEntry { | ||
return mockk { | ||
every { destination } returns mockk { | ||
every { displayName } returns "test.id/$destinationName" | ||
} | ||
} | ||
} |