Skip to content

Commit e95fd56

Browse files
committed
add test for browser menu duck.ai
1 parent 5dbf8d4 commit e95fd56

File tree

2 files changed

+22
-1
lines changed

2 files changed

+22
-1
lines changed

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

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -459,6 +459,8 @@ class BrowserTabViewModelTest {
459459

460460
private val mockDuckAiFeatureStateInputScreenOpenAutomaticallyFlow = MutableStateFlow(false)
461461

462+
private val mockDuckAiFeatureStateFullScreenModeFlow = MutableStateFlow(false)
463+
462464
private val mockExternalIntentProcessingState: ExternalIntentProcessingState = mock()
463465

464466
private val mockVpnMenuStateProvider: VpnMenuStateProvider = mock()
@@ -607,6 +609,7 @@ class BrowserTabViewModelTest {
607609

608610
private val exampleUrl = "http://example.com"
609611
private val shortExampleUrl = "example.com"
612+
private val duckChatURL = "https://duckduckgo.com/?q=DuckDuckGo+AI+Chat&ia=chat&duckai=5"
610613

611614
private val selectedTab = TabEntity("TAB_ID", exampleUrl, position = 0, sourceTabId = "TAB_ID_SOURCE")
612615
private val flowSelectedTab = MutableStateFlow(selectedTab)
@@ -692,6 +695,7 @@ class BrowserTabViewModelTest {
692695
whenever(mockDuckAiFeatureState.showPopupMenuShortcut).thenReturn(MutableStateFlow(false))
693696
whenever(mockDuckAiFeatureState.showInputScreen).thenReturn(mockDuckAiFeatureStateInputScreenFlow)
694697
whenever(mockDuckAiFeatureState.showInputScreenAutomaticallyOnNewTab).thenReturn(mockDuckAiFeatureStateInputScreenOpenAutomaticallyFlow)
698+
whenever(mockDuckAiFeatureState.showFullScreenMode).thenReturn(mockDuckAiFeatureStateFullScreenModeFlow)
695699
whenever(mockExternalIntentProcessingState.hasPendingTabLaunch).thenReturn(mockHasPendingTabLaunchFlow)
696700
whenever(mockExternalIntentProcessingState.hasPendingDuckAiOpen).thenReturn(mockHasPendingDuckAiOpenFlow)
697701
whenever(mockVpnMenuStateProvider.getVpnMenuState()).thenReturn(flowOf(VpnMenuState.Hidden))
@@ -765,6 +769,8 @@ class BrowserTabViewModelTest {
765769

766770
fakeContentScopeScriptsSubscriptionEventPluginPoint = FakeContentScopeScriptsSubscriptionEventPluginPoint()
767771

772+
whenever(mockDuckChat.getDuckChatUrl(any(), any())).thenReturn(duckChatURL)
773+
768774
testee =
769775
BrowserTabViewModel(
770776
statisticsUpdater = mockStatisticsUpdater,
@@ -6341,6 +6347,22 @@ class BrowserTabViewModelTest {
63416347
verify(mockDuckChat).openDuckChat()
63426348
}
63436349

6350+
@Test
6351+
fun whenDuckChatMenuItemClickedAndFullScreenModeThenDontOpenDuckChatScreen() =
6352+
runTest {
6353+
mockDuckAiFeatureStateFullScreenModeFlow.emit(true)
6354+
whenever(mockDuckChat.wasOpenedBefore()).thenReturn(false)
6355+
whenever(mockOmnibarConverter.convertQueryToUrl(duckChatURL, null)).thenReturn(duckChatURL)
6356+
6357+
testee.onDuckChatMenuClicked()
6358+
6359+
verify(mockCommandObserver, atLeastOnce()).onChanged(commandCaptor.capture())
6360+
6361+
assertTrue(commandCaptor.lastValue is Navigate)
6362+
6363+
verify(mockDuckChat, never()).openDuckChat()
6364+
}
6365+
63446366
@Test
63456367
fun whenDuckChatMenuItemClickedAndItWasUsedBeforeThenOpenDuckChatAndSendPixel() =
63466368
runTest {

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4476,7 +4476,6 @@ class BrowserTabViewModel @Inject constructor(
44764476

44774477
if (duckAiFeatureState.showFullScreenMode.value) {
44784478
val url = duckChat.getDuckChatUrl("", false)
4479-
pageRefreshed(url)
44804479
onUserSubmittedQuery(url)
44814480
} else {
44824481
duckChat.openDuckChat()

0 commit comments

Comments
 (0)