Skip to content

Commit

Permalink
PrivacyProtectionStatusTests
Browse files Browse the repository at this point in the history
  • Loading branch information
tomasstrba committed Mar 8, 2024
1 parent a762cb2 commit ff0defc
Show file tree
Hide file tree
Showing 4 changed files with 83 additions and 10 deletions.
22 changes: 14 additions & 8 deletions DuckDuckGo.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,9 @@
1D220BF82B86192200F8BBC6 /* PreferencesEmailProtectionView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1D220BF72B86192200F8BBC6 /* PreferencesEmailProtectionView.swift */; };
1D220BF92B86192200F8BBC6 /* PreferencesEmailProtectionView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1D220BF72B86192200F8BBC6 /* PreferencesEmailProtectionView.swift */; };
1D220BFA2B86192200F8BBC6 /* PreferencesEmailProtectionView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1D220BF72B86192200F8BBC6 /* PreferencesEmailProtectionView.swift */; };
1D220BFC2B87AACF00F8BBC6 /* PreferencesProtectionStatus.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1D220BFB2B87AACF00F8BBC6 /* PreferencesProtectionStatus.swift */; };
1D220BFD2B87AACF00F8BBC6 /* PreferencesProtectionStatus.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1D220BFB2B87AACF00F8BBC6 /* PreferencesProtectionStatus.swift */; };
1D220BFE2B87AACF00F8BBC6 /* PreferencesProtectionStatus.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1D220BFB2B87AACF00F8BBC6 /* PreferencesProtectionStatus.swift */; };
1D220BFC2B87AACF00F8BBC6 /* PrivacyProtectionStatus.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1D220BFB2B87AACF00F8BBC6 /* PrivacyProtectionStatus.swift */; };
1D220BFD2B87AACF00F8BBC6 /* PrivacyProtectionStatus.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1D220BFB2B87AACF00F8BBC6 /* PrivacyProtectionStatus.swift */; };
1D220BFE2B87AACF00F8BBC6 /* PrivacyProtectionStatus.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1D220BFB2B87AACF00F8BBC6 /* PrivacyProtectionStatus.swift */; };
1D26EBAC2B74BECB0002A93F /* NSImageSendable.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1D26EBAB2B74BECB0002A93F /* NSImageSendable.swift */; };
1D26EBAD2B74BECB0002A93F /* NSImageSendable.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1D26EBAB2B74BECB0002A93F /* NSImageSendable.swift */; };
1D26EBAE2B74BECB0002A93F /* NSImageSendable.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1D26EBAB2B74BECB0002A93F /* NSImageSendable.swift */; };
Expand Down Expand Up @@ -100,6 +100,8 @@
1D9FDEC12B9B5FEA0040B78C /* AccessibilityPreferencesTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1D9FDEBF2B9B5FEA0040B78C /* AccessibilityPreferencesTests.swift */; };
1D9FDEC32B9B63C90040B78C /* DataClearingPreferencesTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1D9FDEC22B9B63C90040B78C /* DataClearingPreferencesTests.swift */; };
1D9FDEC42B9B63C90040B78C /* DataClearingPreferencesTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1D9FDEC22B9B63C90040B78C /* DataClearingPreferencesTests.swift */; };
1D9FDEC62B9B64DB0040B78C /* PrivacyProtectionStatusTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1D9FDEC52B9B64DB0040B78C /* PrivacyProtectionStatusTests.swift */; };
1D9FDEC72B9B64DB0040B78C /* PrivacyProtectionStatusTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1D9FDEC52B9B64DB0040B78C /* PrivacyProtectionStatusTests.swift */; };
1DA6D0FD2A1FF9A100540406 /* HTTPCookie.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1DA6D0FC2A1FF9A100540406 /* HTTPCookie.swift */; };
1DA6D0FE2A1FF9A100540406 /* HTTPCookie.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1DA6D0FC2A1FF9A100540406 /* HTTPCookie.swift */; };
1DA6D1022A1FFA3700540406 /* HTTPCookieTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1DA6D0FF2A1FF9DC00540406 /* HTTPCookieTests.swift */; };
Expand Down Expand Up @@ -3384,7 +3386,7 @@
1D1C36E229FAE8DA001FA40C /* FaviconManagerTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FaviconManagerTests.swift; sourceTree = "<group>"; };
1D1C36E529FB019C001FA40C /* HistoryTabExtensionTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = HistoryTabExtensionTests.swift; sourceTree = "<group>"; };
1D220BF72B86192200F8BBC6 /* PreferencesEmailProtectionView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = PreferencesEmailProtectionView.swift; sourceTree = "<group>"; };
1D220BFB2B87AACF00F8BBC6 /* PreferencesProtectionStatus.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PreferencesProtectionStatus.swift; sourceTree = "<group>"; };
1D220BFB2B87AACF00F8BBC6 /* PrivacyProtectionStatus.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PrivacyProtectionStatus.swift; sourceTree = "<group>"; };
1D26EBAB2B74BECB0002A93F /* NSImageSendable.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NSImageSendable.swift; sourceTree = "<group>"; };
1D26EBAF2B74DB600002A93F /* TabSnapshotCleanupService.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TabSnapshotCleanupService.swift; sourceTree = "<group>"; };
1D36E657298AA3BA00AA485D /* InternalUserDeciderStore.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = InternalUserDeciderStore.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -3419,6 +3421,7 @@
1D9FDEBC2B9B5F0F0040B78C /* CookiePopupProtectionPreferencesTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CookiePopupProtectionPreferencesTests.swift; sourceTree = "<group>"; };
1D9FDEBF2B9B5FEA0040B78C /* AccessibilityPreferencesTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AccessibilityPreferencesTests.swift; sourceTree = "<group>"; };
1D9FDEC22B9B63C90040B78C /* DataClearingPreferencesTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DataClearingPreferencesTests.swift; sourceTree = "<group>"; };
1D9FDEC52B9B64DB0040B78C /* PrivacyProtectionStatusTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = PrivacyProtectionStatusTests.swift; sourceTree = "<group>"; };
1DA6D0FC2A1FF9A100540406 /* HTTPCookie.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = HTTPCookie.swift; sourceTree = "<group>"; };
1DA6D0FF2A1FF9DC00540406 /* HTTPCookieTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = HTTPCookieTests.swift; sourceTree = "<group>"; };
1DB67F282B6FE4A6003DF243 /* WebViewSnapshotRenderer.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = WebViewSnapshotRenderer.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -5304,7 +5307,7 @@
37CD54C127F2FDD100F1F7B9 /* DataClearingPreferences.swift */,
37F19A6628E1B43200740DC6 /* DuckPlayerPreferences.swift */,
37CD54C527F2FDD100F1F7B9 /* AboutModel.swift */,
1D220BFB2B87AACF00F8BBC6 /* PreferencesProtectionStatus.swift */,
1D220BFB2B87AACF00F8BBC6 /* PrivacyProtectionStatus.swift */,
);
path = Model;
sourceTree = "<group>";
Expand Down Expand Up @@ -5415,6 +5418,7 @@
1D9FDEBF2B9B5FEA0040B78C /* AccessibilityPreferencesTests.swift */,
1D9FDEC22B9B63C90040B78C /* DataClearingPreferencesTests.swift */,
3714B1E628EDB7FA0056C57A /* DuckPlayerPreferencesTests.swift */,
1D9FDEC52B9B64DB0040B78C /* PrivacyProtectionStatusTests.swift */,
);
path = Preferences;
sourceTree = "<group>";
Expand Down Expand Up @@ -10306,7 +10310,7 @@
3706FBF3293F65D500E42796 /* PseudoFolder.swift in Sources */,
1D26EBAD2B74BECB0002A93F /* NSImageSendable.swift in Sources */,
3706FBF5293F65D500E42796 /* PixelDataStore.swift in Sources */,
1D220BFD2B87AACF00F8BBC6 /* PreferencesProtectionStatus.swift in Sources */,
1D220BFD2B87AACF00F8BBC6 /* PrivacyProtectionStatus.swift in Sources */,
3706FBF6293F65D500E42796 /* Pixel.swift in Sources */,
3706FBF7293F65D500E42796 /* PixelEvent.swift in Sources */,
3706FBF8293F65D500E42796 /* TabBarFooter.swift in Sources */,
Expand Down Expand Up @@ -10628,6 +10632,7 @@
3706FE1C293F661700E42796 /* ConnectBitwardenViewModelTests.swift in Sources */,
4B9DB0552A983B55000927DB /* MockWaitlistStorage.swift in Sources */,
3706FE1D293F661700E42796 /* PixelStoreTests.swift in Sources */,
1D9FDEC72B9B64DB0040B78C /* PrivacyProtectionStatusTests.swift in Sources */,
857E44642A9F70F200ED77A7 /* CampaignVariantTests.swift in Sources */,
3706FE1E293F661700E42796 /* GeolocationProviderTests.swift in Sources */,
9F39106A2B68D87B00CB5112 /* ProgressExtensionTests.swift in Sources */,
Expand Down Expand Up @@ -11167,7 +11172,7 @@
4B9579E02AC7AE700062CA31 /* BookmarkExtension.swift in Sources */,
4B9579E12AC7AE700062CA31 /* PasswordManagementCreditCardModel.swift in Sources */,
B677FC522B06376B0099EB04 /* ReportFeedbackView.swift in Sources */,
1D220BFE2B87AACF00F8BBC6 /* PreferencesProtectionStatus.swift in Sources */,
1D220BFE2B87AACF00F8BBC6 /* PrivacyProtectionStatus.swift in Sources */,
4B9579E22AC7AE700062CA31 /* NSEventExtension.swift in Sources */,
1D26EBB22B74DB600002A93F /* TabSnapshotCleanupService.swift in Sources */,
4B9579E32AC7AE700062CA31 /* Onboarding.swift in Sources */,
Expand Down Expand Up @@ -11978,7 +11983,7 @@
98779A0029999B64005D8EB6 /* Bookmark.xcdatamodeld in Sources */,
85589E9E27BFE4500038AD11 /* DefaultBrowserPromptView.swift in Sources */,
4B4032842AAAC24400CCA602 /* WaitlistActivationDateStore.swift in Sources */,
1D220BFC2B87AACF00F8BBC6 /* PreferencesProtectionStatus.swift in Sources */,
1D220BFC2B87AACF00F8BBC6 /* PrivacyProtectionStatus.swift in Sources */,
AA512D1424D99D9800230283 /* FaviconManager.swift in Sources */,
7BB108592A43375D000AB95F /* PFMoveApplication.m in Sources */,
4B0AACAC28BC63ED001038AC /* ChromiumFaviconsReader.swift in Sources */,
Expand Down Expand Up @@ -12555,6 +12560,7 @@
B662D3DE275613BB0035D4D6 /* EncryptionKeyStoreMock.swift in Sources */,
1D3B1ABF29369FC8006F4388 /* BWEncryptionTests.swift in Sources */,
B6F56567299A414300A04298 /* WKWebViewMockingExtension.swift in Sources */,
1D9FDEC62B9B64DB0040B78C /* PrivacyProtectionStatusTests.swift in Sources */,
B6656E122B29E3BE008798A1 /* DownloadListStoreMock.swift in Sources */,
37D23780287EFEE200BCE03B /* PinnedTabsManagerTests.swift in Sources */,
AA0877BA26D5161D00B05660 /* WebKitVersionProviderTests.swift in Sources */,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//
// PreferencesProtectionStatus.swift
// PrivacyProtectionStatus.swift
//
// Copyright © 2024 DuckDuckGo. All rights reserved.
//
Expand Down
2 changes: 1 addition & 1 deletion DuckDuckGo/Preferences/View/PreferencesSidebar.swift
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ extension Preferences {
}
}

enum StatusIndicator {
enum StatusIndicator: Equatable {
case alwaysOn
case on
case off
Expand Down
67 changes: 67 additions & 0 deletions UnitTests/Preferences/PrivacyProtectionStatusTests.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
//
// PrivacyProtectionStatusTests.swift
//
// Copyright © 2022 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 XCTest
import Combine
@testable import DuckDuckGo_Privacy_Browser

class PrivacyProtectionStatusTests: XCTestCase {

var cancellables: Set<AnyCancellable> = []

override func tearDown() {
super.tearDown()
cancellables.removeAll()
}

func testWhenStatusUpdatedFromPublisherThenReflectsNewStatus() {
// Example of how you might test updates from a publisher
let subject = PassthroughSubject<Bool, Never>()
let status = PrivacyProtectionStatus(statusPublisher: subject) { isOn in
return isOn ? .on : .off
}

// Initial value should be nil
XCTAssertNil(status.status)

let expectation = XCTestExpectation(description: "Status updates to .on")
status.$status.sink { newStatus in
if newStatus == .on {
expectation.fulfill()
}
}.store(in: &cancellables)

subject.send(true)

wait(for: [expectation], timeout: 1.0)
}

func testWhenInitializedWithStaticStatusIndicatorThenSetsStatusCorrectly() {
// Test initialization with a static status indicator
let status = PrivacyProtectionStatus(statusIndicator: .on)

XCTAssertEqual(status.status, .on)
}

func testWhenInitializedWithoutStatusThenStatusIsNil() {
// Test initialization without a status
let status = PrivacyProtectionStatus()

XCTAssertNil(status.status)
}
}

0 comments on commit ff0defc

Please sign in to comment.