Skip to content

Commit

Permalink
fixup! Implement Entry Widget for ongoing engagement cases
Browse files Browse the repository at this point in the history
  • Loading branch information
andrews-moc committed Dec 18, 2024
1 parent 0caf7ca commit b367328
Show file tree
Hide file tree
Showing 3 changed files with 78 additions and 36 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.glia.widgets.core.secureconversations.domain

import com.glia.widgets.chat.domain.IsAuthenticatedUseCase
import com.glia.widgets.core.secureconversations.SecureConversationsRepository
import com.glia.widgets.engagement.State
import com.glia.widgets.engagement.domain.EngagementStateUseCase
Expand All @@ -20,14 +21,16 @@ class HasOngoingSecureConversationUseCaseTest {
private lateinit var repository: SecureConversationsRepository
private lateinit var useCase: HasOngoingSecureConversationUseCase
private lateinit var engagementStateUseCase: EngagementStateUseCase
private lateinit var isAuthenticatedUseCase: IsAuthenticatedUseCase

@Before
fun setUp() {
RxJavaPlugins.setIoSchedulerHandler { Schedulers.trampoline() }
RxAndroidPlugins.setInitMainThreadSchedulerHandler { Schedulers.trampoline() }
repository = mockk()
engagementStateUseCase = mockk()
useCase = HasOngoingSecureConversationUseCase(repository, engagementStateUseCase)
isAuthenticatedUseCase = mockk()
useCase = HasOngoingSecureConversationUseCase(repository, isAuthenticatedUseCase, engagementStateUseCase)
}

@After
Expand All @@ -40,6 +43,7 @@ class HasOngoingSecureConversationUseCaseTest {
every { repository.pendingSecureConversationsStatusObservable } returns Flowable.just(pendingSC)
every { repository.unreadMessagesCountObservable } returns Flowable.just(unreadMessagesCount)
every { engagementStateUseCase() } returns Flowable.just(if (transferredSC) State.TransferredToSecureConversation else State.NoEngagement)
every { isAuthenticatedUseCase() } returns true
}

@Test
Expand Down Expand Up @@ -93,6 +97,7 @@ class HasOngoingSecureConversationUseCaseTest {
every { repository.pendingSecureConversationsStatusObservable } returns pendingSC
every { repository.unreadMessagesCountObservable } returns Flowable.just(0)
every { engagementStateUseCase() } returns Flowable.just(State.NoEngagement)
every { isAuthenticatedUseCase() } returns true

useCase().test().assertValue(false)
val callback = mockk<(Boolean) -> Unit>()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -214,20 +214,23 @@ class EngagementDomainTest {
}

@Test
fun `EngagementTypeUseCase isCallVisualizerScreenSharing returns true when current engagement is call visualizer and has no media`() {
fun `EngagementTypeUseCase isCallVisualizerScreenSharing returns true when current engagement is call visualizer`() {
val isQueueingOrLiveEngagementUseCase: IsQueueingOrLiveEngagementUseCase = mockk(relaxUnitFun = true)
val isCurrentEngagementCallVisualizerUseCase: IsCurrentEngagementCallVisualizerUseCase = mockk(relaxUnitFun = true)
val screenSharingUseCase: ScreenSharingUseCase = mockk(relaxUnitFun = true)
val operatorMediaUseCase: OperatorMediaUseCase = mockk(relaxUnitFun = true)
val visitorMediaUseCase: VisitorMediaUseCase = mockk(relaxUnitFun = true)
val isOperatorPresentUseCase: IsOperatorPresentUseCase = mockk(relaxUnitFun = true)

every { isCurrentEngagementCallVisualizerUseCase() } returns true
every { visitorMediaUseCase.hasMedia } returns false
every { operatorMediaUseCase.hasMedia } returns false
every { screenSharingUseCase.isSharing } returns true

val useCase: EngagementTypeUseCase = EngagementTypeUseCaseImpl(
isQueueingOrLiveEngagementUseCase = isQueueingOrLiveEngagementUseCase,
isCurrentEngagementCallVisualizerUseCase = isCurrentEngagementCallVisualizerUseCase,
screenSharingUseCase = screenSharingUseCase,
operatorMediaUseCase = operatorMediaUseCase,
visitorMediaUseCase = visitorMediaUseCase,
isOperatorPresentUseCase = isOperatorPresentUseCase
Expand All @@ -237,32 +240,36 @@ class EngagementDomainTest {
}

@Test
fun `EngagementTypeUseCase isCallVisualizerScreenSharing returns false when engagement has media`() {
fun `EngagementTypeUseCase isCallVisualizerScreenSharing returns true even when engagement has media`() {
val isQueueingOrLiveEngagementUseCase: IsQueueingOrLiveEngagementUseCase = mockk(relaxUnitFun = true)
val isCurrentEngagementCallVisualizerUseCase: IsCurrentEngagementCallVisualizerUseCase = mockk(relaxUnitFun = true)
val screenSharingUseCase: ScreenSharingUseCase = mockk(relaxUnitFun = true)
val operatorMediaUseCase: OperatorMediaUseCase = mockk(relaxUnitFun = true)
val visitorMediaUseCase: VisitorMediaUseCase = mockk(relaxUnitFun = true)
val isOperatorPresentUseCase: IsOperatorPresentUseCase = mockk(relaxUnitFun = true)

every { isCurrentEngagementCallVisualizerUseCase() } returns true
every { visitorMediaUseCase.hasMedia } returns true
every { operatorMediaUseCase.hasMedia } returns false
every { operatorMediaUseCase.hasMedia } returns true
every { screenSharingUseCase.isSharing } returns true

val useCase: EngagementTypeUseCase = EngagementTypeUseCaseImpl(
isQueueingOrLiveEngagementUseCase = isQueueingOrLiveEngagementUseCase,
isCurrentEngagementCallVisualizerUseCase = isCurrentEngagementCallVisualizerUseCase,
screenSharingUseCase = screenSharingUseCase,
operatorMediaUseCase = operatorMediaUseCase,
visitorMediaUseCase = visitorMediaUseCase,
isOperatorPresentUseCase = isOperatorPresentUseCase
)

assertFalse(useCase.isCallVisualizerScreenSharing)
assertTrue(useCase.isCallVisualizerScreenSharing)
}

@Test
fun `EngagementTypeUseCase isChatEngagement returns true when engagement has no media, is not a cv and operator is present`() {
val isQueueingOrLiveEngagementUseCase: IsQueueingOrLiveEngagementUseCase = mockk(relaxUnitFun = true)
val isCurrentEngagementCallVisualizerUseCase: IsCurrentEngagementCallVisualizerUseCase = mockk(relaxUnitFun = true)
val screenSharingUseCase: ScreenSharingUseCase = mockk(relaxUnitFun = true)
val operatorMediaUseCase: OperatorMediaUseCase = mockk(relaxUnitFun = true)
val visitorMediaUseCase: VisitorMediaUseCase = mockk(relaxUnitFun = true)
val isOperatorPresentUseCase: IsOperatorPresentUseCase = mockk(relaxUnitFun = true)
Expand All @@ -276,6 +283,7 @@ class EngagementDomainTest {
val useCase: EngagementTypeUseCase = EngagementTypeUseCaseImpl(
isQueueingOrLiveEngagementUseCase = isQueueingOrLiveEngagementUseCase,
isCurrentEngagementCallVisualizerUseCase = isCurrentEngagementCallVisualizerUseCase,
screenSharingUseCase = screenSharingUseCase,
operatorMediaUseCase = operatorMediaUseCase,
visitorMediaUseCase = visitorMediaUseCase,
isOperatorPresentUseCase = isOperatorPresentUseCase
Expand All @@ -288,6 +296,7 @@ class EngagementDomainTest {
fun `EngagementTypeUseCase isMediaEngagement returns true when engagement has media and operator is present`() {
val isQueueingOrLiveEngagementUseCase: IsQueueingOrLiveEngagementUseCase = mockk(relaxUnitFun = true)
val isCurrentEngagementCallVisualizerUseCase: IsCurrentEngagementCallVisualizerUseCase = mockk(relaxUnitFun = true)
val screenSharingUseCase: ScreenSharingUseCase = mockk(relaxUnitFun = true)
val operatorMediaUseCase: OperatorMediaUseCase = mockk(relaxUnitFun = true)
val visitorMediaUseCase: VisitorMediaUseCase = mockk(relaxUnitFun = true)
val isOperatorPresentUseCase: IsOperatorPresentUseCase = mockk(relaxUnitFun = true)
Expand All @@ -300,6 +309,7 @@ class EngagementDomainTest {
val useCase: EngagementTypeUseCase = EngagementTypeUseCaseImpl(
isQueueingOrLiveEngagementUseCase = isQueueingOrLiveEngagementUseCase,
isCurrentEngagementCallVisualizerUseCase = isCurrentEngagementCallVisualizerUseCase,
screenSharingUseCase = screenSharingUseCase,
operatorMediaUseCase = operatorMediaUseCase,
visitorMediaUseCase = visitorMediaUseCase,
isOperatorPresentUseCase = isOperatorPresentUseCase
Expand Down Expand Up @@ -385,7 +395,7 @@ class EngagementDomainTest {
}

@Test
fun `OperatorMediaUseCase invoke will emit data only when data is present`() {
fun `OperatorMediaUseCase invoke will emit empty media state even when data is absent`() {
val video = mockk<Video>(relaxUnitFun = true)

val mediaState = mockk<MediaState>(relaxUnitFun = true) {
Expand All @@ -406,13 +416,12 @@ class EngagementDomainTest {

verify { engagementRepository.operatorMediaState }

mediaStateFlow.test().assertNoValues()
assertFalse(operatorMediaUseCase.hasMedia)

mediaStateSubject.onNext(Data.Empty)
mediaStateSubject.onNext(Data.Empty)
mediaStateSubject.onNext(Data.Empty)

mediaStateFlow.test().assertNoValues()
assertFalse(operatorMediaUseCase.hasMedia)

mediaStateSubject.onNext(Data.Value(mediaState))
Expand All @@ -426,7 +435,7 @@ class EngagementDomainTest {
}

@Test
fun `VisitorMediaUseCase invoke will emit data only when data is present`() {
fun `VisitorMediaUseCase invoke will emit empty media state even when data is absent`() {
val video = mockk<Video>(relaxUnitFun = true)

val mediaState = mockk<MediaState>(relaxUnitFun = true) {
Expand All @@ -448,13 +457,12 @@ class EngagementDomainTest {

verify { engagementRepository.visitorMediaState }

mediaStateFlow.test().assertNoValues()
assertFalse(visitorMediaUseCase.hasMedia)

mediaStateSubject.onNext(Data.Empty)
mediaStateSubject.onNext(Data.Empty)
mediaStateSubject.onNext(Data.Empty)

mediaStateFlow.test().assertNoValues()
assertFalse(visitorMediaUseCase.hasMedia)

mediaStateSubject.onNext(Data.Value(mediaState))
Expand Down
Loading

0 comments on commit b367328

Please sign in to comment.