From d27cfc718cb83615fb1b476e23e009a93d4dfc8a Mon Sep 17 00:00:00 2001 From: Marie Denis Date: Thu, 19 Sep 2024 14:49:41 +0200 Subject: [PATCH] RUM-6224 Add unit tests --- Datadog/Datadog.xcodeproj/project.pbxproj | 4 ++ .../PrivacyLevel+SessionReplay.swift | 12 ++-- .../Tests/SessionReplayOverrideTests.swift | 63 +++++++++++++++++++ 3 files changed, 72 insertions(+), 7 deletions(-) create mode 100644 DatadogSessionReplay/Tests/SessionReplayOverrideTests.swift diff --git a/Datadog/Datadog.xcodeproj/project.pbxproj b/Datadog/Datadog.xcodeproj/project.pbxproj index 3dacf2608..456d70aa0 100644 --- a/Datadog/Datadog.xcodeproj/project.pbxproj +++ b/Datadog/Datadog.xcodeproj/project.pbxproj @@ -686,6 +686,7 @@ 969B3B232C33F81E00D62400 /* UIActivityIndicatorRecorderTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 969B3B222C33F81E00D62400 /* UIActivityIndicatorRecorderTests.swift */; }; 96E414142C2AF56F005A6119 /* UIProgressViewRecorder.swift in Sources */ = {isa = PBXBuildFile; fileRef = 96E414132C2AF56F005A6119 /* UIProgressViewRecorder.swift */; }; 96E414162C2AF5C1005A6119 /* UIProgressViewRecorderTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 96E414152C2AF5C1005A6119 /* UIProgressViewRecorderTests.swift */; }; + 96E863722C9C547B0023BF78 /* SessionReplayOverrideTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 96E863712C9C547B0023BF78 /* SessionReplayOverrideTests.swift */; }; 9E55407C25812D1C00F6E3AD /* RUM+objc.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9E55407B25812D1C00F6E3AD /* RUM+objc.swift */; }; 9E58E8E324615EDA008E5063 /* JSONEncoderTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9E58E8E224615EDA008E5063 /* JSONEncoderTests.swift */; }; 9E5B6D2E270C84B4002499B8 /* RUMMonitorE2ETests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9E5B6D2D270C84B4002499B8 /* RUMMonitorE2ETests.swift */; }; @@ -2730,6 +2731,7 @@ 969B3B222C33F81E00D62400 /* UIActivityIndicatorRecorderTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = UIActivityIndicatorRecorderTests.swift; sourceTree = ""; }; 96E414132C2AF56F005A6119 /* UIProgressViewRecorder.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = UIProgressViewRecorder.swift; sourceTree = ""; }; 96E414152C2AF5C1005A6119 /* UIProgressViewRecorderTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = UIProgressViewRecorderTests.swift; sourceTree = ""; }; + 96E863712C9C547B0023BF78 /* SessionReplayOverrideTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SessionReplayOverrideTests.swift; sourceTree = ""; }; 9E0542CA25F8EBBE007A3D0B /* Kronos.xcframework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.xcframework; name = Kronos.xcframework; path = ../Carthage/Build/Kronos.xcframework; sourceTree = ""; }; 9E26E6B824C87693000B3270 /* RUMDataModels.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = RUMDataModels.swift; sourceTree = ""; }; 9E2EF44E2694FA14008A7DAE /* VitalInfoSamplerTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = VitalInfoSamplerTests.swift; sourceTree = ""; }; @@ -3565,6 +3567,7 @@ 61054E022A6EE0DB00AAA894 /* DatadogSessionReplayTests */ = { isa = PBXGroup; children = ( + 96E863712C9C547B0023BF78 /* SessionReplayOverrideTests.swift */, 61054F482A6EE1B900AAA894 /* SessionReplayTests.swift */, 61054F3D2A6EE1B900AAA894 /* SessionReplayConfigurationTests.swift */, 61054F882A6EE1BA00AAA894 /* Feature */, @@ -8457,6 +8460,7 @@ 61054FB92A6EE1BA00AAA894 /* UINavigationBarRecorderTests.swift in Sources */, 61054FA62A6EE1BA00AAA894 /* SnapshotProcessorTests.swift in Sources */, 61054FB72A6EE1BA00AAA894 /* UISegmentRecorderTests.swift in Sources */, + 96E863722C9C547B0023BF78 /* SessionReplayOverrideTests.swift in Sources */, A7D9528A2B28BD94004C79B1 /* ResourceProcessorSpy.swift in Sources */, A7D9528C2B28C18D004C79B1 /* ResourceProcessorTests.swift in Sources */, A74A72892B10D95D00771FEB /* MultipartBuilderSpy.swift in Sources */, diff --git a/DatadogSessionReplay/Sources/Recorder/Utilities/PrivacyLevel+SessionReplay.swift b/DatadogSessionReplay/Sources/Recorder/Utilities/PrivacyLevel+SessionReplay.swift index 50e62d580..9140e432c 100644 --- a/DatadogSessionReplay/Sources/Recorder/Utilities/PrivacyLevel+SessionReplay.swift +++ b/DatadogSessionReplay/Sources/Recorder/Utilities/PrivacyLevel+SessionReplay.swift @@ -1,10 +1,8 @@ -// -// PrivacyLevel+SessionReplay.swift -// DatadogSessionReplay iOS -// -// Created by Marie Denis on 16/09/2024. -// Copyright © 2024 Datadog. All rights reserved. -// +/* + * Unless explicitly stated otherwise all files in this repository are licensed under the Apache License Version 2.0. + * This product includes software developed at Datadog (https://www.datadoghq.com/). + * Copyright 2019-Present Datadog, Inc. + */ #if os(iOS) import UIKit diff --git a/DatadogSessionReplay/Tests/SessionReplayOverrideTests.swift b/DatadogSessionReplay/Tests/SessionReplayOverrideTests.swift new file mode 100644 index 000000000..983c104d1 --- /dev/null +++ b/DatadogSessionReplay/Tests/SessionReplayOverrideTests.swift @@ -0,0 +1,63 @@ +/* + * Unless explicitly stated otherwise all files in this repository are licensed under the Apache License Version 2.0. + * This product includes software developed at Datadog (https://www.datadoghq.com/). + * Copyright 2019-Present Datadog, Inc. + */ + +#if os(iOS) +import XCTest +import UIKit +@testable import DatadogSessionReplay + +class SessionReplayOverrideTests: XCTestCase { + func testWhenNoOverrideIsSet_itDefaultsToNil() { + // Given + let view = UIView() + + // Then + XCTAssertNil(view.dd.sessionReplayOverride.textAndInputPrivacy) + XCTAssertNil(view.dd.sessionReplayOverride.imagePrivacy) + XCTAssertNil(view.dd.sessionReplayOverride.touchPrivacy) + XCTAssertNil(view.dd.sessionReplayOverride.hiddenPrivacy) + } + + func testWithOverrides() { + // Given + var view = UIView() + + // When + view.dd.sessionReplayOverride.textAndInputPrivacy = .maskAllInputs + view.dd.sessionReplayOverride.imagePrivacy = .maskAll + view.dd.sessionReplayOverride.touchPrivacy = .hide + view.dd.sessionReplayOverride.hiddenPrivacy = .hide + + // Then + XCTAssertEqual(view.dd.sessionReplayOverride.textAndInputPrivacy, .maskAllInputs) + XCTAssertEqual(view.dd.sessionReplayOverride.imagePrivacy, .maskAll) + XCTAssertEqual(view.dd.sessionReplayOverride.touchPrivacy, .hide) + XCTAssertEqual(view.dd.sessionReplayOverride.hiddenPrivacy, .hide) + } + + // Test that removing an override sets the property back to nil + func testRemovingOverrides() { + // Given + var view = UIView() + view.dd.sessionReplayOverride.textAndInputPrivacy = .maskAllInputs + view.dd.sessionReplayOverride.imagePrivacy = .maskAll + view.dd.sessionReplayOverride.touchPrivacy = .hide + view.dd.sessionReplayOverride.hiddenPrivacy = .hide + + // When + view.dd.sessionReplayOverride.textAndInputPrivacy = nil + view.dd.sessionReplayOverride.imagePrivacy = nil + view.dd.sessionReplayOverride.touchPrivacy = nil + view.dd.sessionReplayOverride.hiddenPrivacy = nil + + // Then + XCTAssertNil(view.dd.sessionReplayOverride.textAndInputPrivacy) + XCTAssertNil(view.dd.sessionReplayOverride.imagePrivacy) + XCTAssertNil(view.dd.sessionReplayOverride.touchPrivacy) + XCTAssertNil(view.dd.sessionReplayOverride.hiddenPrivacy) + } +} +#endif