-
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 unit tests for VideoCallCoordinator
Correct actions and creation of view controllers in the coordinator has been covered with unit tests. MOB-2915
- Loading branch information
1 parent
32c4222
commit 73c91fb
Showing
4 changed files
with
156 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
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
21 changes: 21 additions & 0 deletions
21
...sualizer/VideoCall/Coordinator/CallVisualizer.VideoCallCoordinator.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,21 @@ | ||
import Foundation | ||
@testable import GliaWidgets | ||
|
||
extension CallVisualizer.VideoCallCoordinator.Environment { | ||
static let mock = Self( | ||
data: .mock, | ||
uuid: { .mock }, | ||
gcd: .mock, | ||
imageViewCache: .mock, | ||
timerProviding: .mock, | ||
uiApplication: .mock, | ||
uiScreen: .mock, | ||
uiDevice: .mock, | ||
notificationCenter: .mock, | ||
date: { .mock }, | ||
engagedOperator: { .mock() }, | ||
screenShareHandler: .mock, | ||
proximityManager: .mock, | ||
log: .mock | ||
) | ||
} |
102 changes: 102 additions & 0 deletions
102
...WidgetsTests/Sources/CallVisualizer/VideoCall/Coordinator/VideoCallCoordinatorTests.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,102 @@ | ||
import Foundation | ||
import XCTest | ||
@testable import GliaWidgets | ||
|
||
final class VideoCallCoordinatorTests: XCTestCase { | ||
var coordinator: CallVisualizer.VideoCallCoordinator! | ||
|
||
override func setUp() { | ||
coordinator = CallVisualizer.VideoCallCoordinator( | ||
environment: .mock, | ||
theme: .mock(), | ||
call: .mock() | ||
) | ||
} | ||
|
||
func test_startGeneratesVideoCallViewController() { | ||
let viewController = coordinator.start() as? CallVisualizer.VideoCallViewController | ||
|
||
XCTAssertNotNil(viewController) | ||
XCTAssertNotNil(coordinator.viewController) | ||
} | ||
|
||
func test_resume() { | ||
_ = coordinator.start() | ||
let viewController = coordinator.resume() as? CallVisualizer.VideoCallViewController | ||
|
||
XCTAssertNotNil(viewController) | ||
} | ||
|
||
func test_resumeCreatesNewViewController() { | ||
let viewController = coordinator.resume() as? CallVisualizer.VideoCallViewController | ||
|
||
XCTAssertNotNil(viewController) | ||
XCTAssertNotNil(coordinator.viewController) | ||
} | ||
|
||
// Show delegate | ||
|
||
func test_showDelegatePropsUpdated() { | ||
let viewController = coordinator.start() as? CallVisualizer.VideoCallViewController | ||
|
||
let props: CallVisualizer.VideoCallViewController.Props = .init( | ||
videoCallViewProps: .mock(), | ||
viewDidLoad: .nop | ||
) | ||
|
||
let event: CallVisualizer.VideoCallViewModel.DelegateEvent = .propsUpdated(props) | ||
|
||
coordinator.viewModel?.delegate?(event) | ||
|
||
XCTAssertEqual(viewController?.props, props) | ||
} | ||
|
||
func test_showDelegateMinimize() throws { | ||
_ = coordinator.start() | ||
|
||
var calledEvents: [CallVisualizer.VideoCallCoordinator.DelegateEvent] = [] | ||
|
||
coordinator.delegate = { event in | ||
calledEvents.append(event) | ||
} | ||
|
||
coordinator.viewModel?.delegate?(.minimized) | ||
|
||
XCTAssertEqual(calledEvents.count, 1) | ||
XCTAssertEqual(try XCTUnwrap(calledEvents.first), .close) | ||
} | ||
|
||
// Resume delegate | ||
|
||
func test_resumeDelegatePropsUpdated() { | ||
_ = coordinator.start() | ||
let viewController = coordinator.resume() as? CallVisualizer.VideoCallViewController | ||
|
||
let props: CallVisualizer.VideoCallViewController.Props = .init( | ||
videoCallViewProps: .mock(), | ||
viewDidLoad: .nop | ||
) | ||
|
||
let event: CallVisualizer.VideoCallViewModel.DelegateEvent = .propsUpdated(props) | ||
|
||
coordinator.viewModel?.delegate?(event) | ||
|
||
XCTAssertEqual(viewController?.props, props) | ||
} | ||
|
||
func test_resumeDelegateMinimize() throws { | ||
_ = coordinator.start() | ||
_ = coordinator.resume() | ||
|
||
var calledEvents: [CallVisualizer.VideoCallCoordinator.DelegateEvent] = [] | ||
|
||
coordinator.delegate = { event in | ||
calledEvents.append(event) | ||
} | ||
|
||
coordinator.viewModel?.delegate?(.minimized) | ||
|
||
XCTAssertEqual(calledEvents.count, 1) | ||
XCTAssertEqual(try XCTUnwrap(calledEvents.first), .close) | ||
} | ||
} |