From b6cf70c10922a269387bf72fa6cb1f29a72db18b Mon Sep 17 00:00:00 2001 From: El-Fitz <8971906+El-Fitz@users.noreply.github.com> Date: Tue, 24 Dec 2024 19:45:04 +0100 Subject: [PATCH 1/2] refactor: inject SelfProvileViewsMonitor and its mock --- ...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 +- .../SelfProfile/SelfProfileViewsMonitor.swift | 2 +- 12 files changed, 51 insertions(+), 3 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 a26fb48c1fa..38af842d545 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 6966fdc7371..cdf77193bb2 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 37aba49e8f1..0b67d7b5350 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 00000000000..0db1f65f2fa --- /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/. +// + +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 c93c42f7c79..d7f3a79f641 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 d425e5bc1a5..b2736fd4823 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 27c29c70b98..173f5c3ab52 100644 --- a/wire-ios/Wire-iOS.xcodeproj/project.pbxproj +++ b/wire-ios/Wire-iOS.xcodeproj/project.pbxproj @@ -684,6 +684,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 */; }; @@ -2617,6 +2618,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 = ""; }; @@ -8038,6 +8040,7 @@ EF4C5D4C23351D230092CA38 /* Container */ = { isa = PBXGroup; children = ( + 764C478C2D1B32BE00227531 /* MockSelfProfileViewsMonitorImplementation.swift */, A98ECDF2232A9564006A57FD /* MockConversationListContainer.swift */, EFAFCA8C213433D6002B31A6 /* ConversationListViewControllerSnapshotTests.swift */, A98ECDF0232A94DD006A57FD /* ConversationListViewControllerViewModelSnapshotTests.swift */, @@ -10136,6 +10139,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 2bffa542752..41760fd0c4c 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 b9e6d7a3e1e..8582d1713dc 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 78497f915fa..9f6984fb7a7 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 67320060677..e217ee773ab 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() diff --git a/wire-ios/Wire-iOS/Sources/UserInterface/SelfProfile/SelfProfileViewsMonitor.swift b/wire-ios/Wire-iOS/Sources/UserInterface/SelfProfile/SelfProfileViewsMonitor.swift index 687d7ed900f..c172c0440a5 100644 --- a/wire-ios/Wire-iOS/Sources/UserInterface/SelfProfile/SelfProfileViewsMonitor.swift +++ b/wire-ios/Wire-iOS/Sources/UserInterface/SelfProfile/SelfProfileViewsMonitor.swift @@ -20,7 +20,7 @@ import WireFoundation import WireLogging import WireSyncEngine -protocol SelfProfileViewsMonitor { +public protocol SelfProfileViewsMonitor { var didViewSelfProfile: Bool { get } func onDidViewSelfProfile() From 3dbda2d73007b931a27fc74003c1e9ac1f034613 Mon Sep 17 00:00:00 2001 From: El-Fitz <8971906+El-Fitz@users.noreply.github.com> Date: Fri, 3 Jan 2025 16:04:49 +0100 Subject: [PATCH 2/2] chore: remove public accessor --- .../Container/MockSelfProfileViewsMonitorImplementation.swift | 2 +- .../UserInterface/SelfProfile/SelfProfileViewsMonitor.swift | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/wire-ios/Wire-iOS Tests/ConversationList/Container/MockSelfProfileViewsMonitorImplementation.swift b/wire-ios/Wire-iOS Tests/ConversationList/Container/MockSelfProfileViewsMonitorImplementation.swift index 0db1f65f2fa..a512f1bf8d9 100644 --- a/wire-ios/Wire-iOS Tests/ConversationList/Container/MockSelfProfileViewsMonitorImplementation.swift +++ b/wire-ios/Wire-iOS Tests/ConversationList/Container/MockSelfProfileViewsMonitorImplementation.swift @@ -16,7 +16,7 @@ // along with this program. If not, see http://www.gnu.org/licenses/. // -import Wire +@testable import Wire class MockSelfProfileViewsMonitorImplementation: SelfProfileViewsMonitor { diff --git a/wire-ios/Wire-iOS/Sources/UserInterface/SelfProfile/SelfProfileViewsMonitor.swift b/wire-ios/Wire-iOS/Sources/UserInterface/SelfProfile/SelfProfileViewsMonitor.swift index c172c0440a5..687d7ed900f 100644 --- a/wire-ios/Wire-iOS/Sources/UserInterface/SelfProfile/SelfProfileViewsMonitor.swift +++ b/wire-ios/Wire-iOS/Sources/UserInterface/SelfProfile/SelfProfileViewsMonitor.swift @@ -20,7 +20,7 @@ import WireFoundation import WireLogging import WireSyncEngine -public protocol SelfProfileViewsMonitor { +protocol SelfProfileViewsMonitor { var didViewSelfProfile: Bool { get } func onDidViewSelfProfile()