From c1d6a9829ba70d256c76f0292cf73fe2fc38654b Mon Sep 17 00:00:00 2001 From: El-Fitz <8971906+El-Fitz@users.noreply.github.com> Date: Mon, 6 Jan 2025 13:24:56 +0100 Subject: [PATCH] feat: inject self profile views monitor - WPB-15038 (#2331) --- ...ationListViewControllerSnapshotTests.swift | 1 + ...ViewControllerViewModelSnapshotTests.swift | 1 + ...tionListViewControllerViewModelTests.swift | 1 + ...elfProfileViewsMonitorImplementation.swift | 35 +++++++++++++++++++ ...versationViewControllerSnapshotTests.swift | 1 + .../ZClientViewControllerTests.swift | 1 + wire-ios/Wire-iOS.xcodeproj/project.pbxproj | 4 +++ .../ConversationListViewController.swift | 1 + ...versationListViewControllerViewModel.swift | 3 +- .../ZClientControllerBuilder.swift | 1 + .../ZClientViewController.swift | 3 +- 11 files changed, 50 insertions(+), 2 deletions(-) create mode 100644 wire-ios/Wire-iOS Tests/ConversationList/Container/MockSelfProfileViewsMonitorImplementation.swift diff --git a/wire-ios/Wire-iOS Tests/ConversationList/Container/ConversationListViewControllerSnapshotTests.swift b/wire-ios/Wire-iOS Tests/ConversationList/Container/ConversationListViewControllerSnapshotTests.swift index 3f00db69b8..6ae0fffb98 100644 --- a/wire-ios/Wire-iOS Tests/ConversationList/Container/ConversationListViewControllerSnapshotTests.swift +++ b/wire-ios/Wire-iOS Tests/ConversationList/Container/ConversationListViewControllerSnapshotTests.swift @@ -67,6 +67,7 @@ final class ConversationListViewControllerSnapshotTests: XCTestCase { zClientViewController = ZClientViewController( account: coreDataStack.account, + selfProfileViewsMonitor: SelfProfileViewsMonitorImplementation(), userSession: userSession, trackingManager: nil ) diff --git a/wire-ios/Wire-iOS Tests/ConversationList/Container/ConversationListViewControllerViewModelSnapshotTests.swift b/wire-ios/Wire-iOS Tests/ConversationList/Container/ConversationListViewControllerViewModelSnapshotTests.swift index ad6060c72d..5b6ee38d88 100644 --- a/wire-ios/Wire-iOS Tests/ConversationList/Container/ConversationListViewControllerViewModelSnapshotTests.swift +++ b/wire-ios/Wire-iOS Tests/ConversationList/Container/ConversationListViewControllerViewModelSnapshotTests.swift @@ -54,6 +54,7 @@ final class ConversationListViewControllerViewModelSnapshotTests: XCTestCase { let selfUser = MockUserType.createSelfUser(name: "Bob") sut = ConversationListViewController.ViewModel( account: account, + selfProfileViewsMonitor: MockSelfProfileViewsMonitorImplementation(didViewSelfProfile: false), selfUserLegalHoldSubject: selfUser, userSession: userSession, isSelfUserE2EICertifiedUseCase: mockIsSelfUserE2EICertifiedUseCase, diff --git a/wire-ios/Wire-iOS Tests/ConversationList/Container/ConversationListViewControllerViewModelTests.swift b/wire-ios/Wire-iOS Tests/ConversationList/Container/ConversationListViewControllerViewModelTests.swift index 507f4f1824..5e669c60b2 100644 --- a/wire-ios/Wire-iOS Tests/ConversationList/Container/ConversationListViewControllerViewModelTests.swift +++ b/wire-ios/Wire-iOS Tests/ConversationList/Container/ConversationListViewControllerViewModelTests.swift @@ -48,6 +48,7 @@ final class ConversationListViewControllerViewModelTests: XCTestCase { sut = ConversationListViewController.ViewModel( account: account, + selfProfileViewsMonitor: MockSelfProfileViewsMonitorImplementation(didViewSelfProfile: false), selfUserLegalHoldSubject: selfUser, userSession: userSession, isSelfUserE2EICertifiedUseCase: mockIsSelfUserE2EICertifiedUseCase, diff --git a/wire-ios/Wire-iOS Tests/ConversationList/Container/MockSelfProfileViewsMonitorImplementation.swift b/wire-ios/Wire-iOS Tests/ConversationList/Container/MockSelfProfileViewsMonitorImplementation.swift new file mode 100644 index 0000000000..a512f1bf8d --- /dev/null +++ b/wire-ios/Wire-iOS Tests/ConversationList/Container/MockSelfProfileViewsMonitorImplementation.swift @@ -0,0 +1,35 @@ +// +// Wire +// Copyright (C) 2024 Wire Swiss GmbH +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see http://www.gnu.org/licenses/. +// + +@testable import Wire + +class MockSelfProfileViewsMonitorImplementation: SelfProfileViewsMonitor { + + private(set) var didViewSelfProfile: Bool + private let onDidViewSelfProfileCallback: @Sendable () -> Void + + init(didViewSelfProfile: Bool, onDidViewSelfProfileCallback: @escaping @Sendable () -> Void = {}) { + self.didViewSelfProfile = didViewSelfProfile + self.onDidViewSelfProfileCallback = onDidViewSelfProfileCallback + } + + func onDidViewSelfProfile() { + didViewSelfProfile = true + onDidViewSelfProfileCallback() + } +} diff --git a/wire-ios/Wire-iOS Tests/ConversationViewControllerSnapshotTests.swift b/wire-ios/Wire-iOS Tests/ConversationViewControllerSnapshotTests.swift index de500b2016..c2b3878de0 100644 --- a/wire-ios/Wire-iOS Tests/ConversationViewControllerSnapshotTests.swift +++ b/wire-ios/Wire-iOS Tests/ConversationViewControllerSnapshotTests.swift @@ -65,6 +65,7 @@ final class ConversationViewControllerSnapshotTests: ZMSnapshotTestCase, CoreDat let zClientViewController = ZClientViewController( account: mockAccount, + selfProfileViewsMonitor: SelfProfileViewsMonitorImplementation(), userSession: userSession, trackingManager: nil ) diff --git a/wire-ios/Wire-iOS Tests/ZClientViewControllerTests.swift b/wire-ios/Wire-iOS Tests/ZClientViewControllerTests.swift index 196c4e8e3c..1c410873c7 100644 --- a/wire-ios/Wire-iOS Tests/ZClientViewControllerTests.swift +++ b/wire-ios/Wire-iOS Tests/ZClientViewControllerTests.swift @@ -37,6 +37,7 @@ final class ZClientViewControllerTests: XCTestCase { userSession.coreDataStack = coreDataFixture.coreDataStack sut = ZClientViewController( account: Account.mockAccount(imageData: mockImageData), + selfProfileViewsMonitor: MockSelfProfileViewsMonitorImplementation(didViewSelfProfile: false), userSession: userSession, trackingManager: nil ) diff --git a/wire-ios/Wire-iOS.xcodeproj/project.pbxproj b/wire-ios/Wire-iOS.xcodeproj/project.pbxproj index a40074ac1a..40c5c7c324 100644 --- a/wire-ios/Wire-iOS.xcodeproj/project.pbxproj +++ b/wire-ios/Wire-iOS.xcodeproj/project.pbxproj @@ -683,6 +683,7 @@ 6636CFDE2C519980001403F9 /* EditingStateControllable.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6636CFDD2C519980001403F9 /* EditingStateControllable.swift */; }; 669105C327397E6A00324115 /* NSAttributedString+DownTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 669105C227397E6900324115 /* NSAttributedString+DownTests.swift */; }; 70355A7127AAD96E00F02C76 /* SecurityLevelView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 70355A7027AAD96E00F02C76 /* SecurityLevelView.swift */; }; + 764C478D2D1B32C100227531 /* MockSelfProfileViewsMonitorImplementation.swift in Sources */ = {isa = PBXBuildFile; fileRef = 764C478C2D1B32BE00227531 /* MockSelfProfileViewsMonitorImplementation.swift */; }; 76D15E712CEFAE8A0059215D /* WireIndividualToTeamMigrationUI in Frameworks */ = {isa = PBXBuildFile; productRef = 76D15E702CEFAE8A0059215D /* WireIndividualToTeamMigrationUI */; }; 7A702FB7286322D800004580 /* ConversationEncryptionProtocolCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7A702FB6286322D800004580 /* ConversationEncryptionProtocolCell.swift */; }; 7C0BB6E61FE682A200386A19 /* AccountSelectionViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7C0BB6E41FE680F200386A19 /* AccountSelectionViewController.swift */; }; @@ -2614,6 +2615,7 @@ 6636CFDD2C519980001403F9 /* EditingStateControllable.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EditingStateControllable.swift; sourceTree = ""; }; 669105C227397E6900324115 /* NSAttributedString+DownTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "NSAttributedString+DownTests.swift"; sourceTree = ""; }; 70355A7027AAD96E00F02C76 /* SecurityLevelView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SecurityLevelView.swift; sourceTree = ""; }; + 764C478C2D1B32BE00227531 /* MockSelfProfileViewsMonitorImplementation.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MockSelfProfileViewsMonitorImplementation.swift; sourceTree = ""; }; 7A702FB6286322D800004580 /* ConversationEncryptionProtocolCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ConversationEncryptionProtocolCell.swift; sourceTree = ""; }; 7C0BB6E41FE680F200386A19 /* AccountSelectionViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AccountSelectionViewController.swift; sourceTree = ""; }; 7C23A26B20247474005FEB54 /* ShareViewControllerTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ShareViewControllerTests.swift; sourceTree = ""; }; @@ -8034,6 +8036,7 @@ EF4C5D4C23351D230092CA38 /* Container */ = { isa = PBXGroup; children = ( + 764C478C2D1B32BE00227531 /* MockSelfProfileViewsMonitorImplementation.swift */, A98ECDF2232A9564006A57FD /* MockConversationListContainer.swift */, EFAFCA8C213433D6002B31A6 /* ConversationListViewControllerSnapshotTests.swift */, A98ECDF0232A94DD006A57FD /* ConversationListViewControllerViewModelSnapshotTests.swift */, @@ -10120,6 +10123,7 @@ EF159F381FD59607006E0A9C /* TextFieldValidatorTests.swift in Sources */, 1658C19620A1E2FA00148F6D /* MockVoiceChannel.swift in Sources */, 5502C6E522B7B800000684B7 /* LegalHoldAlertFactoryTests.swift in Sources */, + 764C478D2D1B32C100227531 /* MockSelfProfileViewsMonitorImplementation.swift in Sources */, BF5127161CC9119400F23DEA /* ZMSnapshotTestCase.swift in Sources */, E9B580CC27B3E71900A5814D /* ConversationOptionsServicesViewControllerTests.swift in Sources */, 0608828F29EC742B0053772B /* ConversationMessageFailedRecipientsTests.swift in Sources */, diff --git a/wire-ios/Wire-iOS/Sources/UserInterface/ConversationList/Container/ConversationListViewController.swift b/wire-ios/Wire-iOS/Sources/UserInterface/ConversationList/Container/ConversationListViewController.swift index 3d731fc1e2..0643ac4828 100644 --- a/wire-ios/Wire-iOS/Sources/UserInterface/ConversationList/Container/ConversationListViewController.swift +++ b/wire-ios/Wire-iOS/Sources/UserInterface/ConversationList/Container/ConversationListViewController.swift @@ -134,6 +134,7 @@ final class ConversationListViewController: UIViewController { ) { let viewModel = ConversationListViewController.ViewModel( account: account, + selfProfileViewsMonitor: SelfProfileViewsMonitorImplementation(), selfUserLegalHoldSubject: selfUserLegalHoldSubject, userSession: userSession, isSelfUserE2EICertifiedUseCase: isSelfUserE2EICertifiedUseCase, diff --git a/wire-ios/Wire-iOS/Sources/UserInterface/ConversationList/Container/ViewModel/ConversationListViewControllerViewModel.swift b/wire-ios/Wire-iOS/Sources/UserInterface/ConversationList/Container/ViewModel/ConversationListViewControllerViewModel.swift index 8e6094013d..831adfe248 100644 --- a/wire-ios/Wire-iOS/Sources/UserInterface/ConversationList/Container/ViewModel/ConversationListViewControllerViewModel.swift +++ b/wire-ios/Wire-iOS/Sources/UserInterface/ConversationList/Container/ViewModel/ConversationListViewControllerViewModel.swift @@ -136,6 +136,7 @@ extension ConversationListViewController { init( account: Account, + selfProfileViewsMonitor: SelfProfileViewsMonitor, selfUserLegalHoldSubject: SelfUserLegalHoldable, userSession: UserSession, isSelfUserE2EICertifiedUseCase: IsSelfUserE2EICertifiedUseCaseProtocol, @@ -144,6 +145,7 @@ extension ConversationListViewController { getUserAccountImageSourceUseCase: any GetUserAccountImageSourceUseCaseProtocol ) { self.account = account + self.selfProfileViewsMonitor = selfProfileViewsMonitor self.selfUserLegalHoldSubject = selfUserLegalHoldSubject self.userSession = userSession self.isSelfUserE2EICertifiedUseCase = isSelfUserE2EICertifiedUseCase @@ -153,7 +155,6 @@ extension ConversationListViewController { self.notificationCenter = notificationCenter self.mainCoordinator = mainCoordinator self.getUserAccountImageSourceUseCase = getUserAccountImageSourceUseCase - self.selfProfileViewsMonitor = SelfProfileViewsMonitorImplementation() super.init() updateE2EICertifiedStatus() diff --git a/wire-ios/Wire-iOS/Sources/UserInterface/MainController/ZClientControllerBuilder.swift b/wire-ios/Wire-iOS/Sources/UserInterface/MainController/ZClientControllerBuilder.swift index b6079c99c9..c874b77003 100644 --- a/wire-ios/Wire-iOS/Sources/UserInterface/MainController/ZClientControllerBuilder.swift +++ b/wire-ios/Wire-iOS/Sources/UserInterface/MainController/ZClientControllerBuilder.swift @@ -28,6 +28,7 @@ struct ZClientControllerBuilder { func build(router: AuthenticatedRouterProtocol) -> ZClientViewController { let viewController = ZClientViewController( account: account, + selfProfileViewsMonitor: SelfProfileViewsMonitorImplementation(), userSession: userSession, trackingManager: trackingManager ) diff --git a/wire-ios/Wire-iOS/Sources/UserInterface/MainController/ZClientViewController.swift b/wire-ios/Wire-iOS/Sources/UserInterface/MainController/ZClientViewController.swift index 2e971aa23d..b76792c7c8 100644 --- a/wire-ios/Wire-iOS/Sources/UserInterface/MainController/ZClientViewController.swift +++ b/wire-ios/Wire-iOS/Sources/UserInterface/MainController/ZClientViewController.swift @@ -177,14 +177,15 @@ final class ZClientViewController: UIViewController { /// init method for testing allows injecting an Account object and self user required init( account: Account, + selfProfileViewsMonitor: SelfProfileViewsMonitor, userSession: UserSession, trackingManager: TrackingManager? ) { self.account = account + self.selfProfileViewsMonitor = selfProfileViewsMonitor self.userSession = userSession self.trackingManager = trackingManager self.colorSchemeController = .init(userSession: userSession) - self.selfProfileViewsMonitor = SelfProfileViewsMonitorImplementation() super.init(nibName: nil, bundle: nil) self.proximityMonitorManager = ProximityMonitorManager()