From f798be8a01482b6ac48f7b63df67d094d77b70a2 Mon Sep 17 00:00:00 2001 From: Marie Denis Date: Wed, 23 Oct 2024 12:09:23 +0200 Subject: [PATCH] Address CR comments on hide override --- .../UIView+SessionReplayPrivacyOverrides+objc.swift | 11 ++--------- .../Tests/DDSessionReplayOverridesTests.swift | 10 +++++----- .../Tests/Mocks/PrivacyOverridesMock+objc.swift | 8 ++------ 3 files changed, 9 insertions(+), 20 deletions(-) diff --git a/DatadogSessionReplay/Sources/UIView+SessionReplayPrivacyOverrides+objc.swift b/DatadogSessionReplay/Sources/UIView+SessionReplayPrivacyOverrides+objc.swift index 2f57516a9..b91cfe65b 100644 --- a/DatadogSessionReplay/Sources/UIView+SessionReplayPrivacyOverrides+objc.swift +++ b/DatadogSessionReplay/Sources/UIView+SessionReplayPrivacyOverrides+objc.swift @@ -54,15 +54,8 @@ public final class objc_SessionReplayPrivacyOverrides: NSObject { /// Hidden privacy override (e.g., mark a view as hidden, rendering it as an opaque wireframe in replays). @objc public var hide: NSNumber? { - get { - guard let hide = _swift.hide else { - return nil - } - return NSNumber(value: hide) - } - set { - _swift.hide = newValue?.boolValue - } + get { _swift.hide.map { NSNumber(value: $0) } } + set { _swift.hide = newValue?.boolValue } } } diff --git a/DatadogSessionReplay/Tests/DDSessionReplayOverridesTests.swift b/DatadogSessionReplay/Tests/DDSessionReplayOverridesTests.swift index d8b4d9135..9ed8a59bb 100644 --- a/DatadogSessionReplay/Tests/DDSessionReplayOverridesTests.swift +++ b/DatadogSessionReplay/Tests/DDSessionReplayOverridesTests.swift @@ -80,7 +80,7 @@ class DDSessionReplayOverrideTests: XCTestCase { let textAndInputPrivacy: objc_TextAndInputPrivacyLevelOverride = .mockRandom() let imagePrivacy: objc_ImagePrivacyLevelOverride = .mockRandom() let touchPrivacy: objc_TouchPrivacyLevelOverride = .mockRandom() - let hidePrivacy = NSNumber.mockRandomHidePrivacy() + let hidePrivacy = NSNumber.mockRandomBoolean() // When let overrides = objc_SessionReplayPrivacyOverrides(view: UIView()) @@ -114,7 +114,7 @@ class DDSessionReplayOverrideTests: XCTestCase { let textAndInputPrivacy: objc_TextAndInputPrivacyLevelOverride = .mockRandom() let imagePrivacy: objc_ImagePrivacyLevelOverride = .mockRandom() let touchPrivacy: objc_TouchPrivacyLevelOverride = .mockRandom() - let hidePrivacy = NSNumber.mockRandomHidePrivacy() + let hidePrivacy = NSNumber.mockRandomBoolean() // When view.ddSessionReplayPrivacyOverrides.textAndInputPrivacy = textAndInputPrivacy @@ -147,7 +147,7 @@ class DDSessionReplayOverrideTests: XCTestCase { let textAndInputPrivacy: objc_TextAndInputPrivacyLevelOverride = .mockRandom() let imagePrivacy: objc_ImagePrivacyLevelOverride = .mockRandom() let touchPrivacy: objc_TouchPrivacyLevelOverride = .mockRandom() - let hidePrivacy = NSNumber.mockRandomHidePrivacy() + let hidePrivacy = NSNumber.mockRandomBoolean() // When (set in Swift) view.dd.sessionReplayPrivacyOverrides.textAndInputPrivacy = textAndInputPrivacy._swift @@ -168,7 +168,7 @@ class DDSessionReplayOverrideTests: XCTestCase { let textAndInputPrivacy: objc_TextAndInputPrivacyLevelOverride = .mockRandom() let imagePrivacy: objc_ImagePrivacyLevelOverride = .mockRandom() let touchPrivacy: objc_TouchPrivacyLevelOverride = .mockRandom() - let hidePrivacy = NSNumber.mockRandomHidePrivacy() + let hidePrivacy = NSNumber.mockRandomBoolean() // When (set in ObjC) view.ddSessionReplayPrivacyOverrides.textAndInputPrivacy = textAndInputPrivacy @@ -192,7 +192,7 @@ class DDSessionReplayOverrideTests: XCTestCase { tempView.ddSessionReplayPrivacyOverrides.textAndInputPrivacy = .mockRandom() tempView.ddSessionReplayPrivacyOverrides.imagePrivacy = .mockRandom() tempView.ddSessionReplayPrivacyOverrides.touchPrivacy = .mockRandom() - tempView.ddSessionReplayPrivacyOverrides.hide = NSNumber.mockRandomHidePrivacy() + tempView.ddSessionReplayPrivacyOverrides.hide = NSNumber.mockRandomBoolean() } XCTAssertNil(view?.ddSessionReplayPrivacyOverrides.textAndInputPrivacy) diff --git a/DatadogSessionReplay/Tests/Mocks/PrivacyOverridesMock+objc.swift b/DatadogSessionReplay/Tests/Mocks/PrivacyOverridesMock+objc.swift index 807a011ee..c8cb56690 100644 --- a/DatadogSessionReplay/Tests/Mocks/PrivacyOverridesMock+objc.swift +++ b/DatadogSessionReplay/Tests/Mocks/PrivacyOverridesMock+objc.swift @@ -42,12 +42,8 @@ extension objc_TouchPrivacyLevelOverride: AnyMockable, RandomMockable { } extension NSNumber { - static func mockAnyHidePrivacy() -> NSNumber? { - return NSNumber(value: true) - } - - static func mockRandomHidePrivacy() -> NSNumber? { - return [true, false].randomElement().map { NSNumber(value: $0) } ?? nil + static func mockRandomBoolean() -> NSNumber? { + NSNumber(value: [true, false].randomElement()!) } } #endif