Skip to content

Commit

Permalink
Fix hiding of text input for Secure Transcript flow
Browse files Browse the repository at this point in the history
Fix hiding of text input for Secure Transcript flow when Secure Message Center is unavailable.

MOB-2734
  • Loading branch information
igorkravchenko committed Oct 12, 2023
1 parent 133357a commit aa139c4
Show file tree
Hide file tree
Showing 4 changed files with 148 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,11 @@ extension SecureConversations {
var availability: Availability
var interactor: Interactor

private (set) var isSecureConversationsAvailable: Bool = true
private (set) var isSecureConversationsAvailable: Bool = true {
didSet {
action?(.transcript(.messageCenterAvailabilityUpdated))
}
}

var siteConfiguration: CoreSdkClient.Site?

Expand Down Expand Up @@ -175,6 +179,7 @@ extension SecureConversations {
let configuration = self.environment.alertConfiguration.unavailableMessageCenter
self.reportMessageCenterUnavailable(configuration: configuration)
case .success(.unavailable(.unauthenticated)):
self.isSecureConversationsAvailable = false
let configuration = self.environment.alertConfiguration.unavailableMessageCenterForBeingUnauthenticated
self.reportMessageCenterUnavailable(configuration: configuration)
}
Expand Down Expand Up @@ -746,3 +751,12 @@ extension SecureConversations.TranscriptModel {

}
}

#if DEBUG
extension SecureConversations.TranscriptModel {
/// Setter for `isSecureConversationsAvailable`. Used in unit tests.
func setIsSecureConversationsAvailable(_ available: Bool) {
self.isSecureConversationsAvailable = available
}
}
#endif
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,8 @@ final class ChatViewController: EngagementViewController, PopoverPresenter {
view?.messageEntryView.uploadListView.props = fileUploadListProps
case let .quickReplyPropsUpdated(props):
view?.renderQuickReply(props: props)
case .transcript(.messageCenterAvailabilityUpdated):
break
}
self?.renderProps()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@ extension ChatViewModel: ViewModel {
}

enum Action {
/// Actions specific for `TranscriptModel`.
enum TranscriptAction {
case messageCenterAvailabilityUpdated
}
case queue
case connected(name: String?, imageUrl: String?)
case transferring
Expand Down Expand Up @@ -55,6 +59,7 @@ extension ChatViewModel: ViewModel {
case setAttachmentButtonVisibility(MediaPickerButtonVisibility)
case fileUploadListPropsUpdated(SecureConversations.FileUploadListView.Props)
case quickReplyPropsUpdated(QuickReplyView.Props)
case transcript(TranscriptAction)
}

enum DelegateEvent {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,6 @@ final class SecureConversationsTranscriptModelTests: XCTestCase {
XCTAssertTrue(viewModel.validateMessage())
}


func testSendMessageUsesSecureEndpoint() {
var modelEnv = TranscriptModel.Environment.failing
let fileUploadListModel = FileUploadListViewModel.mock()
Expand Down Expand Up @@ -379,7 +378,7 @@ final class SecureConversationsTranscriptModelTests: XCTestCase {
callback(.success(1))
}
modelEnv.startSocketObservation = {}
modelEnv.gcd.mainQueue.asyncAfterDeadline = { _, callback in }
modelEnv.gcd.mainQueue.asyncAfterDeadline = { _, _ in }
modelEnv.loadChatMessagesFromHistory = { true }
let scheduler = CoreSdkClient.ReactiveSwift.TestScheduler()
modelEnv.messagesWithUnreadCountLoaderScheduler = scheduler
Expand Down Expand Up @@ -451,7 +450,7 @@ final class SecureConversationsTranscriptModelTests: XCTestCase {
alertConfiguration: .mock()
)

modelEnv.fetchChatHistory = { callback in
modelEnv.fetchChatHistory = { _ in
let uuid = UUID.mock.uuidString
let message = CoreSdkClient.Message(
id: uuid,
Expand Down Expand Up @@ -491,7 +490,7 @@ final class SecureConversationsTranscriptModelTests: XCTestCase {
callback(.success(0))
}
modelEnv.startSocketObservation = {}
modelEnv.gcd.mainQueue.asyncAfterDeadline = { _, callback in }
modelEnv.gcd.mainQueue.asyncAfterDeadline = { _, _ in }
modelEnv.loadChatMessagesFromHistory = { true }
let scheduler = CoreSdkClient.ReactiveSwift.TestScheduler()
modelEnv.messagesWithUnreadCountLoaderScheduler = scheduler
Expand All @@ -515,7 +514,7 @@ final class SecureConversationsTranscriptModelTests: XCTestCase {
alertConfiguration: .mock()
)

modelEnv.fetchChatHistory = { callback in
modelEnv.fetchChatHistory = { _ in
let uuid = UUID.mock.uuidString
let message = CoreSdkClient.Message(
id: uuid,
Expand All @@ -541,4 +540,126 @@ final class SecureConversationsTranscriptModelTests: XCTestCase {
viewModel.start()
scheduler.run()
}

func testIsSecureConversationsAvailableIsFalseIsDueToEmptyQueue() {
var modelEnvironment = TranscriptModel.Environment.failing
modelEnvironment.fileManager = .mock
modelEnvironment.createFileUploadListModel = {
.mock(environment: $0)
}
var availabilityEnv = SecureConversations.Availability.Environment.failing
availabilityEnv.listQueues = { callback in
callback([], nil)
}
availabilityEnv.isAuthenticated = { true }
let model = TranscriptModel(
isCustomCardSupported: false,
environment: modelEnvironment,
availability: .init(environment: availabilityEnv),
deliveredStatusText: "",
interactor: .failing,
alertConfiguration: .mock()
)
XCTAssertFalse(model.isSecureConversationsAvailable)
}

func testIsSecureConversationsAvailableIsFalseDueToUnauthenticated() {
var modelEnvironment = TranscriptModel.Environment.failing
modelEnvironment.fileManager = .mock
modelEnvironment.createFileUploadListModel = {
.mock(environment: $0)
}
var availabilityEnv = SecureConversations.Availability.Environment.failing
availabilityEnv.listQueues = { callback in
callback([.mock()], nil)
}
availabilityEnv.isAuthenticated = { false }
let model = TranscriptModel(
isCustomCardSupported: false,
environment: modelEnvironment,
availability: .init(environment: availabilityEnv),
deliveredStatusText: "",
interactor: .failing,
alertConfiguration: .mock()
)
XCTAssertFalse(model.isSecureConversationsAvailable)
}

func testIsSecureConversationsAvailableIsFalseDueToListQueuesError() {
var modelEnvironment = TranscriptModel.Environment.failing
modelEnvironment.fileManager = .mock
modelEnvironment.createFileUploadListModel = {
.mock(environment: $0)
}
var availabilityEnv = SecureConversations.Availability.Environment.failing
availabilityEnv.listQueues = { callback in
callback(nil, .mock())
}
availabilityEnv.isAuthenticated = { false }
let model = TranscriptModel(
isCustomCardSupported: false,
environment: modelEnvironment,
availability: .init(environment: availabilityEnv),
deliveredStatusText: "",
interactor: .failing,
alertConfiguration: .mock()
)
XCTAssertFalse(model.isSecureConversationsAvailable)
}

func testIsSecureConversationsAvailableIsTrue() {
var modelEnvironment = TranscriptModel.Environment.failing
modelEnvironment.fileManager = .mock
modelEnvironment.createFileUploadListModel = {
.mock(environment: $0)
}
var availabilityEnv = SecureConversations.Availability.Environment.failing
availabilityEnv.listQueues = { callback in
callback([.mock()], nil)
}
availabilityEnv.isAuthenticated = { true }
let model = TranscriptModel(
isCustomCardSupported: false,
environment: modelEnvironment,
availability: .init(environment: availabilityEnv),
deliveredStatusText: "",
interactor: .failing,
alertConfiguration: .mock()
)
XCTAssertFalse(model.isSecureConversationsAvailable)
}

func testSetIsSecureConversationsAvailableCallsAction() throws {
var modelEnvironment = TranscriptModel.Environment.failing
modelEnvironment.fileManager = .mock
modelEnvironment.createFileUploadListModel = {
.mock(environment: $0)
}
var availabilityEnv = SecureConversations.Availability.Environment.failing
availabilityEnv.listQueues = { callback in
callback([.mock()], nil)
}
availabilityEnv.isAuthenticated = { true }
let model = TranscriptModel(
isCustomCardSupported: false,
environment: modelEnvironment,
availability: .init(environment: availabilityEnv),
deliveredStatusText: "",
interactor: .failing,
alertConfiguration: .mock()
)
var actions: [TranscriptModel.Action] = []
model.action = {
actions.append($0)
}
model.setIsSecureConversationsAvailable(true)
XCTAssertEqual(actions.count, 1)
let receivedAction = try XCTUnwrap(actions.first)
switch receivedAction {
case .transcript(.messageCenterAvailabilityUpdated):
break
default:
XCTFail("Unexpected action: \(receivedAction)")
}
}
}

0 comments on commit aa139c4

Please sign in to comment.