Skip to content

Commit

Permalink
Show LO confirmation alert based on toggle
Browse files Browse the repository at this point in the history
This PR will take into account the possibility of toggling out LO
confirmation alert, meaning that engagement can start without explicitly
allowing LO. The toggle is fetch from the site information

MOB-2707
  • Loading branch information
rasmustautsglia committed Nov 2, 2023
1 parent 0a74ef2 commit 09f58e3
Show file tree
Hide file tree
Showing 5 changed files with 82 additions and 24 deletions.
7 changes: 5 additions & 2 deletions GliaWidgets/Sources/CoreSDKClient/CoreSDKClient.Mock.swift
Original file line number Diff line number Diff line change
Expand Up @@ -426,13 +426,15 @@ extension CoreSdkClient.Site {
id: UUID = .mock,
allowedFileSenders: AllowedFileSenders.Mock = .mock,
maskingRegularExpressions: [String] = [],
visitorAppDefaultLocale: String = "en-US"
visitorAppDefaultLocale: String = "en-US",
mobileConfirmDialog: Bool = true
) throws -> Self {
struct Mock: Codable {
let id: UUID
let allowedFileSenders: CoreSdkClient.Site.AllowedFileSenders.Mock
let maskingRegularExpressions: [String]
let visitorAppDefaultLocale: String
let mobileConfirmDialog: Bool
}
return try JSONDecoder()
.decode(
Expand All @@ -443,7 +445,8 @@ extension CoreSdkClient.Site {
id: id,
allowedFileSenders: allowedFileSenders,
maskingRegularExpressions: maskingRegularExpressions,
visitorAppDefaultLocale: visitorAppDefaultLocale
visitorAppDefaultLocale: visitorAppDefaultLocale,
mobileConfirmDialog: mobileConfirmDialog
)
)
)
Expand Down
13 changes: 12 additions & 1 deletion GliaWidgets/Sources/ViewModel/EngagementViewModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,18 @@ class EngagementViewModel: CommonEngagementModel {
)
})
case let .enqueueing(mediaType):
showLiveObservationConfirmation(in: mediaType)
environment.fetchSiteConfigurations { result in
switch result {
case let .success(site):
if site.mobileConfirmDialog == false {
self.enqueue(mediaType: mediaType)
} else {
self.showLiveObservationConfirmation(in: mediaType)
}
case .failure:
self.showAlert(with: self.alertConfiguration.unexpectedError, dismissed: nil)
}
}
default:
break
}
Expand Down
42 changes: 32 additions & 10 deletions GliaWidgetsTests/Sources/CallViewModelTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -346,20 +346,30 @@ class CallViewModelTests: XCTestCase {
viewModel.start()

XCTAssertEqual(call.state.value, .none)
}
func test_viewModelStartDoesNotInitiateEnqueuingWithStartActionAsEngagement() {
let viewModel: CallViewModel = .mock()
viewModel.start()

XCTAssertEqual(viewModel.interactor.state, .none)
}

func test_liveObservationAlertPresentationInitiatedWhenInteractorStateIsEnqueuing() {
func test_liveObservationAlertPresentationInitiatedWhenInteractorStateIsEnqueuing() throws {
enum Call {
case showLiveObservationAlert
}
var calls: [Call] = []
let interactor: Interactor = .mock()
let viewModel: CallViewModel = .mock(interactor: interactor)
let site: CoreSdkClient.Site = try .mock()

var viewModelEnvironment: EngagementViewModel.Environment = .mock
viewModelEnvironment.fetchSiteConfigurations = { completion in
completion(.success(site))
}
let viewModel: ChatViewModel = .mock(
interactor: interactor,
environment: viewModelEnvironment
)
viewModel.engagementAction = { action in
switch action {
case .showLiveObservationConfirmation:
Expand All @@ -372,18 +382,24 @@ class CallViewModelTests: XCTestCase {
XCTAssertEqual(calls, [.showLiveObservationAlert])
}

func test_liveObservationAllowTriggersEnqueue() {
func test_liveObservationAllowTriggersEnqueue() throws {
var interactorEnv: Interactor.Environment = .mock
interactorEnv.coreSdk.queueForEngagement = { _, completion in
completion(.success(.mock))
}

let interactor: Interactor = .mock(environment: interactorEnv)
interactor.isConfigurationPerformed = true

var alertConfig: LiveObservation.Confirmation?
let site: CoreSdkClient.Site = try .mock()

let viewModel: CallViewModel = .mock(interactor: interactor)
var viewModelEnvironment: EngagementViewModel.Environment = .mock
viewModelEnvironment.fetchSiteConfigurations = { completion in
completion(.success(site))
}
let viewModel: ChatViewModel = .mock(
interactor: interactor,
environment: viewModelEnvironment
)
viewModel.engagementAction = { action in
switch action {
case let .showLiveObservationConfirmation(config):
Expand All @@ -397,7 +413,7 @@ class CallViewModelTests: XCTestCase {
XCTAssertEqual(interactor.state, .enqueued(.mock))
}

func test_liveObservationDeclineTriggersNone() {
func test_liveObservationDeclineTriggersNone() throws {
enum Call {
case queueForEngagement
}
Expand All @@ -408,11 +424,17 @@ class CallViewModelTests: XCTestCase {
}

let interactor: Interactor = .mock(environment: interactorEnv)
interactor.isConfigurationPerformed = true

var alertConfig: LiveObservation.Confirmation?
let site: CoreSdkClient.Site = try .mock()

let viewModel: CallViewModel = .mock(interactor: interactor)
var viewModelEnvironment: EngagementViewModel.Environment = .mock
viewModelEnvironment.fetchSiteConfigurations = { completion in
completion(.success(site))
}
let viewModel: ChatViewModel = .mock(
interactor: interactor,
environment: viewModelEnvironment
)
viewModel.engagementAction = { action in
switch action {
case let .showLiveObservationConfirmation(config):
Expand Down
41 changes: 31 additions & 10 deletions GliaWidgetsTests/Sources/ChatViewModel/ChatViewModelTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -703,13 +703,21 @@ class ChatViewModelTests: XCTestCase {
XCTAssertEqual(viewModel.receivedMessageIds, [])
}

func test_liveObservationAlertPresentationInitiatedWhenInteractorStateIsEnqueuing() {
func test_liveObservationAlertPresentationInitiatedWhenInteractorStateIsEnqueuing() throws {
enum Call {
case showLiveObservationAlert
}
var calls: [Call] = []
let interactor: Interactor = .mock()
let viewModel: ChatViewModel = .mock(interactor: interactor)
let site: CoreSdkClient.Site = try .mock()
var viewModelEnvironment: EngagementViewModel.Environment = .mock
viewModelEnvironment.fetchSiteConfigurations = { completion in
completion(.success(site))
}
let viewModel: ChatViewModel = .mock(
interactor: interactor,
environment: viewModelEnvironment
)
viewModel.engagementAction = { action in
switch action {
case .showLiveObservationConfirmation:
Expand All @@ -722,18 +730,25 @@ class ChatViewModelTests: XCTestCase {
XCTAssertEqual(calls, [.showLiveObservationAlert])
}

func test_liveObservationAllowTriggersEnqueue() {
func test_liveObservationAllowTriggersEnqueue() throws {
var interactorEnv: Interactor.Environment = .mock
interactorEnv.coreSdk.queueForEngagement = { _, completion in
completion(.success(.mock))
}

let interactor: Interactor = .mock(environment: interactorEnv)
interactor.isConfigurationPerformed = true

var alertConfig: LiveObservation.Confirmation?
let site: CoreSdkClient.Site = try .mock()

var viewModelEnvironment: EngagementViewModel.Environment = .mock
viewModelEnvironment.fetchSiteConfigurations = { completion in
completion(.success(site))
}
let viewModel: ChatViewModel = .mock(
interactor: interactor,
environment: viewModelEnvironment
)

let viewModel: ChatViewModel = .mock(interactor: interactor)
viewModel.engagementAction = { action in
switch action {
case let .showLiveObservationConfirmation(config):
Expand All @@ -747,7 +762,7 @@ class ChatViewModelTests: XCTestCase {
XCTAssertEqual(interactor.state, .enqueued(.mock))
}

func test_liveObservationDeclineTriggersNone() {
func test_liveObservationDeclineTriggersNone() throws {
enum Call {
case queueForEngagement
}
Expand All @@ -758,11 +773,17 @@ class ChatViewModelTests: XCTestCase {
}

let interactor: Interactor = .mock(environment: interactorEnv)
interactor.isConfigurationPerformed = true

var alertConfig: LiveObservation.Confirmation?
let site: CoreSdkClient.Site = try .mock()

let viewModel: ChatViewModel = .mock(interactor: interactor)
var viewModelEnvironment: EngagementViewModel.Environment = .mock
viewModelEnvironment.fetchSiteConfigurations = { completion in
completion(.success(site))
}
let viewModel: ChatViewModel = .mock(
interactor: interactor,
environment: viewModelEnvironment
)
viewModel.engagementAction = { action in
switch action {
case let .showLiveObservationConfirmation(config):
Expand Down
3 changes: 2 additions & 1 deletion GliaWidgetsTests/Sources/Glia/GliaTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ final class GliaTests: XCTestCase {
completion?()
}
gliaEnv.coreSDKConfigurator.configureWithInteractor = { _ in }

gliaEnv.coreSdk.fetchSiteConfigurations = { _ in }
gliaEnv.uuid = { .mock }
gliaEnv.gcd.mainQueue.asyncIfNeeded = { callback in callback() }

Expand Down Expand Up @@ -132,6 +132,7 @@ final class GliaTests: XCTestCase {
gliaEnv.coreSDKConfigurator.configureWithConfiguration = { _, completion in
completion?()
}
gliaEnv.callVisualizerPresenter = .init(presenter: { nil })
gliaEnv.coreSDKConfigurator.configureWithInteractor = { _ in }

let sdk = Glia(environment: gliaEnv)
Expand Down

0 comments on commit 09f58e3

Please sign in to comment.