Skip to content

Commit

Permalink
Add Settings VM and tests
Browse files Browse the repository at this point in the history
  • Loading branch information
alessandroboron committed Dec 17, 2024
1 parent 7dc8fb1 commit f4eaebe
Show file tree
Hide file tree
Showing 7 changed files with 247 additions and 86 deletions.
22 changes: 17 additions & 5 deletions DuckDuckGo.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -754,6 +754,7 @@
9F06EB7D2D0AEBD000905426 /* MaliciousSiteProtectionManagerTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9F06EB7C2D0AEBD000905426 /* MaliciousSiteProtectionManagerTests.swift */; };
9F06EB822D0AEE1F00905426 /* MaliciousSiteProtectionMocks.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9F06EB802D0AEE1F00905426 /* MaliciousSiteProtectionMocks.swift */; };
9F06EB872D0C733B00905426 /* MaliciousSiteProtectionPreferencesManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9F06EB862D0C733900905426 /* MaliciousSiteProtectionPreferencesManager.swift */; };
9F06EB8C2D10578000905426 /* MaliciousSiteProtectionSettingsViewModelTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9F06EB8B2D10578000905426 /* MaliciousSiteProtectionSettingsViewModelTests.swift */; };
9F06EB922D10740500905426 /* MaliciousSiteProtectionPreferencesManagerTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9F06EB912D10740500905426 /* MaliciousSiteProtectionPreferencesManagerTests.swift */; };
9F16230B2CA0F0190093C4FC /* DebouncerTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9F16230A2CA0F0190093C4FC /* DebouncerTests.swift */; };
9F1798572CD2443F0073018B /* AddToDockPromoViewModelTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9F1798562CD2443F0073018B /* AddToDockPromoViewModelTests.swift */; };
Expand Down Expand Up @@ -823,7 +824,7 @@
9F9A92342C86B42B001D036D /* AppIconPicker.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9F9A92332C86B42B001D036D /* AppIconPicker.swift */; };
9F9EE4CE2C377D4900D4118E /* OnboardingFirePixelMock.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9F9EE4CC2C377D3F00D4118E /* OnboardingFirePixelMock.swift */; };
9F9EE4D42C37BB1300D4118E /* OnboardingView+Landing.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9F9EE4D32C37BB1300D4118E /* OnboardingView+Landing.swift */; };
9F9F325A2CEFA75100211B49 /* SettingsViewModel+ThreatDetection.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9F9F32592CEFA74600211B49 /* SettingsViewModel+ThreatDetection.swift */; };
9F9F325A2CEFA75100211B49 /* MaliciousSiteProtectionSettingsViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9F9F32592CEFA74600211B49 /* MaliciousSiteProtectionSettingsViewModel.swift */; };
9FA5E44B2BF1AF3400BDEF02 /* SubscriptionContainerViewFactory.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9FA5E44A2BF1AF3400BDEF02 /* SubscriptionContainerViewFactory.swift */; };
9FB027122C2526DD009EA190 /* OnboardingView+IntroDialogContent.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9FB027112C2526DD009EA190 /* OnboardingView+IntroDialogContent.swift */; };
9FB027142C252E0C009EA190 /* OnboardingView+BrowsersComparisonContent.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9FB027132C252E0C009EA190 /* OnboardingView+BrowsersComparisonContent.swift */; };
Expand Down Expand Up @@ -2629,6 +2630,7 @@
9F06EB7C2D0AEBD000905426 /* MaliciousSiteProtectionManagerTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MaliciousSiteProtectionManagerTests.swift; sourceTree = "<group>"; };
9F06EB802D0AEE1F00905426 /* MaliciousSiteProtectionMocks.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MaliciousSiteProtectionMocks.swift; sourceTree = "<group>"; };
9F06EB862D0C733900905426 /* MaliciousSiteProtectionPreferencesManager.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MaliciousSiteProtectionPreferencesManager.swift; sourceTree = "<group>"; };
9F06EB8B2D10578000905426 /* MaliciousSiteProtectionSettingsViewModelTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MaliciousSiteProtectionSettingsViewModelTests.swift; sourceTree = "<group>"; };
9F06EB912D10740500905426 /* MaliciousSiteProtectionPreferencesManagerTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MaliciousSiteProtectionPreferencesManagerTests.swift; sourceTree = "<group>"; };
9F16230A2CA0F0190093C4FC /* DebouncerTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DebouncerTests.swift; sourceTree = "<group>"; };
9F1798562CD2443F0073018B /* AddToDockPromoViewModelTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AddToDockPromoViewModelTests.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -2695,7 +2697,7 @@
9F9A92332C86B42B001D036D /* AppIconPicker.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppIconPicker.swift; sourceTree = "<group>"; };
9F9EE4CC2C377D3F00D4118E /* OnboardingFirePixelMock.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = OnboardingFirePixelMock.swift; sourceTree = "<group>"; };
9F9EE4D32C37BB1300D4118E /* OnboardingView+Landing.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "OnboardingView+Landing.swift"; sourceTree = "<group>"; };
9F9F32592CEFA74600211B49 /* SettingsViewModel+ThreatDetection.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "SettingsViewModel+ThreatDetection.swift"; sourceTree = "<group>"; };
9F9F32592CEFA74600211B49 /* MaliciousSiteProtectionSettingsViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MaliciousSiteProtectionSettingsViewModel.swift; sourceTree = "<group>"; };
9FA5E44A2BF1AF3400BDEF02 /* SubscriptionContainerViewFactory.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SubscriptionContainerViewFactory.swift; sourceTree = "<group>"; };
9FB027112C2526DD009EA190 /* OnboardingView+IntroDialogContent.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "OnboardingView+IntroDialogContent.swift"; sourceTree = "<group>"; };
9FB027132C252E0C009EA190 /* OnboardingView+BrowsersComparisonContent.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "OnboardingView+BrowsersComparisonContent.swift"; sourceTree = "<group>"; };
Expand Down Expand Up @@ -5011,6 +5013,7 @@
9F06EB7F2D0AEE0600905426 /* Mocks */,
9F06EB792D09EC2000905426 /* MaliciousSiteProtectionFeatureFlagsTests.swift */,
9F06EB7C2D0AEBD000905426 /* MaliciousSiteProtectionManagerTests.swift */,
9F06EB8B2D10578000905426 /* MaliciousSiteProtectionSettingsViewModelTests.swift */,
9F06EB912D10740500905426 /* MaliciousSiteProtectionPreferencesManagerTests.swift */,
);
path = MaliciousSiteProtection;
Expand All @@ -5019,6 +5022,7 @@
9F06EB7F2D0AEE0600905426 /* Mocks */ = {
isa = PBXGroup;
children = (
9FBC76692CFE3802008B21E7 /* MockMaliciousSiteProtectionManager.swift */,
9F06EB802D0AEE1F00905426 /* MaliciousSiteProtectionMocks.swift */,
);
path = Mocks;
Expand All @@ -5032,6 +5036,14 @@
path = UserPreferences;
sourceTree = "<group>";
};
9F06EB882D0D737500905426 /* Settings */ = {
isa = PBXGroup;
children = (
9F9F32592CEFA74600211B49 /* MaliciousSiteProtectionSettingsViewModel.swift */,
);
path = Settings;
sourceTree = "<group>";
};
9F23B7FF2C2BABE000950875 /* OnboardingIntro */ = {
isa = PBXGroup;
children = (
Expand Down Expand Up @@ -5086,6 +5098,7 @@
9F254AA92CF47CD30063B308 /* MaliciousSiteProtection */ = {
isa = PBXGroup;
children = (
9F06EB882D0D737500905426 /* Settings */,
9F06EB852D0C733100905426 /* UserPreferences */,
9F06EB742D09E8D200905426 /* FeatureFlags */,
9F254AF22CF8E1F30063B308 /* Resources */,
Expand Down Expand Up @@ -5116,7 +5129,6 @@
9F254AD72CF605310063B308 /* MockSSLErrorPageNavigationHandler.swift */,
9F254ADA2CF6120E0063B308 /* MockSpecialErrorPageNavigationDelegate.swift */,
9F254ADD2CF636CF0063B308 /* DummyWKNavigation.swift */,
9FBC76692CFE3802008B21E7 /* MockMaliciousSiteProtectionManager.swift */,
);
path = TestDoubles;
sourceTree = "<group>";
Expand Down Expand Up @@ -5861,7 +5873,6 @@
children = (
D6E83C5F2B22B3C9006C8AFB /* SettingsState.swift */,
D6E83C2D2B1EA06E006C8AFB /* SettingsViewModel.swift */,
9F9F32592CEFA74600211B49 /* SettingsViewModel+ThreatDetection.swift */,
D6E83C552B21ECC1006C8AFB /* SettingsLegacyViewProvider.swift */,
85449EFC23FDA71F00512AAF /* KeyboardSettings.swift */,
4B53648926718D0E001AA041 /* EmailWaitlist.swift */,
Expand Down Expand Up @@ -8150,7 +8161,7 @@
EEC02C142B0519DE0045CE11 /* NetworkProtectionVPNLocationViewModel.swift in Sources */,
D63FF8962C1B67E9006DE24D /* YoutubeOverlayUserScript.swift in Sources */,
9F38A28C2D09BDE500EB100E /* SpecialErrorPageThreatProvider.swift in Sources */,
9F9F325A2CEFA75100211B49 /* SettingsViewModel+ThreatDetection.swift in Sources */,
9F9F325A2CEFA75100211B49 /* MaliciousSiteProtectionSettingsViewModel.swift in Sources */,
F13B4BC01F180D8A00814661 /* TabsModel.swift in Sources */,
8598D2E02CEB98B500C45685 /* Favicons.swift in Sources */,
8598D2E12CEB98B500C45685 /* NotFoundCachingDownloader.swift in Sources */,
Expand Down Expand Up @@ -8520,6 +8531,7 @@
987130C5294AAB9F00AB05E0 /* BookmarkEditorViewModelTests.swift in Sources */,
BDFF03262BA3DA4900F324C9 /* NetworkProtectionFeatureVisibilityTests.swift in Sources */,
9F8E0F332CCA642D001EA7C5 /* VideoPlayerViewModelTests.swift in Sources */,
9F06EB8C2D10578000905426 /* MaliciousSiteProtectionSettingsViewModelTests.swift in Sources */,
D62EC3BA2C246A7000FC9D04 /* YoutublePlayerNavigationHandlerTests.swift in Sources */,
1EAABE712C99FC75003F5137 /* SubscriptionFeatureAvailabilityMock.swift in Sources */,
8341D807212D5E8D000514C2 /* HashExtensionTest.swift in Sources */,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
//
// MaliciousSiteProtectionSettingsViewModel.swift
// DuckDuckGo
//
// Copyright © 2024 DuckDuckGo. All rights reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//

import Foundation
import Combine
import Core
import SwiftUI

final class MaliciousSiteProtectionSettingsViewModel: ObservableObject {
@Published var shouldShowMaliciousSiteProtectionSection = false
@Published var isMaliciousSiteProtectionEnabled: Bool = false

var maliciousSiteProtectionBinding: Binding<Bool> {
Binding<Bool>(
get: {
self.manager.isEnabled
},
set: {
self.manager.isEnabled = $0
self.isMaliciousSiteProtectionEnabled = $0
}
)
}

private let manager: MaliciousSiteProtectionPreferencesManaging
private let featureFlagger: MaliciousSiteProtectionFeatureFlagger
private let urlOpener: URLOpener

init(
manager: MaliciousSiteProtectionPreferencesManaging = MaliciousSiteProtectionPreferencesManager(),
featureFlagger: MaliciousSiteProtectionFeatureFlagger = MaliciousSiteProtectionFeatureFlags(),
urlOpener: URLOpener = UIApplication.shared
) {
self.manager = manager
self.featureFlagger = featureFlagger
self.urlOpener = urlOpener
shouldShowMaliciousSiteProtectionSection = true //featureFlagger.isMaliciousSiteProtectionEnabled
isMaliciousSiteProtectionEnabled = manager.isEnabled
}

func learnMoreAction() {
urlOpener.open(URL.maliciousSiteProtectionLearnMore)
}
}
80 changes: 0 additions & 80 deletions DuckDuckGo/SettingsViewModel+ThreatDetection.swift

This file was deleted.

1 change: 0 additions & 1 deletion DuckDuckGo/SettingsViewModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ final class SettingsViewModel: ObservableObject {
let privacyProDataReporter: PrivacyProDataReporting?
let textZoomCoordinator: TextZoomCoordinating
let aiChatSettings: AIChatSettingsProvider
@Published var threatDetectionSettingsViewModel: ThreatDetectionSettingsViewModel = ThreatDetectionSettingsViewModel()

// Subscription Dependencies
let subscriptionManager: SubscriptionManager
Expand Down
Loading

0 comments on commit f4eaebe

Please sign in to comment.