Skip to content

Commit

Permalink
Fix unit test compilation.
Browse files Browse the repository at this point in the history
  • Loading branch information
samsymons committed Jan 17, 2024
1 parent 91f876c commit 9d55839
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 63 deletions.
5 changes: 1 addition & 4 deletions DuckDuckGo/VPNFeedbackForm/VPNMetadataCollector.swift
Original file line number Diff line number Diff line change
Expand Up @@ -65,10 +65,7 @@ struct VPNMetadata: Encodable {

struct LoginItemState: Encodable {
let vpnMenuState: String

#if NETP_SYSTEM_EXTENSION
let notificationsAgentState: String
#endif
}

let appInfo: AppInfo
Expand Down Expand Up @@ -228,7 +225,7 @@ final class DefaultVPNMetadataCollector: VPNMetadataCollector {
let notificationsAgentState = String(describing: LoginItem.notificationsAgent.status)
return .init(vpnMenuState: vpnMenuState, notificationsAgentState: notificationsAgentState)
#else
return .init(vpnMenuState: vpnMenuState)
return .init(vpnMenuState: vpnMenuState, notificationsAgentState: "not-required")
#endif
}

Expand Down
116 changes: 61 additions & 55 deletions UnitTests/HomePage/ContinueSetUpModelTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import XCTest
import BrowserServicesKit
@testable import DuckDuckGo_Privacy_Browser

#if NETWORK_PROTECTION && DBP
#if NETWORK_PROTECTION

final class MockNetworkProtectionRemoteMessaging: NetworkProtectionRemoteMessaging {

Expand All @@ -38,6 +38,10 @@ final class MockNetworkProtectionRemoteMessaging: NetworkProtectionRemoteMessagi

}

#endif

#if DBP

final class MockDataBrokerProtectionRemoteMessaging: DataBrokerProtectionRemoteMessaging {

var messages: [DataBrokerProtectionRemoteMessage] = []
Expand Down Expand Up @@ -89,30 +93,34 @@ final class ContinueSetUpModelTests: XCTestCase {
privacyConfigManager.privacyConfig = config

#if NETWORK_PROTECTION && DBP
vm = HomePage.Models.ContinueSetUpModel(
defaultBrowserProvider: capturingDefaultBrowserProvider,
dataImportProvider: capturingDataImportProvider,
tabCollectionViewModel: tabCollectionVM,
emailManager: emailManager,
privacyPreferences: privacyPreferences,
duckPlayerPreferences: duckPlayerPreferences,
let messaging = HomePageRemoteMessaging(
networkProtectionRemoteMessaging: MockNetworkProtectionRemoteMessaging(),
dataBrokerProtectionRemoteMessaging: MockDataBrokerProtectionRemoteMessaging(),
networkProtectionUserDefaults: userDefaults,
dataBrokerProtectionUserDefaults: userDefaults,
privacyConfigurationManager: privacyConfigManager
dataBrokerProtectionRemoteMessaging: MockDataBrokerProtectionRemoteMessaging(),
dataBrokerProtectionUserDefaults: userDefaults
)
#elseif NETWORK_PROTECTION
let messaging = HomePageRemoteMessaging(
networkProtectionRemoteMessaging: MockNetworkProtectionRemoteMessaging(),
networkProtectionUserDefaults: userDefaults
)
#else
#elseif DBP
let messaging = HomePageRemoteMessaging(
dataBrokerProtectionRemoteMessaging: MockDataBrokerProtectionRemoteMessaging(),
dataBrokerProtectionUserDefaults: userDefaults
)
#endif

vm = HomePage.Models.ContinueSetUpModel(
defaultBrowserProvider: capturingDefaultBrowserProvider,
dataImportProvider: capturingDataImportProvider,
tabCollectionViewModel: tabCollectionVM,
emailManager: emailManager,
privacyPreferences: privacyPreferences,
duckPlayerPreferences: duckPlayerPreferences,
homePageRemoteMessaging: messaging,
privacyConfigurationManager: privacyConfigManager
)
#endif
}

override func tearDown() {
Expand Down Expand Up @@ -148,29 +156,15 @@ final class ContinueSetUpModelTests: XCTestCase {
duckPlayerPreferences.youtubeOverlayAnyButtonPressed = true
privacyPreferences.autoconsentEnabled = true

#if NETWORK_PROTECTION && DBP
vm = HomePage.Models.ContinueSetUpModel(
defaultBrowserProvider: capturingDefaultBrowserProvider,
dataImportProvider: capturingDataImportProvider,
tabCollectionViewModel: tabCollectionVM,
emailManager: emailManager,
privacyPreferences: privacyPreferences,
duckPlayerPreferences: duckPlayerPreferences,
networkProtectionRemoteMessaging: MockNetworkProtectionRemoteMessaging(),
dataBrokerProtectionRemoteMessaging: MockDataBrokerProtectionRemoteMessaging(),
networkProtectionUserDefaults: userDefaults,
dataBrokerProtectionUserDefaults: userDefaults
)
#else
vm = HomePage.Models.ContinueSetUpModel(
defaultBrowserProvider: capturingDefaultBrowserProvider,
dataImportProvider: capturingDataImportProvider,
tabCollectionViewModel: tabCollectionVM,
emailManager: emailManager,
privacyPreferences: privacyPreferences,
duckPlayerPreferences: duckPlayerPreferences
homePageRemoteMessaging: createMessaging()
)
#endif

XCTAssertFalse(vm.isMoreOrLessButtonNeeded)
}
Expand Down Expand Up @@ -463,29 +457,15 @@ final class ContinueSetUpModelTests: XCTestCase {
userDefaults.set(false, forKey: UserDefaultsWrapper<Date>.Key.homePageShowSurveyDay0.rawValue)
userDefaults.set(false, forKey: UserDefaultsWrapper<Date>.Key.homePageShowSurveyDay7.rawValue)

#if NETWORK_PROTECTION && DBP
vm = HomePage.Models.ContinueSetUpModel(
defaultBrowserProvider: capturingDefaultBrowserProvider,
dataImportProvider: capturingDataImportProvider,
tabCollectionViewModel: tabCollectionVM,
emailManager: emailManager,
privacyPreferences: privacyPreferences,
duckPlayerPreferences: duckPlayerPreferences,
networkProtectionRemoteMessaging: MockNetworkProtectionRemoteMessaging(),
dataBrokerProtectionRemoteMessaging: MockDataBrokerProtectionRemoteMessaging(),
networkProtectionUserDefaults: userDefaults,
dataBrokerProtectionUserDefaults: userDefaults
homePageRemoteMessaging: createMessaging()
)
#else
vm = HomePage.Models.ContinueSetUpModel(
defaultBrowserProvider: capturingDefaultBrowserProvider,
dataImportProvider: capturingDataImportProvider,
tabCollectionViewModel: tabCollectionVM,
emailManager: emailManager,
privacyPreferences: privacyPreferences,
duckPlayerPreferences: duckPlayerPreferences
)
#endif

XCTAssertEqual(vm.visibleFeaturesMatrix, [[]])
}
Expand Down Expand Up @@ -545,6 +525,27 @@ final class ContinueSetUpModelTests: XCTestCase {
return features.chunked(into: HomePage.featuresPerRow)
}

private func createMessaging() -> HomePageRemoteMessaging {
#if NETWORK_PROTECTION && DBP
return HomePageRemoteMessaging(
networkProtectionRemoteMessaging: MockNetworkProtectionRemoteMessaging(),
networkProtectionUserDefaults: userDefaults,
dataBrokerProtectionRemoteMessaging: MockDataBrokerProtectionRemoteMessaging(),
dataBrokerProtectionUserDefaults: userDefaults
)
#elseif NETWORK_PROTECTION
return HomePageRemoteMessaging(
networkProtectionRemoteMessaging: MockNetworkProtectionRemoteMessaging(),
networkProtectionUserDefaults: userDefaults
)
#elseif DBP
return HomePageRemoteMessaging(
dataBrokerProtectionRemoteMessaging: MockDataBrokerProtectionRemoteMessaging(),
dataBrokerProtectionUserDefaults: userDefaults
)
#endif
}

enum SurveyDay {
case day0
case day7
Expand All @@ -570,27 +571,32 @@ extension HomePage.Models.ContinueSetUpModel {
manager.privacyConfig = privacyConfig

#if NETWORK_PROTECTION && DBP
return HomePage.Models.ContinueSetUpModel(
defaultBrowserProvider: defaultBrowserProvider,
dataImportProvider: dataImportProvider,
tabCollectionViewModel: TabCollectionViewModel(),
emailManager: emailManager,
privacyPreferences: privacyPreferences,
duckPlayerPreferences: duckPlayerPreferences,
let messaging = HomePageRemoteMessaging(
networkProtectionRemoteMessaging: MockNetworkProtectionRemoteMessaging(),
dataBrokerProtectionRemoteMessaging: MockDataBrokerProtectionRemoteMessaging(),
networkProtectionUserDefaults: appGroupUserDefaults,
dataBrokerProtectionUserDefaults: appGroupUserDefaults,
privacyConfigurationManager: manager)
#else
dataBrokerProtectionRemoteMessaging: MockDataBrokerProtectionRemoteMessaging(),
dataBrokerProtectionUserDefaults: appGroupUserDefaults
)
#elseif NETWORK_PROTECTION
let messaging = HomePageRemoteMessaging(
networkProtectionRemoteMessaging: MockNetworkProtectionRemoteMessaging(),
networkProtectionUserDefaults: appGroupUserDefaults
)
#elseif DBP
let messaging = HomePageRemoteMessaging(
dataBrokerProtectionRemoteMessaging: MockDataBrokerProtectionRemoteMessaging(),
dataBrokerProtectionUserDefaults: appGroupUserDefaults
)
#endif

return HomePage.Models.ContinueSetUpModel(
defaultBrowserProvider: defaultBrowserProvider,
dataImportProvider: dataImportProvider,
tabCollectionViewModel: TabCollectionViewModel(),
emailManager: emailManager,
privacyPreferences: privacyPreferences,
duckPlayerPreferences: duckPlayerPreferences,
homePageRemoteMessaging: messaging,
privacyConfigurationManager: manager)
#endif
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -108,10 +108,7 @@ private class MockVPNMetadataCollector: VPNMetadataCollector {
selectedEnvironment: "production"
)

let loginItemState = VPNMetadata.LoginItemState(
vpnMenuState: "enabled",
notificationsAgentState: "enabled"
)
let loginItemState = VPNMetadata.LoginItemState(vpnMenuState: "enabled", notificationsAgentState: "enabled")

return VPNMetadata(
appInfo: appInfo,
Expand Down

0 comments on commit 9d55839

Please sign in to comment.