-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add tests for Secure Conversations coordinator
Correct actions and creation of view controllers in the coordinator has been covered with unit tests. MOB-2914
- Loading branch information
1 parent
0f193c7
commit 223b1bf
Showing
7 changed files
with
324 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
53 changes: 53 additions & 0 deletions
53
...ts/SecureConversations/Coordinator/SecureConversations.Coordinator.Environment.Mock.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
import Foundation | ||
@testable import GliaWidgets | ||
|
||
extension SecureConversations.Coordinator.Environment { | ||
static let mock = Self( | ||
queueIds: [], | ||
listQueues: { completion in }, | ||
sendSecureMessagePayload: { secureMessagePayload, queueIds, completion in .mock }, | ||
createFileUploader: { maximumUploads, environment in .mock() }, | ||
uploadSecureFile: { file, progress, completion in .mock }, | ||
fileManager: .mock, | ||
data: .mock, | ||
date: { .mock }, | ||
gcd: .mock, | ||
createThumbnailGenerator: { .mock }, | ||
uuid: { .mock }, | ||
uiApplication: .mock, | ||
uiScreen: .mock, | ||
notificationCenter: .mock, | ||
createFileUploadListModel: { environment in .mock() }, | ||
viewFactory: .mock(), | ||
fetchFile: { engagementFile, progress, completion in }, | ||
createFileDownload: { file, storage, environment in .mock() }, | ||
loadChatMessagesFromHistory: { true }, | ||
fetchChatHistory: { completion in }, | ||
fetchSiteConfigurations: { completion in }, | ||
chatCall: .init(with: .mock()), | ||
unreadMessages: .init(with: 0), | ||
showsCallBubble: true, | ||
screenShareHandler: .mock, | ||
isWindowVisible: .init(with: true), | ||
uploadFileToEngagement: { file, progress, completion in }, | ||
getCurrentEngagement: { .mock() }, | ||
submitSurveyAnswer: { answers, surveyId, engagementId, completion in }, | ||
interactor: .mock(), | ||
getSecureUnreadMessageCount: { callback in }, | ||
messagesWithUnreadCountLoaderScheduler: CoreSdkClient.reactiveSwiftDateSchedulerMock, | ||
secureMarkMessagesAsRead: { callback in .mock }, | ||
downloadSecureFile: { file, progress, completion in .mock }, | ||
isAuthenticated: { true }, | ||
startSocketObservation: { }, | ||
stopSocketObservation: { }, | ||
createSendMessagePayload: { content, attachment in .mock() }, | ||
orientationManager: .mock(), | ||
proximityManager: .mock, | ||
log: .mock, | ||
timerProviding: .mock, | ||
snackBar: SnackBar( | ||
present: { text, style, viewController, bottomOffset, timerProviding, gcd, notificationCenter in | ||
} | ||
) | ||
) | ||
} |
212 changes: 212 additions & 0 deletions
212
GliaWidgetsTests/SecureConversations/Coordinator/SecureConversations.CoordinatorTests.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,212 @@ | ||
import Foundation | ||
import XCTest | ||
@testable import GliaWidgets | ||
|
||
final class SecureConversationsCoordinatorTests: XCTestCase { | ||
var navigationPresenter = NavigationPresenter(with: NavigationController()) | ||
var coordinator: SecureConversations.Coordinator! | ||
|
||
override func setUp() { | ||
coordinator = createCoordinator() | ||
} | ||
|
||
func createCoordinator( | ||
initialScreen: SecureConversations.InitialScreen = .welcome | ||
) -> SecureConversations.Coordinator { | ||
return SecureConversations.Coordinator( | ||
messagingInitialScreen: initialScreen, | ||
viewFactory: .mock(), | ||
navigationPresenter: navigationPresenter, | ||
environment: .mock | ||
) | ||
} | ||
|
||
// Start | ||
func test_startGeneratesWelcomeViewController() { | ||
let viewController = coordinator.start() as? SecureConversations.WelcomeViewController | ||
|
||
XCTAssertNotNil(viewController) | ||
} | ||
|
||
func test_startGeneratesChatViewController() { | ||
let coordinator = createCoordinator(initialScreen: .chatTranscript) | ||
let viewController = coordinator.start() as? ChatViewController | ||
|
||
XCTAssertNotNil(viewController) | ||
} | ||
|
||
// Delegate | ||
func test_backTapped() { | ||
coordinator.delegate = { event in | ||
switch event { | ||
case .backTapped: XCTAssertTrue(true) | ||
default: XCTFail() | ||
} | ||
} | ||
|
||
coordinator.viewModel?.delegate?(.backTapped) | ||
} | ||
|
||
func test_closeTapped() { | ||
coordinator.delegate = { event in | ||
switch event { | ||
case .closeTapped(let presentation): | ||
XCTAssertEqual(presentation, .doNotPresentSurvey) | ||
default: XCTFail() | ||
} | ||
} | ||
|
||
coordinator.viewModel?.delegate?(.backTapped) | ||
} | ||
|
||
func test_renderProps() throws { | ||
let welcomeViewController = try XCTUnwrap(coordinator.start() as? SecureConversations.WelcomeViewController) | ||
coordinator.viewModel?.delegate?(.renderProps(.mock)) | ||
|
||
XCTAssertEqual(.mock, welcomeViewController.props) | ||
} | ||
|
||
func test_confirmationScreenRequested() { | ||
_ = coordinator.start() | ||
coordinator.viewModel?.delegate?(.confirmationScreenRequested) | ||
let confirmationViewController = navigationPresenter.viewControllers | ||
.last as? SecureConversations.ConfirmationViewController | ||
|
||
XCTAssertNotNil(confirmationViewController) | ||
} | ||
|
||
func test_mediaPickerRequested() throws { | ||
let welcomeViewController = try XCTUnwrap(coordinator.start() as? SecureConversations.WelcomeViewController) | ||
let scene = try XCTUnwrap(UIApplication.shared.connectedScenes.first as? UIWindowScene) | ||
let window = scene.windows.first | ||
let oldRootViewController = window?.rootViewController | ||
window?.rootViewController = welcomeViewController | ||
defer { window?.rootViewController = oldRootViewController } | ||
coordinator.viewModel?.delegate?( | ||
.mediaPickerRequested( | ||
from: welcomeViewController.view, | ||
callback: { _ in } | ||
) | ||
) | ||
let presentedViewController = welcomeViewController.presentedViewController as? PopoverViewController | ||
|
||
XCTAssertNotNil(presentedViewController) | ||
} | ||
|
||
// Take media is not tested because this triggers the native | ||
// "App would like to access the camera" dialog, which could | ||
// bring unintended consequences. | ||
func test_pickMedia() { | ||
_ = coordinator.start() | ||
|
||
XCTAssertNil(coordinator.selectedPickerController) | ||
|
||
coordinator.viewModel?.delegate?(.pickMedia(.nop)) | ||
XCTAssertNotNil(coordinator.selectedPickerController) | ||
|
||
switch coordinator.selectedPickerController { | ||
case .mediaPickerController(let controller): | ||
XCTAssertEqual(controller.viewModel.source, .library) | ||
default: XCTFail() | ||
} | ||
} | ||
|
||
func test_pickFile() { | ||
_ = coordinator.start() | ||
|
||
XCTAssertNil(coordinator.selectedPickerController) | ||
|
||
coordinator.viewModel?.delegate?(.pickFile(.nop)) | ||
XCTAssertNotNil(coordinator.selectedPickerController) | ||
|
||
switch coordinator.selectedPickerController { | ||
case .filePickerController: XCTAssertTrue(true) | ||
default: XCTFail() | ||
} | ||
} | ||
|
||
func test_showAlert() throws { | ||
let welcomeViewController = try XCTUnwrap(coordinator.start() as? SecureConversations.WelcomeViewController) | ||
let scene = try XCTUnwrap(UIApplication.shared.connectedScenes.first as? UIWindowScene) | ||
let window = scene.windows.first | ||
let oldRootViewController = window?.rootViewController | ||
window?.rootViewController = welcomeViewController | ||
defer { window?.rootViewController = oldRootViewController } | ||
|
||
let configuration = MessageAlertConfiguration( | ||
title: "", | ||
message: "" | ||
) | ||
coordinator.viewModel?.delegate?( | ||
.showAlert( | ||
configuration, | ||
accessibilityIdentifier: nil, | ||
dismissed: nil | ||
) | ||
) | ||
|
||
let presentedViewController = welcomeViewController.presentedViewController as? AlertViewController | ||
|
||
XCTAssertNotNil(presentedViewController) | ||
} | ||
|
||
func test_showAlertAsView() throws { | ||
let welcomeViewController = try XCTUnwrap(coordinator.start() as? SecureConversations.WelcomeViewController) | ||
let scene = try XCTUnwrap(UIApplication.shared.connectedScenes.first as? UIWindowScene) | ||
let window = scene.windows.first | ||
let oldRootViewController = window?.rootViewController | ||
window?.rootViewController = welcomeViewController | ||
defer { window?.rootViewController = oldRootViewController } | ||
|
||
let configuration = MessageAlertConfiguration( | ||
title: "", | ||
message: "" | ||
) | ||
coordinator.viewModel?.delegate?( | ||
.showAlertAsView( | ||
configuration, | ||
accessibilityIdentifier: nil, | ||
dismissed: nil | ||
) | ||
) | ||
|
||
let presentedViewController = welcomeViewController.children.first { $0 is AlertViewController } | ||
|
||
XCTAssertNotNil(presentedViewController) | ||
} | ||
|
||
func test_showSettingsAlert() throws { | ||
let welcomeViewController = try XCTUnwrap(coordinator.start() as? SecureConversations.WelcomeViewController) | ||
let scene = try XCTUnwrap(UIApplication.shared.connectedScenes.first as? UIWindowScene) | ||
let window = scene.windows.first | ||
let oldRootViewController = window?.rootViewController | ||
window?.rootViewController = welcomeViewController | ||
defer { window?.rootViewController = oldRootViewController } | ||
|
||
let configuration = SettingsAlertConfiguration( | ||
title: "", | ||
message: "", | ||
settingsTitle: "", | ||
cancelTitle: "" | ||
) | ||
coordinator.viewModel?.delegate?( | ||
.showSettingsAlert( | ||
configuration, | ||
cancelled: { } | ||
) | ||
) | ||
|
||
let presentedViewController = welcomeViewController.presentedViewController as? UIAlertController | ||
|
||
XCTAssertNotNil(presentedViewController) | ||
} | ||
|
||
func test_transcriptRequested() { | ||
_ = coordinator.start() | ||
coordinator.viewModel?.delegate?(.transcriptRequested) | ||
let transcriptViewController = navigationPresenter.viewControllers | ||
.last as? ChatViewController | ||
|
||
XCTAssertNotNil(transcriptViewController) | ||
} | ||
} |
Oops, something went wrong.