-
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.
Correct actions and creation of view controllers in the coordinator has been covered with unit tests. MOB-2920
- Loading branch information
1 parent
06de0f8
commit 32c4222
Showing
4 changed files
with
204 additions
and
1 deletion.
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
2 changes: 1 addition & 1 deletion
2
GliaWidgets/Sources/ViewController/Call/CallViewController.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
31 changes: 31 additions & 0 deletions
31
GliaWidgetsTests/Sources/Coordinators/Call/CallCoordinator.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,31 @@ | ||
import Foundation | ||
@testable import GliaWidgets | ||
|
||
extension CallCoordinator.Environment { | ||
static let mock = Self( | ||
fetchFile: { engagementFile, progress, completion in }, | ||
downloadSecureFile: { file, progress, completion in .mock }, | ||
uploadFileToEngagement: { file, progress, completion in }, | ||
fileManager: .mock, | ||
data: .mock, | ||
date: { .mock }, | ||
gcd: .mock, | ||
createThumbnailGenerator: { .mock }, | ||
createFileDownload: { file, storage, environment in .mock() }, | ||
fromHistory: { false }, | ||
fetchSiteConfigurations: { completion in }, | ||
getCurrentEngagement: { .mock() }, | ||
timerProviding: .mock, | ||
submitSurveyAnswer: { answers, surveyId, engagementId, completion in }, | ||
uuid: { .mock }, | ||
uiApplication: .mock, | ||
uiScreen: .mock, | ||
notificationCenter: .mock, | ||
fetchChatHistory: { completion in }, | ||
createFileUploadListModel: { environment in .mock() }, | ||
createSendMessagePayload: { content, attachment in .mock() }, | ||
proximityManager: .mock, | ||
log: .mock, | ||
snackBar: .mock | ||
) | ||
} |
156 changes: 156 additions & 0 deletions
156
GliaWidgetsTests/Sources/Coordinators/Call/CallCoordinatorTests.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,156 @@ | ||
import Foundation | ||
import XCTest | ||
@testable import GliaWidgets | ||
|
||
final class CallCoordinatorTests: XCTestCase { | ||
var coordinator: CallCoordinator! | ||
|
||
override func setUpWithError() throws { | ||
let offer = try CoreSdkClient.MediaUpgradeOffer( | ||
type: .audio, | ||
direction: .twoWay | ||
) | ||
|
||
let startAction = CallViewModel.StartAction.call( | ||
offer: offer, | ||
answer: { _, _ in } | ||
) | ||
|
||
coordinator = CallCoordinator( | ||
interactor: .mock(), | ||
viewFactory: .mock(), | ||
navigationPresenter: NavigationPresenter(with: NavigationController()), | ||
call: .mock(), | ||
unreadMessages: .init(with: 0), | ||
screenShareHandler: .mock, | ||
startAction: startAction, | ||
environment: .mock | ||
) | ||
} | ||
|
||
func test_startGeneratesCallViewController() { | ||
let viewController = coordinator.start() | ||
|
||
XCTAssertNotNil(viewController) | ||
} | ||
|
||
// Delegate | ||
|
||
func test_delegateChat() throws { | ||
var calledEvents: [CallCoordinator.DelegateEvent] = [] | ||
|
||
coordinator.delegate = { event in | ||
calledEvents.append(event) | ||
} | ||
|
||
coordinator.start().viewModel.delegate?(.chat) | ||
|
||
XCTAssertEqual(calledEvents.count, 1) | ||
switch try XCTUnwrap(calledEvents.first) { | ||
case .chat: XCTAssertTrue(true) | ||
default: XCTFail() | ||
} | ||
} | ||
|
||
func test_delegateMinimize() throws { | ||
var calledEvents: [CallCoordinator.DelegateEvent] = [] | ||
|
||
coordinator.delegate = { event in | ||
calledEvents.append(event) | ||
} | ||
|
||
coordinator.start().viewModel.delegate?(.minimize) | ||
|
||
XCTAssertEqual(calledEvents.count, 1) | ||
switch try XCTUnwrap(calledEvents.first) { | ||
case .minimize: XCTAssertTrue(true) | ||
default: XCTFail() | ||
} | ||
} | ||
|
||
func test_delegateVisitorOnHoldUpdated() throws { | ||
var calledEvents: [CallCoordinator.DelegateEvent] = [] | ||
|
||
coordinator.delegate = { event in | ||
calledEvents.append(event) | ||
} | ||
|
||
coordinator.start().viewModel.delegate?(.visitorOnHoldUpdated(isOnHold: true)) | ||
|
||
XCTAssertEqual(calledEvents.count, 1) | ||
switch try XCTUnwrap(calledEvents.first) { | ||
case .visitorOnHoldUpdated: XCTAssertTrue(true) | ||
default: XCTFail() | ||
} | ||
} | ||
|
||
// Engagement delegate | ||
|
||
func test_engagementDelegateVisitorOnHoldUpdated() throws { | ||
var calledEvents: [CallCoordinator.DelegateEvent] = [] | ||
|
||
coordinator.delegate = { event in | ||
calledEvents.append(event) | ||
} | ||
|
||
coordinator.start().viewModel.engagementDelegate?(.back) | ||
|
||
XCTAssertEqual(calledEvents.count, 1) | ||
switch try XCTUnwrap(calledEvents.first) { | ||
case .back: XCTAssertTrue(true) | ||
default: XCTFail() | ||
} | ||
} | ||
|
||
func test_engagementDelegateOpenLink() throws { | ||
var calledEvents: [CallCoordinator.DelegateEvent] = [] | ||
|
||
coordinator.delegate = { event in | ||
calledEvents.append(event) | ||
} | ||
|
||
let link: WebViewController.Link = (title: "", url: URL.mock) | ||
coordinator.start().viewModel.engagementDelegate?(.openLink(link)) | ||
|
||
XCTAssertEqual(calledEvents.count, 1) | ||
switch try XCTUnwrap(calledEvents.first) { | ||
case .openLink(let openedLink): XCTAssertEqual(link.url, openedLink.url) | ||
default: XCTFail() | ||
} | ||
} | ||
|
||
func test_engagementDelegateEngaged() throws { | ||
var calledEvents: [CallCoordinator.DelegateEvent] = [] | ||
|
||
coordinator.delegate = { event in | ||
calledEvents.append(event) | ||
} | ||
|
||
coordinator.start().viewModel.engagementDelegate?( | ||
.engaged(operatorImageUrl: URL.mock.absoluteString) | ||
) | ||
|
||
XCTAssertEqual(calledEvents.count, 1) | ||
switch try XCTUnwrap(calledEvents.first) { | ||
case .engaged(let operatorImageUrl): | ||
XCTAssertEqual(URL.mock.absoluteString, operatorImageUrl) | ||
default: XCTFail() | ||
} | ||
} | ||
|
||
func test_engagementDelegateFinished() throws { | ||
var calledEvents: [CallCoordinator.DelegateEvent] = [] | ||
|
||
coordinator.delegate = { event in | ||
calledEvents.append(event) | ||
} | ||
|
||
coordinator.start().viewModel.engagementDelegate?(.finished) | ||
|
||
XCTAssertEqual(calledEvents.count, 1) | ||
switch try XCTUnwrap(calledEvents.first) { | ||
case .finished: XCTAssertTrue(true) | ||
default: XCTFail() | ||
} | ||
} | ||
} |