Skip to content

Commit

Permalink
For mozilla-mobile#12025: Set Search Shortcuts Off By Default
Browse files Browse the repository at this point in the history
  • Loading branch information
Kate Glazko authored and Kate Glazko committed Jun 27, 2020
1 parent df49db6 commit f4e0908
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 2 deletions.
12 changes: 12 additions & 0 deletions app/src/androidTest/java/org/mozilla/fenix/ui/SearchTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,12 @@ class SearchTest {
@Test
fun shortcutButtonTest() {
homeScreen {
}.openThreeDotMenu {
}.openSettings {
}.openSearchSubMenu {
enableShowSearchShortcuts()
}.goBack {
}.goBack {
}.openSearch {
verifySearchWithText()
clickSearchEngineButton("DuckDuckGo")
Expand All @@ -63,6 +69,12 @@ class SearchTest {
@Test
fun shortcutSearchEngineSettingsTest() {
homeScreen {
}.openThreeDotMenu {
}.openSettings {
}.openSearchSubMenu {
enableShowSearchShortcuts()
}.goBack {
}.goBack {
}.openSearch {
scrollToSearchEngineSettings()
clickSearchEngineSettings()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ class SettingsSubMenuSearchRobot {
selectDefaultSearchEngine(searchEngineName)

fun disableShowSearchSuggestions() = toggleShowSearchSuggestions()
fun enableShowSearchShortcuts() = toggleShowSearchShortcuts()

class Transition {
val mDevice = UiDevice.getInstance(InstrumentationRegistry.getInstrumentation())
Expand Down Expand Up @@ -142,5 +143,16 @@ private fun toggleShowSearchSuggestions() {
.perform(click())
}

private fun toggleShowSearchShortcuts() {
onView(withId(androidx.preference.R.id.recycler_view)).perform(
RecyclerViewActions.scrollTo<RecyclerView.ViewHolder>(
hasDescendant(withText("Show search shortcuts"))
)
)

onView(withText("Show search shortcuts"))
.perform(click())
}

private fun goBackButton() =
onView(CoreMatchers.allOf(withContentDescription("Navigate up")))
2 changes: 1 addition & 1 deletion app/src/main/java/org/mozilla/fenix/utils/Settings.kt
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,7 @@ class Settings private constructor(

val shouldShowSearchShortcuts by booleanPreference(
appContext.getPreferenceKey(R.string.pref_key_show_search_shortcuts),
default = true
default = false
)

val shouldUseDarkTheme by booleanPreference(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,10 @@ class DefaultSearchControllerTest {
@Test
fun `show search shortcuts when setting enabled AND query empty`() {
val text = ""
testContext.settings().preferences
.edit()
.putBoolean(testContext.getString(R.string.pref_key_show_search_shortcuts), true)
.apply()

controller.handleTextChanged(text)

Expand All @@ -160,6 +164,10 @@ class DefaultSearchControllerTest {
fun `show search shortcuts when setting enabled AND query equals url`() {
val text = "mozilla.org"
every { session?.url } returns "mozilla.org"
testContext.settings().preferences
.edit()
.putBoolean(testContext.getString(R.string.pref_key_show_search_shortcuts), true)
.apply()

assertEquals(text, session?.url)

Expand Down
2 changes: 1 addition & 1 deletion app/src/test/java/org/mozilla/fenix/utils/SettingsTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,7 @@ class SettingsTest {
fun shouldShowSearchShortcuts() {
// When just created
// Then
assertTrue(settings.shouldShowSearchShortcuts)
assertFalse(settings.shouldShowSearchShortcuts)
}

@Test
Expand Down

0 comments on commit f4e0908

Please sign in to comment.