Skip to content

Commit 5a32188

Browse files
committed
add test for text submission
1 parent bdc0222 commit 5a32188

File tree

3 files changed

+33
-1
lines changed

3 files changed

+33
-1
lines changed

duckchat/duckchat-impl/src/main/java/com/duckduckgo/duckchat/impl/inputscreen/ui/viewmodel/InputScreenViewModel.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -418,7 +418,7 @@ class InputScreenViewModel @AssistedInject constructor(
418418
fun onChatSubmitted(query: String) {
419419
viewModelScope.launch {
420420
when {
421-
_visibilityState.value.fullScreenMode -> {
421+
visibilityState.value.fullScreenMode -> {
422422
val url = duckChat.getDuckChatUrl(query, true)
423423
command.value = Command.SubmitSearch(url)
424424
}

duckchat/duckchat-impl/src/test/kotlin/com/duckduckgo/duckchat/impl/messaging/fakes/FakeDuckChat.kt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,13 @@ class FakeDuckChat(
4646
openDuckChatWithPrefillCalls.add(query)
4747
}
4848

49+
override fun getDuckChatUrl(
50+
query: String,
51+
autoPrompt: Boolean,
52+
): String {
53+
return "https://duckduckgo.com/?q=DuckDuckGo+AI+Chat&ia=chat&duckai=5"
54+
}
55+
4956
override fun isDuckChatUrl(uri: Uri): Boolean {
5057
return uri.toString().contains("duckchat")
5158
}

duckchat/duckchat-impl/src/test/kotlin/com/duckduckgo/duckchat/impl/ui/inputscreen/InputScreenViewModelTest.kt

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import com.duckduckgo.browser.api.autocomplete.AutoCompleteFactory
2020
import com.duckduckgo.browser.api.autocomplete.AutoCompleteSettings
2121
import com.duckduckgo.common.test.CoroutineTestRule
2222
import com.duckduckgo.common.utils.extensions.toBinaryString
23+
import com.duckduckgo.duckchat.api.DuckAiFeatureState
2324
import com.duckduckgo.duckchat.api.DuckChat
2425
import com.duckduckgo.duckchat.impl.inputscreen.ui.InputScreenConfigResolver
2526
import com.duckduckgo.duckchat.impl.inputscreen.ui.command.Command
@@ -42,6 +43,7 @@ import com.duckduckgo.history.api.NavigationHistory
4243
import com.duckduckgo.voice.api.VoiceSearchAvailability
4344
import kotlinx.coroutines.ExperimentalCoroutinesApi
4445
import kotlinx.coroutines.flow.MutableSharedFlow
46+
import kotlinx.coroutines.flow.MutableStateFlow
4547
import kotlinx.coroutines.flow.flow
4648
import kotlinx.coroutines.flow.flowOf
4749
import kotlinx.coroutines.test.advanceTimeBy
@@ -86,6 +88,11 @@ class InputScreenViewModelTest {
8688
private val inputScreenConfigResolver: InputScreenConfigResolver = mock()
8789
private val omnibarRepository: OmnibarRepository = mock()
8890

91+
private val duckAiFeatureState: DuckAiFeatureState = mock()
92+
private val fullScreenModeDisabledFlow = MutableStateFlow(false)
93+
private val fullScreenModeEnabledFlow = MutableStateFlow(true)
94+
private val duckChatURL = "https://duckduckgo.com/?q=DuckDuckGo+AI+Chat&ia=chat&duckai=5"
95+
8996
@Before
9097
fun setup() =
9198
runTest {
@@ -95,9 +102,11 @@ class InputScreenViewModelTest {
95102
flowOf(AutoCompleteResult("", listOf(AutoCompleteDefaultSuggestion("suggestion")))),
96103
)
97104
whenever(duckChat.wasOpenedBefore()).thenReturn(false)
105+
whenever(duckChat.getDuckChatUrl(any(), any())).thenReturn(duckChatURL)
98106
whenever(inputScreenConfigResolver.useTopBar()).thenReturn(true)
99107
whenever(voiceSearchAvailability.isVoiceSearchAvailable).thenReturn(true)
100108
whenever(omnibarRepository.omnibarType).thenReturn(OmnibarType.SINGLE_TOP)
109+
whenever(duckAiFeatureState.showFullScreenMode).thenReturn(fullScreenModeDisabledFlow)
101110
}
102111

103112
private fun createViewModel(currentOmnibarText: String = ""): InputScreenViewModel =
@@ -116,6 +125,7 @@ class InputScreenViewModelTest {
116125
inputScreenSessionUsageMetric = inputScreenSessionUsageMetric,
117126
inputScreenConfigResolver = inputScreenConfigResolver,
118127
omnibarRepository = omnibarRepository,
128+
duckAiFeatureState = duckAiFeatureState,
119129
)
120130

121131
@Test
@@ -2000,4 +2010,19 @@ class InputScreenViewModelTest {
20002010

20012011
assertFalse(viewModel.visibilityState.value.mainButtonsVisible)
20022012
}
2013+
2014+
@Test
2015+
fun `when fullscreen mode enabled submitting chat sends a query to the main fragment`() =
2016+
runTest {
2017+
whenever(duckAiFeatureState.showFullScreenMode).thenReturn(fullScreenModeEnabledFlow)
2018+
whenever(inputScreenSessionStore.hasUsedSearchMode()).thenReturn(false)
2019+
whenever(inputScreenSessionStore.hasUsedChatMode()).thenReturn(false)
2020+
2021+
val viewModel = createViewModel()
2022+
val query = "example"
2023+
2024+
viewModel.onChatSubmitted(query)
2025+
2026+
assertEquals(SubmitSearch(duckChatURL), viewModel.command.value)
2027+
}
20032028
}

0 commit comments

Comments
 (0)