Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -509,7 +509,8 @@ class BrowserViewModel @Inject constructor(
) {
val duckAiFullScreenMode = duckAiFeatureState.showFullScreenMode.value
logcat(INFO) { "Duck.ai openDuckChat duckChatSessionActive $duckChatSessionActive" }
sendCommand(OpenDuckChat(duckChatUrl, duckChatSessionActive, withTransition, tabs.value.size, duckAiFullScreenMode))
val tabsCount = tabs.value?.size ?: 0
sendCommand(OpenDuckChat(duckChatUrl, duckChatSessionActive, withTransition, tabsCount, duckAiFullScreenMode))
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -612,6 +612,39 @@ class BrowserViewModelTest {
}
}

@Test
fun `when openDuckChat called and tabs are null then command is sent with 0 tabs`() = runTest {
doReturn(MutableLiveData(null)).whenever(mockTabRepository).liveTabs
initTestee()

testee.openDuckChat(duckChatUrl = "duck://chat", duckChatSessionActive = false, withTransition = false)

testee.commands.test {
val command = awaitItem()
assertTrue(command is Command.OpenDuckChat)
command as Command.OpenDuckChat
assertEquals(0, command.tabs)
cancelAndIgnoreRemainingEvents()
}
}

@Test
fun `when openDuckChat called then command is sent with correct tab count`() = runTest {
val tabs = listOf(TabEntity("1", "", "", position = 0))
doReturn(MutableLiveData(tabs)).whenever(mockTabRepository).liveTabs
initTestee()

testee.openDuckChat(duckChatUrl = "duck://chat", duckChatSessionActive = false, withTransition = false)

testee.commands.test {
val command = awaitItem()
assertTrue(command is Command.OpenDuckChat)
command as Command.OpenDuckChat
assertEquals(tabs.size, command.tabs)
cancelAndIgnoreRemainingEvents()
}
}

private fun initTestee() {
testee = BrowserViewModel(
tabRepository = mockTabRepository,
Expand Down
Loading