Skip to content

Commit

Permalink
code review
Browse files Browse the repository at this point in the history
  • Loading branch information
nshuba committed Jan 17, 2025
1 parent 8a8fcc1 commit 62b4990
Show file tree
Hide file tree
Showing 5 changed files with 77 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -777,6 +777,22 @@ class BrowserTabViewModelTest {
}
}

@Test
fun whenViewBecomesVisibleAndDuckChatDisabledThenDuckChatNotVisible() {
whenever(mockDuckChat.showInBrowserMenu()).thenReturn(false)

testee.onViewVisible()
assertFalse(browserViewState().showDuckChatOption)
}

@Test
fun whenViewBecomesVisibleAndDuckChatEnabledThenDuckChatIsVisible() {
whenever(mockDuckChat.showInBrowserMenu()).thenReturn(true)

testee.onViewVisible()
assertTrue(browserViewState().showDuckChatOption)
}

@Test
fun whenInvalidatedGlobalLayoutRestoredThenErrorIsShown() {
givenInvalidatedGlobalLayout()
Expand Down Expand Up @@ -5240,6 +5256,8 @@ class BrowserTabViewModelTest {
assertFalse(testee.isPrinting())
}

// TODO:

@Test
fun whenOnFavoriteAddedThePixelFired() {
testee.onFavoriteAdded()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,6 @@ import com.duckduckgo.common.ui.view.show
import com.duckduckgo.common.utils.DispatcherProvider
import com.duckduckgo.di.scopes.ActivityScope
import com.duckduckgo.duckchat.api.DuckChat
import com.duckduckgo.navigation.api.GlobalActivityStarter
import com.google.android.material.snackbar.BaseTransientBottomBar
import com.google.android.material.snackbar.Snackbar
import javax.inject.Inject
Expand Down Expand Up @@ -115,9 +114,6 @@ class TabSwitcherActivity : DuckDuckGoActivity(), TabSwitcherListener, Coroutine
@Inject
lateinit var appBuildConfig: AppBuildConfig

@Inject
lateinit var globalActivityStarter: GlobalActivityStarter

@Inject
lateinit var duckChat: DuckChat

Expand Down
2 changes: 1 addition & 1 deletion app/src/main/res/layout/content_settings_new_other.xml
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
android:id="@+id/shareFeedbackSetting"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:primaryText="@string/sendFeedback"
app:primaryText="@string/leaveFeedback"
app:leadingIcon="@drawable/ic_heart_gray_color_24" />

<com.duckduckgo.common.ui.view.listitem.OneLineListItem
Expand Down
3 changes: 1 addition & 2 deletions app/src/main/res/values/donottranslate.xml
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,5 @@
<!-- DuckChat -->
<string name="duckChatTitle">Duck.ai</string>
<string name="duckChatMenuItem">New AI Chat</string>
<!-- Feedback -> translate along with DuckChat -->
<string name="sendFeedback">Send Feedback</string>

</resources>
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
/*
* Copyright (c) 2025 DuckDuckGo
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package com.duckduckgo.duckchat.impl

import kotlinx.coroutines.flow.flowOf
import kotlinx.coroutines.flow.take
import kotlinx.coroutines.flow.toList
import kotlinx.coroutines.test.runTest
import org.junit.Assert.assertFalse
import org.junit.Assert.assertTrue
import org.junit.Test
import org.mockito.Mockito.mock
import org.mockito.kotlin.verify
import org.mockito.kotlin.whenever

class DuckChatFeatureRepositoryTest {
private val mockDatabase: DuckChatDataStore = mock()

private val testee = RealDuckChatFeatureRepository(mockDatabase)

@Test
fun whenSetShowInBrowserMenuThenSetInDatabase() = runTest {
testee.setShowInBrowserMenu(true)

verify(mockDatabase).setShowInBrowserMenu(true)
}

@Test
fun whenObserveShowInBrowserMenuThenObserveDatabase() = runTest {
whenever(mockDatabase.observeShowInBrowserMenu()).thenReturn(flowOf(true, false))

val results = testee.observeShowInBrowserMenu().take(2).toList()
assertTrue(results[0])
assertFalse(results[1])
}

@Test
fun whenShouldShowInBrowserMenuThenGetFromDatabase() {
whenever(mockDatabase.getShowInBrowserMenu()).thenReturn(true)

assertTrue(testee.shouldShowInBrowserMenu())
}
}

0 comments on commit 62b4990

Please sign in to comment.