Skip to content

Commit 28fa140

Browse files
committed
Duck.ai: Provide default value for tabs (#7129)
Task/Issue URL: https://app.asana.com/1/137249556945/project/1157893581871903/task/1211962674281407?focus=true ### Description This PR fixes the access to the tabs when null ### Steps to test this PR _Third party open_ - [x] Install the app and make it default browser - [x] Enable Duck.ai and force close the app - [x] Open DDG via a third party app (Reddit for example) - [x] Verify it works as expected
1 parent 4cc3afb commit 28fa140

File tree

2 files changed

+35
-1
lines changed

2 files changed

+35
-1
lines changed

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -509,7 +509,8 @@ class BrowserViewModel @Inject constructor(
509509
) {
510510
val duckAiFullScreenMode = duckAiFeatureState.showFullScreenMode.value
511511
logcat(INFO) { "Duck.ai openDuckChat duckChatSessionActive $duckChatSessionActive" }
512-
sendCommand(OpenDuckChat(duckChatUrl, duckChatSessionActive, withTransition, tabs.value.size, duckAiFullScreenMode))
512+
val tabsCount = tabs.value?.size ?: 0
513+
sendCommand(OpenDuckChat(duckChatUrl, duckChatSessionActive, withTransition, tabsCount, duckAiFullScreenMode))
513514
}
514515
}
515516

app/src/test/java/com/duckduckgo/app/browser/BrowserViewModelTest.kt

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -612,6 +612,39 @@ class BrowserViewModelTest {
612612
}
613613
}
614614

615+
@Test
616+
fun `when openDuckChat called and tabs are null then command is sent with 0 tabs`() = runTest {
617+
doReturn(MutableLiveData(null)).whenever(mockTabRepository).liveTabs
618+
initTestee()
619+
620+
testee.openDuckChat(duckChatUrl = "duck://chat", duckChatSessionActive = false, withTransition = false)
621+
622+
testee.commands.test {
623+
val command = awaitItem()
624+
assertTrue(command is Command.OpenDuckChat)
625+
command as Command.OpenDuckChat
626+
assertEquals(0, command.tabs)
627+
cancelAndIgnoreRemainingEvents()
628+
}
629+
}
630+
631+
@Test
632+
fun `when openDuckChat called then command is sent with correct tab count`() = runTest {
633+
val tabs = listOf(TabEntity("1", "", "", position = 0))
634+
doReturn(MutableLiveData(tabs)).whenever(mockTabRepository).liveTabs
635+
initTestee()
636+
637+
testee.openDuckChat(duckChatUrl = "duck://chat", duckChatSessionActive = false, withTransition = false)
638+
639+
testee.commands.test {
640+
val command = awaitItem()
641+
assertTrue(command is Command.OpenDuckChat)
642+
command as Command.OpenDuckChat
643+
assertEquals(tabs.size, command.tabs)
644+
cancelAndIgnoreRemainingEvents()
645+
}
646+
}
647+
615648
private fun initTestee() {
616649
testee = BrowserViewModel(
617650
tabRepository = mockTabRepository,

0 commit comments

Comments
 (0)