Skip to content

Commit

Permalink
refactor: inject SelfProvileViewsMonitor and its mock
Browse files Browse the repository at this point in the history
  • Loading branch information
El-Fitz committed Jan 6, 2025
1 parent 282d25e commit b6cf70c
Show file tree
Hide file tree
Showing 12 changed files with 51 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ final class ConversationListViewControllerSnapshotTests: XCTestCase {

zClientViewController = ZClientViewController(
account: coreDataStack.account,
selfProfileViewsMonitor: SelfProfileViewsMonitorImplementation(),
userSession: userSession,
trackingManager: nil
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ final class ConversationListViewControllerViewModelTests: XCTestCase {

sut = ConversationListViewController.ViewModel(
account: account,
selfProfileViewsMonitor: MockSelfProfileViewsMonitorImplementation(didViewSelfProfile: false),
selfUserLegalHoldSubject: selfUser,
userSession: userSession,
isSelfUserE2EICertifiedUseCase: mockIsSelfUserE2EICertifiedUseCase,
Expand Down
Original file line number Diff line number Diff line change
@@ -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()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ final class ConversationViewControllerSnapshotTests: ZMSnapshotTestCase, CoreDat

let zClientViewController = ZClientViewController(
account: mockAccount,
selfProfileViewsMonitor: SelfProfileViewsMonitorImplementation(),
userSession: userSession,
trackingManager: nil
)
Expand Down
1 change: 1 addition & 0 deletions wire-ios/Wire-iOS Tests/ZClientViewControllerTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
Expand Down
4 changes: 4 additions & 0 deletions wire-ios/Wire-iOS.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -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 */; };
Expand Down Expand Up @@ -2617,6 +2618,7 @@
6636CFDD2C519980001403F9 /* EditingStateControllable.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EditingStateControllable.swift; sourceTree = "<group>"; };
669105C227397E6900324115 /* NSAttributedString+DownTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "NSAttributedString+DownTests.swift"; sourceTree = "<group>"; };
70355A7027AAD96E00F02C76 /* SecurityLevelView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SecurityLevelView.swift; sourceTree = "<group>"; };
764C478C2D1B32BE00227531 /* MockSelfProfileViewsMonitorImplementation.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MockSelfProfileViewsMonitorImplementation.swift; sourceTree = "<group>"; };
7A702FB6286322D800004580 /* ConversationEncryptionProtocolCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ConversationEncryptionProtocolCell.swift; sourceTree = "<group>"; };
7C0BB6E41FE680F200386A19 /* AccountSelectionViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AccountSelectionViewController.swift; sourceTree = "<group>"; };
7C23A26B20247474005FEB54 /* ShareViewControllerTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ShareViewControllerTests.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -8038,6 +8040,7 @@
EF4C5D4C23351D230092CA38 /* Container */ = {
isa = PBXGroup;
children = (
764C478C2D1B32BE00227531 /* MockSelfProfileViewsMonitorImplementation.swift */,
A98ECDF2232A9564006A57FD /* MockConversationListContainer.swift */,
EFAFCA8C213433D6002B31A6 /* ConversationListViewControllerSnapshotTests.swift */,
A98ECDF0232A94DD006A57FD /* ConversationListViewControllerViewModelSnapshotTests.swift */,
Expand Down Expand Up @@ -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 */,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@ final class ConversationListViewController: UIViewController {
) {
let viewModel = ConversationListViewController.ViewModel(
account: account,
selfProfileViewsMonitor: SelfProfileViewsMonitorImplementation(),
selfUserLegalHoldSubject: selfUserLegalHoldSubject,
userSession: userSession,
isSelfUserE2EICertifiedUseCase: isSelfUserE2EICertifiedUseCase,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@ extension ConversationListViewController {

init(
account: Account,
selfProfileViewsMonitor: SelfProfileViewsMonitor,
selfUserLegalHoldSubject: SelfUserLegalHoldable,
userSession: UserSession,
isSelfUserE2EICertifiedUseCase: IsSelfUserE2EICertifiedUseCaseProtocol,
Expand All @@ -144,6 +145,7 @@ extension ConversationListViewController {
getUserAccountImageSourceUseCase: any GetUserAccountImageSourceUseCaseProtocol
) {
self.account = account
self.selfProfileViewsMonitor = selfProfileViewsMonitor
self.selfUserLegalHoldSubject = selfUserLegalHoldSubject
self.userSession = userSession
self.isSelfUserE2EICertifiedUseCase = isSelfUserE2EICertifiedUseCase
Expand All @@ -153,7 +155,6 @@ extension ConversationListViewController {
self.notificationCenter = notificationCenter
self.mainCoordinator = mainCoordinator
self.getUserAccountImageSourceUseCase = getUserAccountImageSourceUseCase
self.selfProfileViewsMonitor = SelfProfileViewsMonitorImplementation()
super.init()

updateE2EICertifiedStatus()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ struct ZClientControllerBuilder {
func build(router: AuthenticatedRouterProtocol) -> ZClientViewController {
let viewController = ZClientViewController(
account: account,
selfProfileViewsMonitor: SelfProfileViewsMonitorImplementation(),
userSession: userSession,
trackingManager: trackingManager
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import WireFoundation
import WireLogging
import WireSyncEngine

protocol SelfProfileViewsMonitor {
public protocol SelfProfileViewsMonitor {
var didViewSelfProfile: Bool { get }

func onDidViewSelfProfile()
Expand Down

0 comments on commit b6cf70c

Please sign in to comment.