16
16
17
17
package com.duckduckgo.duckchat.impl.inputscreen.ui
18
18
19
+ import android.content.Context
19
20
import android.content.Intent
21
+ import android.content.res.Configuration
22
+ import android.content.res.Resources
20
23
import androidx.test.ext.junit.runners.AndroidJUnit4
21
24
import com.duckduckgo.duckchat.api.inputscreen.InputScreenActivityParams
22
25
import com.duckduckgo.duckchat.impl.DuckChatInternal
@@ -33,13 +36,19 @@ import org.mockito.kotlin.whenever
33
36
class InputScreenConfigResolverTest {
34
37
private val duckChatInternal: DuckChatInternal = mock()
35
38
private val inputScreenBottomBarEnabled = MutableStateFlow (false )
39
+ private val mockActivityContext: Context = mock()
40
+ private val mockResources: Resources = mock()
41
+ private val configuration = Configuration ()
36
42
37
43
private lateinit var inputScreenConfigResolver: InputScreenConfigResolverImpl
38
44
39
45
@Before
40
46
fun setup () {
41
47
whenever(duckChatInternal.inputScreenBottomBarEnabled).thenReturn(inputScreenBottomBarEnabled)
42
- inputScreenConfigResolver = InputScreenConfigResolverImpl (duckChatInternal)
48
+ whenever(mockActivityContext.resources).thenReturn(mockResources)
49
+ whenever(mockResources.configuration).thenReturn(configuration)
50
+ configuration.orientation = Configuration .ORIENTATION_PORTRAIT
51
+ inputScreenConfigResolver = InputScreenConfigResolverImpl (duckChatInternal, mockActivityContext)
43
52
}
44
53
45
54
@Test
@@ -118,4 +127,68 @@ class InputScreenConfigResolverTest {
118
127
119
128
assertFalse(inputScreenConfigResolver.useTopBar())
120
129
}
130
+
131
+ @Test
132
+ fun `when landscape and isTopOmnibar true and bottom bar enabled then useTopBar returns true` () {
133
+ configuration.orientation = Configuration .ORIENTATION_LANDSCAPE
134
+
135
+ val intent = Intent ().apply {
136
+ putExtra(
137
+ " ACTIVITY_SERIALIZABLE_PARAMETERS_ARG" ,
138
+ InputScreenActivityParams (query = " " , isTopOmnibar = true ),
139
+ )
140
+ }
141
+ inputScreenConfigResolver.onInputScreenCreated(intent)
142
+ inputScreenBottomBarEnabled.value = true
143
+
144
+ assertTrue(inputScreenConfigResolver.useTopBar())
145
+ }
146
+
147
+ @Test
148
+ fun `when landscape and isTopOmnibar true and bottom bar disabled then useTopBar returns true` () {
149
+ configuration.orientation = Configuration .ORIENTATION_LANDSCAPE
150
+
151
+ val intent = Intent ().apply {
152
+ putExtra(
153
+ " ACTIVITY_SERIALIZABLE_PARAMETERS_ARG" ,
154
+ InputScreenActivityParams (query = " " , isTopOmnibar = true ),
155
+ )
156
+ }
157
+ inputScreenConfigResolver.onInputScreenCreated(intent)
158
+ inputScreenBottomBarEnabled.value = false
159
+
160
+ assertTrue(inputScreenConfigResolver.useTopBar())
161
+ }
162
+
163
+ @Test
164
+ fun `when landscape and isTopOmnibar false and bottom bar enabled then useTopBar returns true` () {
165
+ configuration.orientation = Configuration .ORIENTATION_LANDSCAPE
166
+
167
+ val intent = Intent ().apply {
168
+ putExtra(
169
+ " ACTIVITY_SERIALIZABLE_PARAMETERS_ARG" ,
170
+ InputScreenActivityParams (query = " " , isTopOmnibar = false ),
171
+ )
172
+ }
173
+ inputScreenConfigResolver.onInputScreenCreated(intent)
174
+ inputScreenBottomBarEnabled.value = true
175
+
176
+ assertTrue(inputScreenConfigResolver.useTopBar())
177
+ }
178
+
179
+ @Test
180
+ fun `when landscape and isTopOmnibar false and bottom bar disabled then useTopBar returns true` () {
181
+ configuration.orientation = Configuration .ORIENTATION_LANDSCAPE
182
+
183
+ val intent = Intent ().apply {
184
+ putExtra(
185
+ " ACTIVITY_SERIALIZABLE_PARAMETERS_ARG" ,
186
+ InputScreenActivityParams (query = " " , isTopOmnibar = false ),
187
+ )
188
+ }
189
+ inputScreenConfigResolver.onInputScreenCreated(intent)
190
+ inputScreenBottomBarEnabled.value = false
191
+
192
+ assertTrue(inputScreenConfigResolver.useTopBar())
193
+ }
121
194
}
0 commit comments