Skip to content

Commit

Permalink
Call minimize() before GVA deeplink is opened
Browse files Browse the repository at this point in the history
In case when `urlTarget` is `self` we need to minimize Glia UI and then open the link, if  `urlTarget` is `modal` - just open the link.

MOB-3201

(cherry picked from commit ea759f5)
  • Loading branch information
Egor Egorov authored and EgorovEI committed Mar 25, 2024
1 parent 56f1367 commit d9d0ae6
Show file tree
Hide file tree
Showing 9 changed files with 107 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -63,13 +63,17 @@ private extension SecureConversations.TranscriptModel {
openUrl(url)

default:
if urlTarget == .gvaOptionUrlTargetModal ||
urlTarget == .gvaOptionUrlTargetSelf {
// if GvaOption.urlTarget is "modal" or "self", then button url is deeplink
// and should be opened by UIApplication, to provide integrator
// an ability to handle deeplinks they configured.
// if GvaOption.urlTarget is "modal" or "self", then button url is deeplink
// and should be opened by UIApplication, to provide integrator
// an ability to handle deeplinks they configured.
switch urlTarget {
case String.gvaOptionUrlTargetSelf:
// In case of urlTarget "self" we need to minimize Glia UI
self.delegate?(.minimize)
openUrl(url)
} else {
case String.gvaOptionUrlTargetModal:
openUrl(url)
default:
return
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ extension SecureConversations {
case takeMedia(ObservableValue<MediaPickerEvent>)
case pickFile(ObservableValue<FilePickerEvent>)
case upgradeToChatEngagement(TranscriptModel)
case minimize
}

typealias Event = ChatViewModel.Event
Expand Down
5 changes: 5 additions & 0 deletions GliaWidgets/Sources/Coordinators/Chat/ChatCoordinator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ class ChatCoordinator: SubFlowCoordinator, FlowCoordinator {
)
case call
case finished
case minimize
}

var delegate: ((DelegateEvent) -> Void)?
Expand Down Expand Up @@ -207,6 +208,8 @@ extension ChatCoordinator {
self?.presentQuickLookController(with: file)
case .call:
self?.delegate?(.call)
case .minimize:
self?.delegate?(.minimize)
}
}

Expand Down Expand Up @@ -317,6 +320,8 @@ extension ChatCoordinator {
controller.swapAndBindViewModel(.chat(chatModel))
chatModel.migrate(from: transcriptModel)
self.delegate?(.secureTranscriptUpgradedToLiveChat(controller))
case .minimize:
self?.delegate?(.minimize)
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -336,6 +336,8 @@ extension EngagementCoordinator {
case .finished:
popCoordinator()
self.end()
case .minimize:
minimize()
}
}

Expand Down
16 changes: 10 additions & 6 deletions GliaWidgets/Sources/ViewModel/Chat/ChatViewModel+GVA.swift
Original file line number Diff line number Diff line change
Expand Up @@ -86,13 +86,17 @@ private extension ChatViewModel {
openUrl(url)

default:
if urlTarget == .gvaOptionUrlTargetModal ||
urlTarget == .gvaOptionUrlTargetSelf {
// if GvaOption.urlTarget is "modal" or "self", then button url is deeplink
// and should be opened by UIApplication, to provide integrator
// an ability to handle deeplinks they configured.
// if GvaOption.urlTarget is "modal" or "self", then button url is deeplink
// and should be opened by UIApplication, to provide integrator
// an ability to handle deeplinks they configured.
switch urlTarget {
case String.gvaOptionUrlTargetSelf:
// In case of urlTarget "self" we need to minimize Glia UI
self.delegate?(.minimize)
openUrl(url)
} else {
case String.gvaOptionUrlTargetModal:
openUrl(url)
default:
return
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ extension ChatViewModel: ViewModel {
case secureTranscriptUpgradedToLiveChat(ChatViewController)
case showFile(LocalFile)
case call
case minimize
}

enum StartAction {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,45 @@
import XCTest

extension SecureConversationsTranscriptModelTests {
func test_gvaDeepLinkActionCallsMinimize() {
let option: GvaOption = .mock(url: "mock://mock.self", urlTarget: "self")
var calls: [Call] = []
let viewModel = createViewModel()
viewModel.delegate = { event in
switch event {
case .minimize:
calls.append(.minimize)

default:
XCTFail("createSendMessagePayload should not be called")
}
}
viewModel.environment.uiApplication.open = { _ in }

viewModel.gvaOptionAction(for: option)()

XCTAssertEqual(calls, [.minimize])
}

func test_gvaDeepLinkActionDoesNotCallMinimize() {
let option: GvaOption = .mock(url: "mock://mock.modal", urlTarget: "modal")
var calls: [Call] = []
let viewModel = createViewModel()
viewModel.delegate = { event in
switch event {
case .minimize:
calls.append(.minimize)

default:
XCTFail("createSendMessagePayload should not be called")
}
}
viewModel.environment.uiApplication.open = { _ in }

viewModel.gvaOptionAction(for: option)()
XCTAssertTrue(calls.isEmpty)
}

func test_gvaLinkButtonAction() {
let options: [GvaOption] = [
.mock(url: "http://mock.mock"),
Expand Down Expand Up @@ -138,6 +177,7 @@ private extension SecureConversationsTranscriptModelTests {
case openUrl(String?)
case sendOption(String?, String?)
case showAlert
case minimize
}

func createViewModel() -> TranscriptModel {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,43 @@
import XCTest

extension ChatViewModelTests {
func test_gvaDeepLinkActionCallsMinimize() {
let option: GvaOption = .mock(url: "mock://mock.self", urlTarget: "self")
var calls: [Call] = []
viewModel = .mock()
viewModel.delegate = { event in
switch event {
case .minimize:
calls.append(.minimize)

default:
XCTFail("createSendMessagePayload should not be called")
}
}

viewModel.gvaOptionAction(for: option)()

XCTAssertEqual(calls, [.minimize])
}

func test_gvaDeepLinkActionDoesNotCallMinimize() {
let option: GvaOption = .mock(url: "mock://mock.modal", urlTarget: "modal")
var calls: [Call] = []
viewModel = .mock()
viewModel.delegate = { event in
switch event {
case .minimize:
calls.append(.minimize)

default:
XCTFail("createSendMessagePayload should not be called")
}
}

viewModel.gvaOptionAction(for: option)()
XCTAssertTrue(calls.isEmpty)
}

func test_gvaLinkButtonAction() {
let options: [GvaOption] = [
.mock(url: "http://mock.mock"),
Expand Down Expand Up @@ -162,5 +199,6 @@ private extension ChatViewModelTests {
case openUrl(String?)
case sendOption(String?, String?)
case showAlert
case minimize
}
}
1 change: 0 additions & 1 deletion TestingApp/DeeplinkService/SettingsDeeplinkHandler.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ struct SettingsDeeplinkHandler: DeeplinkHandler {
let root = window?.rootViewController as? ViewController else {
return false
}
Glia.sharedInstance.minimize()
root.presentSettings()
return true
}
Expand Down

0 comments on commit d9d0ae6

Please sign in to comment.