Skip to content

Commit

Permalink
RUM-6224 Add unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
mariedm committed Sep 19, 2024
1 parent 7291704 commit d27cfc7
Show file tree
Hide file tree
Showing 3 changed files with 72 additions and 7 deletions.
4 changes: 4 additions & 0 deletions Datadog/Datadog.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -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 */; };
Expand Down Expand Up @@ -2730,6 +2731,7 @@
969B3B222C33F81E00D62400 /* UIActivityIndicatorRecorderTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = UIActivityIndicatorRecorderTests.swift; sourceTree = "<group>"; };
96E414132C2AF56F005A6119 /* UIProgressViewRecorder.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = UIProgressViewRecorder.swift; sourceTree = "<group>"; };
96E414152C2AF5C1005A6119 /* UIProgressViewRecorderTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = UIProgressViewRecorderTests.swift; sourceTree = "<group>"; };
96E863712C9C547B0023BF78 /* SessionReplayOverrideTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SessionReplayOverrideTests.swift; sourceTree = "<group>"; };
9E0542CA25F8EBBE007A3D0B /* Kronos.xcframework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.xcframework; name = Kronos.xcframework; path = ../Carthage/Build/Kronos.xcframework; sourceTree = "<group>"; };
9E26E6B824C87693000B3270 /* RUMDataModels.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = RUMDataModels.swift; sourceTree = "<group>"; };
9E2EF44E2694FA14008A7DAE /* VitalInfoSamplerTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = VitalInfoSamplerTests.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -3565,6 +3567,7 @@
61054E022A6EE0DB00AAA894 /* DatadogSessionReplayTests */ = {
isa = PBXGroup;
children = (
96E863712C9C547B0023BF78 /* SessionReplayOverrideTests.swift */,
61054F482A6EE1B900AAA894 /* SessionReplayTests.swift */,
61054F3D2A6EE1B900AAA894 /* SessionReplayConfigurationTests.swift */,
61054F882A6EE1BA00AAA894 /* Feature */,
Expand Down Expand Up @@ -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 */,
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand Down
63 changes: 63 additions & 0 deletions DatadogSessionReplay/Tests/SessionReplayOverrideTests.swift
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit d27cfc7

Please sign in to comment.