From 73c91fbe217054209f7b54144ec13d763981055e Mon Sep 17 00:00:00 2001 From: Gerson Noboa Date: Mon, 22 Jan 2024 12:49:50 +0200 Subject: [PATCH] Add unit tests for VideoCallCoordinator Correct actions and creation of view controllers in the coordinator has been covered with unit tests. MOB-2915 --- GliaWidgets.xcodeproj/project.pbxproj | 32 ++++++ .../Coordinator/VideoCallCoordinator.swift | 2 +- ...ideoCallCoordinator.Environment.Mock.swift | 21 ++++ .../VideoCallCoordinatorTests.swift | 102 ++++++++++++++++++ 4 files changed, 156 insertions(+), 1 deletion(-) create mode 100644 GliaWidgetsTests/Sources/CallVisualizer/VideoCall/Coordinator/CallVisualizer.VideoCallCoordinator.Environment.Mock.swift create mode 100644 GliaWidgetsTests/Sources/CallVisualizer/VideoCall/Coordinator/VideoCallCoordinatorTests.swift diff --git a/GliaWidgets.xcodeproj/project.pbxproj b/GliaWidgets.xcodeproj/project.pbxproj index 0e4a25ae5..152b58d33 100644 --- a/GliaWidgets.xcodeproj/project.pbxproj +++ b/GliaWidgets.xcodeproj/project.pbxproj @@ -190,6 +190,8 @@ 315BAB1A29ADFEBC00FF284B /* ConfirmationStyle+TitleStyle.swift in Sources */ = {isa = PBXBuildFile; fileRef = 315BAB1929ADFEBC00FF284B /* ConfirmationStyle+TitleStyle.swift */; }; 315BAB1C29ADFEC800FF284B /* ConfirmationStyle+SubtitleStyle.swift in Sources */ = {isa = PBXBuildFile; fileRef = 315BAB1B29ADFEC800FF284B /* ConfirmationStyle+SubtitleStyle.swift */; }; 315BAB1E29ADFED800FF284B /* ConfirmationStyle+CheckMessagesButtonStyle.swift in Sources */ = {isa = PBXBuildFile; fileRef = 315BAB1D29ADFED800FF284B /* ConfirmationStyle+CheckMessagesButtonStyle.swift */; }; + 31758EC02B5E9E22007BBD9F /* VideoCallCoordinatorTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 31758EBE2B5E9E22007BBD9F /* VideoCallCoordinatorTests.swift */; }; + 31758EC12B5E9E22007BBD9F /* CallVisualizer.VideoCallCoordinator.Environment.Mock.swift in Sources */ = {isa = PBXBuildFile; fileRef = 31758EBF2B5E9E22007BBD9F /* CallVisualizer.VideoCallCoordinator.Environment.Mock.swift */; }; 31882C9B2AA21B71009DE4BD /* Localization+Templates.swift in Sources */ = {isa = PBXBuildFile; fileRef = 31882C9A2AA21B71009DE4BD /* Localization+Templates.swift */; }; 3189DD9429DEFAC600D68E9F /* SecureConversations.WelcomeViewModelSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3189DD9329DEFAC600D68E9F /* SecureConversations.WelcomeViewModelSpec.swift */; }; 3189DD9629E4331200D68E9F /* SecureConversations.WelcomeViewModel.Mock.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3189DD9529E4331200D68E9F /* SecureConversations.WelcomeViewModel.Mock.swift */; }; @@ -984,6 +986,8 @@ 315BAB1929ADFEBC00FF284B /* ConfirmationStyle+TitleStyle.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "ConfirmationStyle+TitleStyle.swift"; sourceTree = ""; }; 315BAB1B29ADFEC800FF284B /* ConfirmationStyle+SubtitleStyle.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "ConfirmationStyle+SubtitleStyle.swift"; sourceTree = ""; }; 315BAB1D29ADFED800FF284B /* ConfirmationStyle+CheckMessagesButtonStyle.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "ConfirmationStyle+CheckMessagesButtonStyle.swift"; sourceTree = ""; }; + 31758EBE2B5E9E22007BBD9F /* VideoCallCoordinatorTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = VideoCallCoordinatorTests.swift; sourceTree = ""; }; + 31758EBF2B5E9E22007BBD9F /* CallVisualizer.VideoCallCoordinator.Environment.Mock.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CallVisualizer.VideoCallCoordinator.Environment.Mock.swift; sourceTree = ""; }; 31882C9A2AA21B71009DE4BD /* Localization+Templates.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Localization+Templates.swift"; sourceTree = ""; }; 3189DD9329DEFAC600D68E9F /* SecureConversations.WelcomeViewModelSpec.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SecureConversations.WelcomeViewModelSpec.swift; sourceTree = ""; }; 3189DD9529E4331200D68E9F /* SecureConversations.WelcomeViewModel.Mock.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SecureConversations.WelcomeViewModel.Mock.swift; sourceTree = ""; }; @@ -2808,6 +2812,31 @@ path = Call; sourceTree = ""; }; + 31FF0DD22B5AB82000834AFB /* CallVisualizer */ = { + isa = PBXGroup; + children = ( + 31FF0DD32B5AB82900834AFB /* VideoCall */, + ); + path = CallVisualizer; + sourceTree = ""; + }; + 31FF0DD32B5AB82900834AFB /* VideoCall */ = { + isa = PBXGroup; + children = ( + 31FF0DD42B5AB82F00834AFB /* Coordinator */, + ); + path = VideoCall; + sourceTree = ""; + }; + 31FF0DD42B5AB82F00834AFB /* Coordinator */ = { + isa = PBXGroup; + children = ( + 31758EBF2B5E9E22007BBD9F /* CallVisualizer.VideoCallCoordinator.Environment.Mock.swift */, + 31758EBE2B5E9E22007BBD9F /* VideoCallCoordinatorTests.swift */, + ); + path = Coordinator; + sourceTree = ""; + }; 69BB38CE6B54F4C95ED474B6 /* Pods */ = { isa = PBXGroup; children = ( @@ -2826,6 +2855,7 @@ 7512A57827BF9FB800319DF1 /* Sources */ = { isa = PBXGroup; children = ( + 31FF0DD22B5AB82000834AFB /* CallVisualizer */, 31FF0DC72B5907C600834AFB /* Coordinators */, 84602A752AEA5BDE0031E606 /* ProximityManager */, 84681A932A61840700DD7406 /* ChatViewModel */, @@ -5225,6 +5255,8 @@ 9AE05CB62805D2CB00871321 /* Interactor.Environment.Failing.swift in Sources */, 846429862A45DB4100943BD6 /* AlertViewController.Kind+Mock.swift in Sources */, AF29811229E42F3C0005BD55 /* AvailabilityTests.swift in Sources */, + 31758EC12B5E9E22007BBD9F /* CallVisualizer.VideoCallCoordinator.Environment.Mock.swift in Sources */, + 31758EC02B5E9E22007BBD9F /* VideoCallCoordinatorTests.swift in Sources */, 9AE05CB32805C9D900871321 /* ChatViewModel.Environment.Failing.swift in Sources */, 7552DFB12A6FB7DF0093519B /* ChatMessageTests.swift in Sources */, 8491AF672AB8707600CC3E72 /* ChatViewModelTests+Transferring.swift in Sources */, diff --git a/GliaWidgets/Sources/CallVisualizer/VideoCall/Coordinator/VideoCallCoordinator.swift b/GliaWidgets/Sources/CallVisualizer/VideoCall/Coordinator/VideoCallCoordinator.swift index 212313a71..e0e342b24 100644 --- a/GliaWidgets/Sources/CallVisualizer/VideoCall/Coordinator/VideoCallCoordinator.swift +++ b/GliaWidgets/Sources/CallVisualizer/VideoCall/Coordinator/VideoCallCoordinator.swift @@ -7,7 +7,7 @@ extension CallVisualizer { var delegate: ((DelegateEvent) -> Void)? private let theme: Theme private let environment: Environment - private var viewModel: VideoCallViewModel? + private(set) var viewModel: VideoCallViewModel? let call: Call var viewController: VideoCallViewController? diff --git a/GliaWidgetsTests/Sources/CallVisualizer/VideoCall/Coordinator/CallVisualizer.VideoCallCoordinator.Environment.Mock.swift b/GliaWidgetsTests/Sources/CallVisualizer/VideoCall/Coordinator/CallVisualizer.VideoCallCoordinator.Environment.Mock.swift new file mode 100644 index 000000000..d3ab420e4 --- /dev/null +++ b/GliaWidgetsTests/Sources/CallVisualizer/VideoCall/Coordinator/CallVisualizer.VideoCallCoordinator.Environment.Mock.swift @@ -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 + ) +} diff --git a/GliaWidgetsTests/Sources/CallVisualizer/VideoCall/Coordinator/VideoCallCoordinatorTests.swift b/GliaWidgetsTests/Sources/CallVisualizer/VideoCall/Coordinator/VideoCallCoordinatorTests.swift new file mode 100644 index 000000000..6beb2f722 --- /dev/null +++ b/GliaWidgetsTests/Sources/CallVisualizer/VideoCall/Coordinator/VideoCallCoordinatorTests.swift @@ -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) + } +}