Skip to content

Commit

Permalink
Address CR comments on hide override
Browse files Browse the repository at this point in the history
  • Loading branch information
mariedm committed Oct 23, 2024
1 parent af9e61b commit f798be8
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
}
}

Expand Down
10 changes: 5 additions & 5 deletions DatadogSessionReplay/Tests/DDSessionReplayOverridesTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit f798be8

Please sign in to comment.