@@ -1514,6 +1514,72 @@ class SentryHubTests: XCTestCase {
15141514
15151515 XCTAssertEqual ( expected, span. sampled)
15161516 }
1517+
1518+ #if canImport(UIKit) && !SENTRY_NO_UIKIT
1519+ #if os(iOS) || os(tvOS)
1520+ func testGetSessionReplayId_ReturnsNilWhenIntegrationNotInstalled( ) {
1521+ let result = sut. getSessionReplayId ( )
1522+ XCTAssertNil ( result)
1523+ }
1524+
1525+ func testGetSessionReplayId_ReturnsNilWhenSessionReplayIsNil( ) {
1526+ let integration = SentrySessionReplayIntegration ( )
1527+ sut. addInstalledIntegration ( integration, name: " SentrySessionReplayIntegration " )
1528+
1529+ let result = sut. getSessionReplayId ( )
1530+
1531+ XCTAssertNil ( result)
1532+ }
1533+
1534+ func testGetSessionReplayId_ReturnsNilWhenSessionReplayIdIsNil( ) {
1535+ let integration = SentrySessionReplayIntegration ( )
1536+ let mockSessionReplay = createMockSessionReplay ( )
1537+ Dynamic ( integration) . sessionReplay = mockSessionReplay
1538+ sut. addInstalledIntegration ( integration, name: " SentrySessionReplayIntegration " )
1539+
1540+ let result = sut. getSessionReplayId ( )
1541+
1542+ XCTAssertNil ( result)
1543+ }
1544+
1545+ func testGetSessionReplayId_ReturnsIdStringWhenSessionReplayIdExists( ) {
1546+ let integration = SentrySessionReplayIntegration ( )
1547+ let mockSessionReplay = createMockSessionReplay ( )
1548+ let rootView = UIView ( )
1549+ mockSessionReplay. start ( rootView: rootView, fullSession: true )
1550+
1551+ Dynamic ( integration) . sessionReplay = mockSessionReplay
1552+ sut. addInstalledIntegration ( integration, name: " SentrySessionReplayIntegration " )
1553+
1554+ let result = sut. getSessionReplayId ( )
1555+
1556+ XCTAssertNotNil ( result)
1557+ XCTAssertEqual ( result, mockSessionReplay. sessionReplayId? . sentryIdString)
1558+ }
1559+
1560+ private func createMockSessionReplay( ) -> MockSentrySessionReplay {
1561+ return MockSentrySessionReplay ( )
1562+ }
1563+
1564+ private class MockSentrySessionReplay : SentrySessionReplay {
1565+ init ( ) {
1566+ super. init (
1567+ replayOptions: SentryReplayOptions ( sessionSampleRate: 0 , onErrorSampleRate: 0 ) ,
1568+ experimentalOptions: SentryExperimentalOptions ( ) ,
1569+ replayFolderPath: FileManager . default. temporaryDirectory,
1570+ screenshotProvider: MockScreenshotProvider ( ) ,
1571+ replayMaker: MockReplayMaker ( ) ,
1572+ breadcrumbConverter: SentrySRDefaultBreadcrumbConverter ( ) ,
1573+ touchTracker: nil ,
1574+ dateProvider: TestCurrentDateProvider ( ) ,
1575+ delegate: MockReplayDelegate ( ) ,
1576+ displayLinkWrapper: TestDisplayLinkWrapper ( ) ,
1577+ environmentChecker: TestSessionReplayEnvironmentChecker ( mockedIsReliableReturnValue: true )
1578+ )
1579+ }
1580+ }
1581+ #endif
1582+ #endif
15171583}
15181584
15191585#if os(iOS) || os(tvOS) || targetEnvironment(macCatalyst)
@@ -1527,6 +1593,30 @@ class TestTimeToDisplayTracker: SentryTimeToDisplayTracker {
15271593 override func reportFullyDisplayed( ) {
15281594 registerFullDisplayCalled = true
15291595 }
1530-
15311596}
15321597#endif
1598+
1599+ #if canImport(UIKit) && !SENTRY_NO_UIKIT
1600+ #if os(iOS) || os(tvOS)
1601+ private class MockScreenshotProvider : NSObject , SentryViewScreenshotProvider {
1602+ func image( view: UIView , onComplete: @escaping Sentry . ScreenshotCallback ) {
1603+ onComplete ( UIImage ( ) )
1604+ }
1605+ }
1606+
1607+ private class MockReplayDelegate : NSObject , SentrySessionReplayDelegate {
1608+ func sessionReplayShouldCaptureReplayForError( ) -> Bool { return true }
1609+ func sessionReplayNewSegment( replayEvent: SentryReplayEvent , replayRecording: SentryReplayRecording , videoUrl: URL ) { }
1610+ func sessionReplayStarted( replayId: SentryId ) { }
1611+ func breadcrumbsForSessionReplay( ) -> [ Breadcrumb ] { return [ ] }
1612+ func currentScreenNameForSessionReplay( ) -> String ? { return nil }
1613+ }
1614+
1615+ private class MockReplayMaker : NSObject , SentryReplayVideoMaker {
1616+ func createVideoInBackgroundWith( beginning: Date , end: Date , completion: @escaping ( [ Sentry . SentryVideoInfo ] ) -> Void ) { }
1617+ func createVideoWith( beginning: Date , end: Date ) -> [ Sentry . SentryVideoInfo ] { return [ ] }
1618+ func addFrameAsync( timestamp: Date , maskedViewImage: UIImage , forScreen: String ? ) { }
1619+ func releaseFramesUntil( _ date: Date ) { }
1620+ }
1621+ #endif
1622+ #endif
0 commit comments