Skip to content

Commit e4c7efc

Browse files
authored
Change Duck.ai auto-submit behavior (#5980)
Task/Issue URL: https://app.asana.com/1/137249556945/project/488551667048375/task/1210096722341714?focus=true ### Description - While on SERP, if the user is not currently typing in the address bar, tapping the Duck.ai button will pre-fill the query in Duck.ai. The user will then need to tap the submit button. - If the user is typing, then the prompt will auto-submit. - If the user opens Duck.ai while the current URL is in the address bar then Duck.ai is opened without a prompt. ### Steps to test this PR - [ ] On new tab, tap the Duck.ai button - [ ] Verify that Duck.ai is opened without a prompt - [ ] Go back - [ ] Type something and tap the Duck.ai button - [ ] Verify that Duck.ai is opened with auto-prompt - [ ] Go back and submit the query - [ ] Tap the address bar and then the Duck.ai button - [ ] Verify that the prompt is pre-filled - [ ] Go back - [ ] Edit the query and tap the Duck.ai button - [ ] Verify that Duck.ai is opened with auto-prompt - [ ] Kill the app and reopen - [ ] Tap the address bar and then the Duck.ai button - [ ] Verify that the prompt is pre-filled --- - To see the specific tasks where the Asana app for GitHub is being used, see below: - https://app.asana.com/0/0/1210117788341374
1 parent daa0a1c commit e4c7efc

File tree

3 files changed

+59
-6
lines changed

3 files changed

+59
-6
lines changed

app/src/androidTest/java/com/duckduckgo/app/browser/BrowserTabViewModelTest.kt

+45
Original file line numberDiff line numberDiff line change
@@ -6252,6 +6252,51 @@ class BrowserTabViewModelTest {
62526252
verify(mockDuckChat, never()).openDuckChatWithAutoPrompt(any())
62536253
}
62546254

6255+
@Test
6256+
fun whenOpenDuckChatWithQueryEqualToUrlThenOpenDuckChat() = runTest {
6257+
val url = "https://example.com"
6258+
loadUrl(url)
6259+
6260+
testee.openDuckChat(url)
6261+
6262+
verify(mockDuckChat).openDuckChat()
6263+
verify(mockDuckChat, never()).openDuckChatWithAutoPrompt(any())
6264+
}
6265+
6266+
@Test
6267+
fun whenOpenDuckChatWithLastSubmittedUserQueryThenOpenDuckChatWithQuery() = runTest {
6268+
val query = "example"
6269+
testee.setLastSubmittedUserQuery(query)
6270+
6271+
testee.openDuckChat(query)
6272+
6273+
verify(mockDuckChat).openDuckChat(query)
6274+
verify(mockDuckChat, never()).openDuckChatWithAutoPrompt(any())
6275+
}
6276+
6277+
@Test
6278+
fun whenLastSubmittedUserQueryIsNullAndOmnibarHasTextThenOpenDuckChatWithQuery() = runTest {
6279+
val query = "example"
6280+
testee.omnibarViewState.value = omnibarViewState().copy(omnibarText = "foo")
6281+
6282+
testee.openDuckChat(query)
6283+
6284+
verify(mockDuckChat).openDuckChat(query)
6285+
verify(mockDuckChat, never()).openDuckChatWithAutoPrompt(any())
6286+
}
6287+
6288+
@Test
6289+
fun whenLastSubmittedUserQueryDiffersFromNewQueryThenOpenWithAutoPrompt() = runTest {
6290+
val query = "example"
6291+
testee.setLastSubmittedUserQuery("foo")
6292+
testee.omnibarViewState.value = omnibarViewState().copy(omnibarText = "")
6293+
6294+
testee.openDuckChat(query)
6295+
6296+
verify(mockDuckChat).openDuckChatWithAutoPrompt(query)
6297+
verify(mockDuckChat, never()).openDuckChat()
6298+
}
6299+
62556300
private fun aCredential(): LoginCredentials {
62566301
return LoginCredentials(domain = null, username = null, password = null)
62576302
}

app/src/main/java/com/duckduckgo/app/browser/BrowserTabFragment.kt

+1
Original file line numberDiff line numberDiff line change
@@ -2800,6 +2800,7 @@ class BrowserTabFragment :
28002800
}
28012801

28022802
private fun userEnteredQuery(query: String) {
2803+
viewModel.setLastSubmittedUserQuery(query)
28032804
viewModel.onUserSubmittedQuery(query)
28042805
}
28052806

app/src/main/java/com/duckduckgo/app/browser/BrowserTabViewModel.kt

+13-6
Original file line numberDiff line numberDiff line change
@@ -571,6 +571,7 @@ class BrowserTabViewModel @Inject constructor(
571571
private var isProcessingTrackingLink = false
572572
private var isLinkOpenedInNewTab = false
573573
private var allowlistRefreshTriggerJob: Job? = null
574+
private var lastSubmittedUserQuery: String? = null
574575

575576
private val fireproofWebsitesObserver = Observer<List<FireproofWebsiteEntity>> {
576577
browserViewState.value = currentBrowserViewState().copy(isFireproofWebsite = isFireproofWebsite())
@@ -4102,12 +4103,18 @@ class BrowserTabViewModel @Inject constructor(
41024103
senseOfProtectionExperiment.firePrivacyDashboardClickedPixelIfInExperiment()
41034104
}
41044105

4105-
fun openDuckChat(query: String?) {
4106-
if (query?.isNotEmpty() == true) {
4107-
duckChat.openDuckChatWithAutoPrompt(query)
4108-
} else {
4109-
duckChat.openDuckChat()
4110-
}
4106+
fun openDuckChat(query: String?) = when {
4107+
query.isNullOrBlank() || query == url -> duckChat.openDuckChat()
4108+
4109+
query == lastSubmittedUserQuery ||
4110+
(lastSubmittedUserQuery == null && !omnibarViewState.value?.omnibarText.isNullOrBlank())
4111+
-> duckChat.openDuckChat(query)
4112+
4113+
else -> duckChat.openDuckChatWithAutoPrompt(query)
4114+
}
4115+
4116+
fun setLastSubmittedUserQuery(query: String) {
4117+
lastSubmittedUserQuery = query
41114118
}
41124119

41134120
companion object {

0 commit comments

Comments
 (0)