Skip to content

Commit 8080b00

Browse files
add swift tests
1 parent 3248e9a commit 8080b00

File tree

5 files changed

+78
-2
lines changed

5 files changed

+78
-2
lines changed

RNSentryCocoaTester/RNSentryCocoaTester.xcodeproj/project.pbxproj

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
/* Begin PBXBuildFile section */
1010
330F308C2C0F3840002A0D4E /* RNSentryBreadcrumbTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 330F308B2C0F3840002A0D4E /* RNSentryBreadcrumbTests.m */; };
11+
336084392C32E382008CC412 /* RNSentryCocoaUnitTesterTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 336084382C32E382008CC412 /* RNSentryCocoaUnitTesterTests.swift */; };
1112
33958C692BFCF12600AD1FB6 /* RNSentryOnDrawReporterTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 33958C682BFCF12600AD1FB6 /* RNSentryOnDrawReporterTests.m */; };
1213
33AFDFED2B8D14B300AAB120 /* RNSentryFramesTrackerListenerTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 33AFDFEC2B8D14B300AAB120 /* RNSentryFramesTrackerListenerTests.m */; };
1314
33AFDFF12B8D15E500AAB120 /* RNSentryDependencyContainerTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 33AFDFF02B8D15E500AAB120 /* RNSentryDependencyContainerTests.m */; };
@@ -19,6 +20,9 @@
1920
1482D5685A340AB93348A43D /* Pods-RNSentryCocoaTesterTests.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-RNSentryCocoaTesterTests.release.xcconfig"; path = "Target Support Files/Pods-RNSentryCocoaTesterTests/Pods-RNSentryCocoaTesterTests.release.xcconfig"; sourceTree = "<group>"; };
2021
330F308B2C0F3840002A0D4E /* RNSentryBreadcrumbTests.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = RNSentryBreadcrumbTests.m; sourceTree = "<group>"; };
2122
330F308D2C0F385A002A0D4E /* RNSentryBreadcrumb.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = RNSentryBreadcrumb.h; path = ../ios/RNSentryBreadcrumb.h; sourceTree = "<group>"; };
23+
336084372C32E382008CC412 /* RNSentryCocoaTesterTests-Bridging-Header.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "RNSentryCocoaTesterTests-Bridging-Header.h"; sourceTree = "<group>"; };
24+
336084382C32E382008CC412 /* RNSentryCocoaUnitTesterTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = RNSentryCocoaUnitTesterTests.swift; sourceTree = "<group>"; };
25+
3360843A2C32E3A8008CC412 /* RNSentryReplayBreadcrumbConverter.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = RNSentryReplayBreadcrumbConverter.h; path = ../ios/RNSentryReplayBreadcrumbConverter.h; sourceTree = "<group>"; };
2226
3360898D29524164007C7730 /* RNSentryCocoaTesterTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = RNSentryCocoaTesterTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; };
2327
338739072A7D7D2800950DDD /* RNSentryTests.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = RNSentryTests.h; sourceTree = "<group>"; };
2428
33958C672BFCEF5A00AD1FB6 /* RNSentryOnDrawReporter.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = RNSentryOnDrawReporter.h; path = ../ios/RNSentryOnDrawReporter.h; sourceTree = "<group>"; };
@@ -76,6 +80,7 @@
7680
3360899029524164007C7730 /* RNSentryCocoaTesterTests */ = {
7781
isa = PBXGroup;
7882
children = (
83+
336084382C32E382008CC412 /* RNSentryCocoaUnitTesterTests.swift */,
7984
33F58ACF2977037D008F60EA /* RNSentryTests.mm */,
8085
338739072A7D7D2800950DDD /* RNSentryTests.h */,
8186
33AFDFEC2B8D14B300AAB120 /* RNSentryFramesTrackerListenerTests.m */,
@@ -84,13 +89,15 @@
8489
33AFDFF22B8D15F600AAB120 /* RNSentryDependencyContainerTests.h */,
8590
33958C682BFCF12600AD1FB6 /* RNSentryOnDrawReporterTests.m */,
8691
330F308B2C0F3840002A0D4E /* RNSentryBreadcrumbTests.m */,
92+
336084372C32E382008CC412 /* RNSentryCocoaTesterTests-Bridging-Header.h */,
8793
);
8894
path = RNSentryCocoaTesterTests;
8995
sourceTree = "<group>";
9096
};
9197
33AFE0122B8F319000AAB120 /* RNSentry */ = {
9298
isa = PBXGroup;
9399
children = (
100+
3360843A2C32E3A8008CC412 /* RNSentryReplayBreadcrumbConverter.h */,
94101
330F308D2C0F385A002A0D4E /* RNSentryBreadcrumb.h */,
95102
33958C672BFCEF5A00AD1FB6 /* RNSentryOnDrawReporter.h */,
96103
33AFE0132B8F31AF00AAB120 /* RNSentryDependencyContainer.h */,
@@ -134,10 +141,12 @@
134141
isa = PBXProject;
135142
attributes = {
136143
BuildIndependentTargetsInParallel = 1;
144+
LastSwiftUpdateCheck = 1540;
137145
LastUpgradeCheck = 1420;
138146
TargetAttributes = {
139147
3360898C29524164007C7730 = {
140148
CreatedOnToolsVersion = 14.2;
149+
LastSwiftMigration = 1540;
141150
};
142151
};
143152
};
@@ -207,6 +216,7 @@
207216
buildActionMask = 2147483647;
208217
files = (
209218
33AFDFF12B8D15E500AAB120 /* RNSentryDependencyContainerTests.m in Sources */,
219+
336084392C32E382008CC412 /* RNSentryCocoaUnitTesterTests.swift in Sources */,
210220
33F58AD02977037D008F60EA /* RNSentryTests.mm in Sources */,
211221
33958C692BFCF12600AD1FB6 /* RNSentryOnDrawReporterTests.m in Sources */,
212222
330F308C2C0F3840002A0D4E /* RNSentryBreadcrumbTests.m in Sources */,
@@ -333,6 +343,7 @@
333343
isa = XCBuildConfiguration;
334344
baseConfigurationReference = E2321E7CFA55AB617247098E /* Pods-RNSentryCocoaTesterTests.debug.xcconfig */;
335345
buildSettings = {
346+
CLANG_ENABLE_MODULES = YES;
336347
CODE_SIGN_STYLE = Automatic;
337348
CURRENT_PROJECT_VERSION = 1;
338349
GENERATE_INFOPLIST_FILE = YES;
@@ -387,6 +398,9 @@
387398
SUPPORTS_MACCATALYST = NO;
388399
SUPPORTS_MAC_DESIGNED_FOR_IPHONE_IPAD = NO;
389400
SWIFT_EMIT_LOC_STRINGS = NO;
401+
SWIFT_OBJC_BRIDGING_HEADER = "RNSentryCocoaTesterTests/RNSentryCocoaTesterTests-Bridging-Header.h";
402+
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
403+
SWIFT_VERSION = 5.0;
390404
TARGETED_DEVICE_FAMILY = 1;
391405
};
392406
name = Debug;
@@ -395,6 +409,7 @@
395409
isa = XCBuildConfiguration;
396410
baseConfigurationReference = 1482D5685A340AB93348A43D /* Pods-RNSentryCocoaTesterTests.release.xcconfig */;
397411
buildSettings = {
412+
CLANG_ENABLE_MODULES = YES;
398413
CODE_SIGN_STYLE = Automatic;
399414
CURRENT_PROJECT_VERSION = 1;
400415
GENERATE_INFOPLIST_FILE = YES;
@@ -449,6 +464,8 @@
449464
SUPPORTS_MACCATALYST = NO;
450465
SUPPORTS_MAC_DESIGNED_FOR_IPHONE_IPAD = NO;
451466
SWIFT_EMIT_LOC_STRINGS = NO;
467+
SWIFT_OBJC_BRIDGING_HEADER = "RNSentryCocoaTesterTests/RNSentryCocoaTesterTests-Bridging-Header.h";
468+
SWIFT_VERSION = 5.0;
452469
TARGETED_DEVICE_FAMILY = 1;
453470
};
454471
name = Release;
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
//
2+
// Use this file to import your target's public headers that you would like to expose to Swift.
3+
//
4+
5+
#import "RNSentryReplayBreadcrumbConverter.h"
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
import XCTest
2+
3+
final class RNSentryCocoaUnitTesterTests: XCTestCase {
4+
5+
func testTouchMessageReturnsNilOnEmptyArray() throws {
6+
let converter = RNSentryReplayBreadcrumbConverter()
7+
let actual = converter.getTouchPathMessage(from: [])
8+
XCTAssertEqual(actual, nil);
9+
}
10+
11+
func testTouchMessageReturnsNilOnNilArray() throws {
12+
let converter = RNSentryReplayBreadcrumbConverter()
13+
let actual = converter.getTouchPathMessage(from: nil as [Any]?)
14+
XCTAssertEqual(actual, nil);
15+
}
16+
17+
func testTouchMessageReturnsNilOnMissingNameAndLavel() throws {
18+
let testPath: [Any?] = [["element": "element4", "file": "file4"]]
19+
let converter = RNSentryReplayBreadcrumbConverter()
20+
let actual = converter.getTouchPathMessage(from: testPath as [Any])
21+
XCTAssertEqual(actual, nil);
22+
}
23+
24+
func testTouchMessageReturnsMessageOnValidPathExample1() throws {
25+
let testPath: [Any?] = [
26+
["label": "label0"],
27+
["name": "name1"],
28+
["name": "item2", "label": "label2"],
29+
["name": "item3", "label": "label3", "element": "element3"],
30+
["name": "item4", "label": "label4", "file": "file4"],
31+
["name": "item5", "label": "label5", "element": "element5", "file": "file5"],
32+
]
33+
let converter = RNSentryReplayBreadcrumbConverter()
34+
let actual = converter.getTouchPathMessage(from: testPath as [Any])
35+
XCTAssertEqual(actual, "label3(element3) > label2 > name1 > label0");
36+
}
37+
38+
func testTouchMessageReturnsMessageOnValidPathExample2() throws {
39+
let testPath: [Any?] = [
40+
["name": "item2", "label": "label2"],
41+
["name": "item3", "label": "label3", "element": "element3"],
42+
["name": "item4", "label": "label4", "file": "file4"],
43+
["name": "item5", "label": "label5", "element": "element5", "file": "file5"],
44+
["label": "label6"],
45+
["name": "name7"],
46+
]
47+
let converter = RNSentryReplayBreadcrumbConverter()
48+
let actual = converter.getTouchPathMessage(from: testPath as [Any])
49+
XCTAssertEqual(actual, "label5(element5, file5) > label4(file4) > label3(element3) > label2");
50+
}
51+
52+
}

ios/RNSentryReplayBreadcrumbConverter.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,7 @@
88

99
- (instancetype _Nonnull)init;
1010

11+
- (NSString* _Nullable) getTouchPathMessageFrom:(NSArray* _Nullable) path;
12+
1113
@end
1214
#endif

ios/RNSentryReplayBreadcrumbConverter.m

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ - (instancetype _Nonnull)init {
6767
}
6868

6969
NSMutableArray *path = [breadcrumb.data valueForKey:@"path"];
70-
NSString* message = [self getMessageFrom:path];
70+
NSString* message = [self getTouchPathMessageFrom:path];
7171

7272
return [SentrySessionReplayIntegration
7373
createBreadcrumbwithTimestamp:breadcrumb.timestamp
@@ -77,7 +77,7 @@ - (instancetype _Nonnull)init {
7777
data:breadcrumb.data];
7878
}
7979

80-
- (NSString* _Nullable) getMessageFrom:(NSArray* _Nullable) path {
80+
- (NSString* _Nullable) getTouchPathMessageFrom:(NSArray* _Nullable) path {
8181
if (path == nil) {
8282
return nil;
8383
}

0 commit comments

Comments
 (0)