@@ -60,6 +60,7 @@ import com.duckduckgo.app.cta.db.DismissedCtaDao
6060import com.duckduckgo.app.cta.model.CtaId
6161import com.duckduckgo.app.cta.model.DismissedCta
6262import com.duckduckgo.app.cta.ui.*
63+ import com.duckduckgo.app.email.EmailManager
6364import com.duckduckgo.app.fire.fireproofwebsite.data.FireproofWebsiteDao
6465import com.duckduckgo.app.fire.fireproofwebsite.data.FireproofWebsiteEntity
6566import com.duckduckgo.app.fire.fireproofwebsite.data.FireproofWebsiteRepository
@@ -113,9 +114,12 @@ import dagger.Lazy
113114import io.reactivex.Observable
114115import io.reactivex.Single
115116import kotlinx.coroutines.ExperimentalCoroutinesApi
117+ import kotlinx.coroutines.FlowPreview
116118import kotlinx.coroutines.channels.Channel
117119import kotlinx.coroutines.flow.MutableSharedFlow
120+ import kotlinx.coroutines.flow.MutableStateFlow
118121import kotlinx.coroutines.flow.asSharedFlow
122+ import kotlinx.coroutines.flow.asStateFlow
119123import kotlinx.coroutines.flow.consumeAsFlow
120124import kotlinx.coroutines.flow.flowOf
121125import kotlinx.coroutines.runBlocking
@@ -134,6 +138,7 @@ import java.io.File
134138import java.util.*
135139import java.util.concurrent.TimeUnit
136140
141+ @FlowPreview
137142@ExperimentalCoroutinesApi
138143class BrowserTabViewModelTest {
139144
@@ -237,6 +242,9 @@ class BrowserTabViewModelTest {
237242 @Mock
238243 private lateinit var fireproofDialogsEventHandler: FireproofDialogsEventHandler
239244
245+ @Mock
246+ private lateinit var mockEmailManager: EmailManager
247+
240248 private val lazyFaviconManager = Lazy { mockFaviconManager }
241249
242250 private lateinit var mockAutoCompleteApi: AutoCompleteApi
@@ -266,6 +274,8 @@ class BrowserTabViewModelTest {
266274
267275 private val childClosedTabsFlow = childClosedTabsSharedFlow.asSharedFlow()
268276
277+ private val emailStateFlow = MutableStateFlow (false )
278+
269279 @Before
270280 fun before () {
271281 MockitoAnnotations .openMocks(this )
@@ -280,6 +290,7 @@ class BrowserTabViewModelTest {
280290
281291 whenever(mockDismissedCtaDao.dismissedCtas()).thenReturn(dismissedCtaDaoChannel.consumeAsFlow())
282292 whenever(mockTabRepository.flowTabs).thenReturn(flowOf(emptyList()))
293+ whenever(mockEmailManager.signedInFlow()).thenReturn(emailStateFlow.asStateFlow())
283294
284295 ctaViewModel = CtaViewModel (
285296 mockAppInstallStore,
@@ -345,7 +356,8 @@ class BrowserTabViewModelTest {
345356 variantManager = mockVariantManager,
346357 fileDownloader = mockFileDownloader,
347358 globalPrivacyControl = GlobalPrivacyControlManager (mockSettingsStore),
348- fireproofDialogsEventHandler = fireproofDialogsEventHandler
359+ fireproofDialogsEventHandler = fireproofDialogsEventHandler,
360+ emailManager = mockEmailManager
349361 )
350362
351363 testee.loadData(" abc" , null , false )
@@ -3150,6 +3162,98 @@ class BrowserTabViewModelTest {
31503162 assertCommandNotIssued<Command .ChildTabClosed >()
31513163 }
31523164
3165+ @Test
3166+ fun whenConsumeAliasAndCopyToClipboardThenCopyAliasToClipboardCommandSent () {
3167+ whenever(mockEmailManager.getAlias()).thenReturn(" alias" )
3168+
3169+ testee.consumeAliasAndCopyToClipboard()
3170+
3171+ assertCommandIssued<Command .CopyAliasToClipboard >()
3172+ }
3173+
3174+ @Test
3175+ fun whenEmailIsSignedOutThenIsEmailSignedInReturnsFalse () = coroutineRule.runBlocking {
3176+ emailStateFlow.emit(false )
3177+
3178+ assertFalse(browserViewState().isEmailSignedIn)
3179+ }
3180+
3181+ @Test
3182+ fun whenEmailIsSignedInThenIsEmailSignedInReturnsTrue () = coroutineRule.runBlocking {
3183+ emailStateFlow.emit(true )
3184+
3185+ assertTrue(browserViewState().isEmailSignedIn)
3186+ }
3187+
3188+ @Test
3189+ fun whenConsumeAliasThenInjectAddressCommandSent () {
3190+ whenever(mockEmailManager.getAlias()).thenReturn(" alias" )
3191+
3192+ testee.consumeAlias()
3193+
3194+ assertCommandIssued<Command .InjectEmailAddress > {
3195+ assertEquals(" alias" , this .address)
3196+ }
3197+ }
3198+
3199+ @Test
3200+ fun whenConsumeAliasThenPixelSent () {
3201+ whenever(mockEmailManager.getAlias()).thenReturn(" alias" )
3202+
3203+ testee.consumeAlias()
3204+
3205+ verify(mockPixel).enqueueFire(AppPixelName .EMAIL_USE_ALIAS )
3206+ }
3207+
3208+ @Test
3209+ fun whenCancelAutofillTooltipThenPixelSent () {
3210+ whenever(mockEmailManager.getAlias()).thenReturn(" alias" )
3211+
3212+ testee.cancelAutofillTooltip()
3213+
3214+ verify(mockPixel).enqueueFire(AppPixelName .EMAIL_TOOLTIP_DISMISSED )
3215+ }
3216+
3217+ @Test
3218+ fun whenUseAddressThenInjectAddressCommandSent () {
3219+ whenever(mockEmailManager.getEmailAddress()).thenReturn(" address" )
3220+
3221+ testee.useAddress()
3222+
3223+ assertCommandIssued<Command .InjectEmailAddress > {
3224+ assertEquals(" address" , this .address)
3225+ }
3226+ }
3227+
3228+ @Test
3229+ fun whenUseAddressThenPixelSent () {
3230+ whenever(mockEmailManager.getEmailAddress()).thenReturn(" address" )
3231+
3232+ testee.useAddress()
3233+
3234+ verify(mockPixel).enqueueFire(AppPixelName .EMAIL_USE_ADDRESS )
3235+ }
3236+
3237+ @Test
3238+ fun whenShowEmailTooltipIfAddressExistsThenShowEmailTooltipCommandSent () {
3239+ whenever(mockEmailManager.getEmailAddress()).thenReturn(" address" )
3240+
3241+ testee.showEmailTooltip()
3242+
3243+ assertCommandIssued<Command .ShowEmailTooltip > {
3244+ assertEquals(" address" , this .address)
3245+ }
3246+ }
3247+
3248+ @Test
3249+ fun whenShowEmailTooltipIfAddressDoesNotExistThenCommandNotSent () {
3250+ whenever(mockEmailManager.getEmailAddress()).thenReturn(null )
3251+
3252+ testee.showEmailTooltip()
3253+
3254+ assertCommandNotIssued<Command .ShowEmailTooltip >()
3255+ }
3256+
31533257 private suspend fun givenFireButtonPulsing () {
31543258 whenever(mockUserStageStore.getUserAppStage()).thenReturn(AppStage .DAX_ONBOARDING )
31553259 dismissedCtaDaoChannel.send(listOf (DismissedCta (CtaId .DAX_DIALOG_TRACKERS_FOUND )))
0 commit comments