Skip to content

Commit

Permalink
Merge f615224 into 4c3c7db
Browse files Browse the repository at this point in the history
  • Loading branch information
antonis authored Oct 30, 2024
2 parents 4c3c7db + f615224 commit c290d35
Show file tree
Hide file tree
Showing 9 changed files with 296 additions and 126 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@
## Unreleased

### Changes

- Enables Spotlight in Android and iOS SDKs ([#4211](https://github.com/getsentry/sentry-react-native/pull/4211))

### Dependencies

- Bump JavaScript SDK from v8.34.0 to v8.35.0 ([#4196](https://github.com/getsentry/sentry-react-native/pull/4196))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,16 @@ package io.sentry.react
import android.content.pm.PackageInfo
import android.content.pm.PackageManager
import com.facebook.react.bridge.Arguments
import com.facebook.react.bridge.JavaOnlyMap
import com.facebook.react.bridge.Promise
import com.facebook.react.bridge.ReactApplicationContext
import com.facebook.react.bridge.WritableMap
import io.sentry.ILogger
import io.sentry.SentryLevel
import io.sentry.android.core.SentryAndroidOptions
import org.junit.After
import org.junit.Assert.assertEquals
import org.junit.Assert.assertFalse
import org.junit.Before
import org.junit.Test
import org.junit.runner.RunWith
Expand Down Expand Up @@ -93,4 +96,33 @@ class RNSentryModuleImplTest {
val capturedMap = writableMapCaptor.value
assertEquals(false, capturedMap.getBoolean("has_fetched"))
}

@Test
fun `when the spotlight option is enabled, the spotlight SentryAndroidOption is set to true and the default url is used`() {
val options = JavaOnlyMap.of(
"spotlight", true,
"defaultSidecarUrl", "http://localhost:8969/teststream"
)
val actualOptions = SentryAndroidOptions()
module.getSentryAndroidOptions(actualOptions, options, logger)
assert(actualOptions.isEnableSpotlight)
assertEquals("http://localhost:8969/teststream", actualOptions.spotlightConnectionUrl)
}

@Test
fun `when the spotlight url is passed, the spotlight is enabled for the given url`() {
val options = JavaOnlyMap.of("spotlight", "http://localhost:8969/teststream")
val actualOptions = SentryAndroidOptions()
module.getSentryAndroidOptions(actualOptions, options, logger)
assert(actualOptions.isEnableSpotlight)
assertEquals("http://localhost:8969/teststream", actualOptions.spotlightConnectionUrl)
}

@Test
fun `when the spotlight option is disabled, the spotlight SentryAndroidOption is set to false`() {
val options = JavaOnlyMap.of("spotlight", false)
val actualOptions = SentryAndroidOptions()
module.getSentryAndroidOptions(actualOptions, options, logger)
assertFalse(actualOptions.isEnableSpotlight)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,86 @@ - (void)testCreateOptionsWithDictionaryAutoPerformanceTracingDisabled
XCTAssertEqual(actualOptions.enableAutoPerformanceTracing, false, @"Did not disable Auto Performance Tracing");
}

- (void)testCreateOptionsWithDictionarySpotlightEnabled
{
RNSentry * rnSentry = [[RNSentry alloc] init];
NSError* error = nil;

NSDictionary *_Nonnull mockedReactNativeDictionary = @{
@"dsn": @"https://[email protected]/123456",
@"spotlight": @YES,
@"defaultSidecarUrl": @"http://localhost:8969/teststream",
};
SentryOptions* actualOptions = [rnSentry createOptionsWithDictionary:mockedReactNativeDictionary error:&error];
XCTAssertNotNil(actualOptions, @"Did not create sentry options");
XCTAssertNil(error, @"Should not pass no error");
XCTAssertTrue(actualOptions.enableSpotlight , @"Did not enable spotlight");
XCTAssertEqual(actualOptions.spotlightUrl , @"http://localhost:8969/teststream");
}

- (void)testCreateOptionsWithDictionarySpotlightOne
{
RNSentry * rnSentry = [[RNSentry alloc] init];
NSError* error = nil;

NSDictionary *_Nonnull mockedReactNativeDictionary = @{
@"dsn": @"https://[email protected]/123456",
@"spotlight": @1,
@"defaultSidecarUrl": @"http://localhost:8969/teststream",
};
SentryOptions* actualOptions = [rnSentry createOptionsWithDictionary:mockedReactNativeDictionary error:&error];
XCTAssertNotNil(actualOptions, @"Did not create sentry options");
XCTAssertNil(error, @"Should not pass no error");
XCTAssertTrue(actualOptions.enableSpotlight , @"Did not enable spotlight");
XCTAssertEqual(actualOptions.spotlightUrl , @"http://localhost:8969/teststream");
}

- (void)testCreateOptionsWithDictionarySpotlightUrl
{
RNSentry * rnSentry = [[RNSentry alloc] init];
NSError* error = nil;

NSDictionary *_Nonnull mockedReactNativeDictionary = @{
@"dsn": @"https://[email protected]/123456",
@"spotlight": @"http://localhost:8969/teststream",
};
SentryOptions* actualOptions = [rnSentry createOptionsWithDictionary:mockedReactNativeDictionary error:&error];
XCTAssertNotNil(actualOptions, @"Did not create sentry options");
XCTAssertNil(error, @"Should not pass no error");
XCTAssertTrue(actualOptions.enableSpotlight , @"Did not enable spotlight");
XCTAssertEqual(actualOptions.spotlightUrl , @"http://localhost:8969/teststream");
}

- (void)testCreateOptionsWithDictionarySpotlightDisabled
{
RNSentry * rnSentry = [[RNSentry alloc] init];
NSError* error = nil;

NSDictionary *_Nonnull mockedReactNativeDictionary = @{
@"dsn": @"https://[email protected]/123456",
@"spotlight": @NO,
};
SentryOptions* actualOptions = [rnSentry createOptionsWithDictionary:mockedReactNativeDictionary error:&error];
XCTAssertNotNil(actualOptions, @"Did not create sentry options");
XCTAssertNil(error, @"Should not pass no error");
XCTAssertFalse(actualOptions.enableSpotlight, @"Did not disable spotlight");
}

- (void)testCreateOptionsWithDictionarySpotlightZero
{
RNSentry * rnSentry = [[RNSentry alloc] init];
NSError* error = nil;

NSDictionary *_Nonnull mockedReactNativeDictionary = @{
@"dsn": @"https://[email protected]/123456",
@"spotlight": @0,
};
SentryOptions* actualOptions = [rnSentry createOptionsWithDictionary:mockedReactNativeDictionary error:&error];
XCTAssertNotNil(actualOptions, @"Did not create sentry options");
XCTAssertNil(error, @"Should not pass no error");
XCTAssertFalse(actualOptions.enableSpotlight, @"Did not disable spotlight");
}

- (void)testPassesErrorOnWrongDsn
{
RNSentry * rnSentry = [[RNSentry alloc] init];
Expand Down
Loading

0 comments on commit c290d35

Please sign in to comment.