Skip to content

Commit

Permalink
RUM-6263 Clean up
Browse files Browse the repository at this point in the history
  • Loading branch information
maciejburda committed Oct 21, 2024
1 parent e0ac222 commit 2c0baea
Show file tree
Hide file tree
Showing 7 changed files with 18 additions and 49 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
#if os(iOS)
import Foundation
import DatadogInternal
import UIKit

/// Object is responsible for getting the RUM context, randomising the sampling rate,
/// managing the recording state, starting/stopping the recording,
Expand Down
3 changes: 3 additions & 0 deletions DatadogSessionReplay/Sources/Recorder/RecordingTrigger.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
* This product includes software developed at Datadog (https://www.datadoghq.com/).
* Copyright 2019-Present Datadog, Inc.
*/

#if os(iOS)
import DatadogInternal
import UIKit

Expand Down Expand Up @@ -57,3 +59,4 @@ internal class RecordingTrigger: UIViewHandler, UIEventHandler {
recordingCoordinator?.captureNextRecord()
}
}
#endif
2 changes: 2 additions & 0 deletions DatadogSessionReplay/Sources/Recorder/UIViewSwizzler.swift
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
* Copyright 2019-Present Datadog, Inc.
*/

#if os(iOS)
import UIKit
import DatadogInternal

Expand Down Expand Up @@ -53,3 +54,4 @@ internal class UIViewSwizzler {
}
}
}
#endif
14 changes: 7 additions & 7 deletions DatadogSessionReplay/Tests/Mocks/RecordingCoordinatorSpy.swift
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
//
// RecordingCoordinatorSpy.swift
// Datadog
//
// Created by Maciej Burda on 08/10/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)
@testable import DatadogSessionReplay

class RecordingCoordinatorSpy: RecordingCoordinating {
Expand All @@ -28,3 +27,4 @@ class RecordingCoordinatorSpy: RecordingCoordinating {
captureNextRecordCalledCount += 1
}
}
#endif
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class RecordingCoordinatorTests: XCTestCase {
private lazy var contextPublisher: SRContextPublisher = {
SRContextPublisher(core: core)
}()
private let queue = TestSyncQueue()
private let queue = NoQueue()

override func setUpWithError() throws {
core = PassthroughCoreMock()
Expand Down Expand Up @@ -188,33 +188,6 @@ class RecordingCoordinatorTests: XCTestCase {
XCTAssertEqual(recordingMock.captureNextRecordCallsCount, 1)
}

func test_whenStartRecordingImmediatelyIsTrue_itShouldRecord() throws {
// Given
prepareRecordingCoordinator(startRecordingImmediately: true)

// When
let rumContext = RUMContext.mockRandom()
rumContextObserver.notify(rumContext: rumContext)
recordingCoordinator?.captureNextRecord()

// Then
XCTAssertEqual(try core.context.baggages["sr_has_replay"]?.decode(), true)
XCTAssertEqual(recordingMock.captureNextRecordCallsCount, 1)
}

func test_whenStartRecordingImmediatelyIsFalse_shouldNotRecord() throws {
// Given
prepareRecordingCoordinator(startRecordingImmediately: false)

// When
let rumContext = RUMContext.mockRandom()
rumContextObserver.notify(rumContext: rumContext)

// Then
XCTAssertEqual(try core.context.baggages["sr_has_replay"]?.decode(), false)
XCTAssertEqual(recordingMock.captureNextRecordCallsCount, 0)
}

// MARK: Start / Stop API Tests

func test_whenStopRecording_shouldStopRecord() throws {
Expand Down Expand Up @@ -264,8 +237,7 @@ class RecordingCoordinatorTests: XCTestCase {
imagePrivacy: ImagePrivacyLevel = .maskNonBundledOnly,
touchPrivacy: TouchPrivacyLevel = .show,
telemetry: Telemetry = NOPTelemetry(),
methodCallTelemetrySamplingRate: Float = 0,
startRecordingImmediately: Bool = true
methodCallTelemetrySamplingRate: Float = 0
) {
recordingCoordinator = RecordingCoordinator(
textAndInputPrivacy: textAndInputPrivacy,
Expand All @@ -276,7 +248,6 @@ class RecordingCoordinatorTests: XCTestCase {
recorder: recordingMock,
sampler: sampler,
telemetry: telemetry,
startRecordingImmediately: startRecordingImmediately,
methodCallTelemetrySamplingRate: methodCallTelemetrySamplingRate,
queue: queue
)
Expand All @@ -301,10 +272,4 @@ final class RecordingMock: Recording {
try captureNextRecordClosure?(recorderContext)
}
}

final class TestSyncQueue: Queue {
func run(_ block: @escaping () -> Void) {
block()
}
}
#endif
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
* Copyright 2019-Present Datadog, Inc.
*/

#if os(iOS)
import XCTest
@testable import DatadogSessionReplay

Expand Down Expand Up @@ -67,7 +68,7 @@ class RecordingTriggerTests: XCTestCase {
XCTAssertEqual(recordingCoordinatorSpy.captureNextRecordCalledCount, 0)
}

func testStartsWatchingImmediately() {
func testStartsWatchingImmediately() throws {
recordingCoordinatorSpy = RecordingCoordinatorSpy()
recordingTrigger = try RecordingTrigger(
recordingCoordinator: recordingCoordinatorSpy,
Expand All @@ -88,3 +89,4 @@ class RecordingTriggerTests: XCTestCase {
}
}
}
#endif
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,9 @@

#if os(iOS)
import XCTest
//@testable import DatadogInternal
//@_spi(Internal)
@testable import DatadogSessionReplay

class UIApplicationSwizzlerTests: XCTestCase {
class UIViewSwizzlerTests: XCTestCase {
private let handler = UIViewHandlerMock()
private lazy var swizzler = try! UIViewSwizzler(handler: handler)

Expand Down

0 comments on commit 2c0baea

Please sign in to comment.