Skip to content

Commit f983864

Browse files
Add iOS specs
1 parent 3995a08 commit f983864

File tree

2 files changed

+155
-1
lines changed

2 files changed

+155
-1
lines changed

InstabugSample/ios/InstabugSample.xcodeproj/project.pbxproj

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
BAD36E3122F19973007F5E74 /* InstabugRepliesTests.m in Sources */ = {isa = PBXBuildFile; fileRef = BAD36E3022F19973007F5E74 /* InstabugRepliesTests.m */; };
2222
BAD36E3322F19B1B007F5E74 /* InstabugSurveysTests.m in Sources */ = {isa = PBXBuildFile; fileRef = BAD36E3222F19B1B007F5E74 /* InstabugSurveysTests.m */; };
2323
C006102922E9EBCA00EDC852 /* libOCMock.a in Frameworks */ = {isa = PBXBuildFile; fileRef = C006102822E9EBCA00EDC852 /* libOCMock.a */; };
24+
C0AB369625854A6100F1E21E /* InstabugAPMTests.m in Sources */ = {isa = PBXBuildFile; fileRef = C0AB369525854A6100F1E21E /* InstabugAPMTests.m */; };
2425
/* End PBXBuildFile section */
2526

2627
/* Begin PBXContainerItemProxy section */
@@ -63,9 +64,9 @@
6364
BAD36E3022F19973007F5E74 /* InstabugRepliesTests.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = InstabugRepliesTests.m; sourceTree = "<group>"; };
6465
BAD36E3222F19B1B007F5E74 /* InstabugSurveysTests.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = InstabugSurveysTests.m; sourceTree = "<group>"; };
6566
C006102822E9EBCA00EDC852 /* libOCMock.a */ = {isa = PBXFileReference; lastKnownFileType = archive.ar; name = libOCMock.a; path = usr/lib/libOCMock.a; sourceTree = "<group>"; };
67+
C0AB369525854A6100F1E21E /* InstabugAPMTests.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = InstabugAPMTests.m; sourceTree = "<group>"; };
6668
C74E4010ABE7AFC7DB5E79DC /* Pods-InstabugSampleTests.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-InstabugSampleTests.debug.xcconfig"; path = "Pods/Target Support Files/Pods-InstabugSampleTests/Pods-InstabugSampleTests.debug.xcconfig"; sourceTree = "<group>"; };
6769
ED297162215061F000B7C4FE /* JavaScriptCore.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = JavaScriptCore.framework; path = System/Library/Frameworks/JavaScriptCore.framework; sourceTree = SDKROOT; };
68-
FA49CB8462F384E9EDD7DDFD /* Instabug.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Instabug.framework; path = "../node_modules/instabug-reactnative/ios/Instabug.framework"; sourceTree = "<group>"; };
6970
/* End PBXFileReference section */
7071

7172
/* Begin PBXFrameworksBuildPhase section */
@@ -101,6 +102,7 @@
101102
BAD36E2E22F19788007F5E74 /* InstabugFeatureRequestsTests.m */,
102103
BAD36E3022F19973007F5E74 /* InstabugRepliesTests.m */,
103104
BAD36E3222F19B1B007F5E74 /* InstabugSurveysTests.m */,
105+
C0AB369525854A6100F1E21E /* InstabugAPMTests.m */,
104106
);
105107
path = InstabugSampleTests;
106108
sourceTree = "<group>";
@@ -410,6 +412,7 @@
410412
BAD36E1E22F0906A007F5E74 /* IBGConstants.m in Sources */,
411413
BAD36E3322F19B1B007F5E74 /* InstabugSurveysTests.m in Sources */,
412414
BAD36E2F22F19788007F5E74 /* InstabugFeatureRequestsTests.m in Sources */,
415+
C0AB369625854A6100F1E21E /* InstabugAPMTests.m in Sources */,
413416
BAD36E1C22F08B27007F5E74 /* InstabugBugReportingTests.m in Sources */,
414417
BAD36E2D22F1955C007F5E74 /* InstabugChatsTests.m in Sources */,
415418
00E356F31AD99517003FC87E /* InstabugSampleTests.m in Sources */,
Lines changed: 151 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,151 @@
1+
//
2+
// InstabugAPMTests.m
3+
// InstabugSampleTests
4+
//
5+
// Created by Ali Abdelfattah on 12/12/20.
6+
// Copyright © 2020 Facebook. All rights reserved.
7+
//
8+
9+
#import <XCTest/XCTest.h>
10+
#import "OCMock/OCMock.h"
11+
#import "InstabugAPMBridge.h"
12+
#import <Instabug/IBGTypes.h>
13+
#import <Instabug/IBGAPM.h>
14+
#import "Instabug/Instabug.h"
15+
#import "IBGConstants.h"
16+
17+
@interface InstabugAPMTests : XCTestCase
18+
@property (nonatomic, retain) InstabugAPMBridge *instabugBridge;
19+
@end
20+
21+
@protocol APMCPTestProtocol <NSObject>
22+
/**
23+
* This protocol helps in correctly mapping APM mocked methods
24+
* when their method name matches another method in a different
25+
* module that differs in method signature.
26+
*/
27+
- (void)setEnabled:(BOOL)isEnabled;
28+
29+
@end
30+
31+
@protocol ExecutionTraceCPTestProtocol <NSObject>
32+
/**
33+
* This protocol helps in correctly mapping IBGExecutionTrace mocked methods
34+
* when their method name matches another method in a different
35+
* module that differs in method signature.
36+
*/
37+
- (void)end;
38+
@end
39+
40+
@implementation InstabugAPMTests
41+
42+
- (void)setUp {
43+
// Put setup code here. This method is called before the invocation of each test method in the class.
44+
self.instabugBridge = [[InstabugAPMBridge alloc] init];
45+
}
46+
47+
/*
48+
+------------------------------------------------------------------------+
49+
| APM Module |
50+
+------------------------------------------------------------------------+
51+
*/
52+
53+
- (void) testSetAPMEnabled {
54+
id mock = OCMClassMock([IBGAPM class]);
55+
BOOL isEnabled = YES;
56+
57+
OCMStub([mock setEnabled:isEnabled]);
58+
[self.instabugBridge setEnabled:isEnabled];
59+
OCMVerify([mock setEnabled:isEnabled]);
60+
}
61+
62+
- (void) testSetLogLevel {
63+
id mock = OCMClassMock([IBGAPM class]);
64+
BOOL logLevel = IBGLogLevelVerbose;
65+
66+
OCMStub([mock setLogLevel:logLevel]);
67+
[self.instabugBridge setLogLevel:logLevel];
68+
OCMVerify([mock setLogLevel:logLevel]);
69+
}
70+
71+
- (void) testSetAppLaunchEnabled {
72+
id mock = OCMClassMock([IBGAPM class]);
73+
BOOL isEnabled = YES;
74+
75+
OCMStub([mock setAppLaunchEnabled:isEnabled]);
76+
[self.instabugBridge setAppLaunchEnabled:isEnabled];
77+
OCMVerify([mock setAppLaunchEnabled:isEnabled]);
78+
}
79+
80+
- (void) testSetAutoUITraceEnabled {
81+
id mock = OCMClassMock([IBGAPM class]);
82+
BOOL isEnabled = YES;
83+
84+
OCMStub([mock setAutoUITraceEnabled:isEnabled]);
85+
[self.instabugBridge setAutoUITraceEnabled:isEnabled];
86+
OCMVerify([mock setAutoUITraceEnabled:isEnabled]);
87+
}
88+
89+
- (void) testStartExecutionTrace {
90+
id mock = OCMClassMock([IBGAPM class]);
91+
NSString* traceName = @"Trace_1";
92+
NSString* traceKey = @"1";
93+
RCTResponseSenderBlock callback = ^(NSArray *response) {};
94+
95+
OCMStub([mock startExecutionTraceWithName:traceName]);
96+
[self.instabugBridge startExecutionTrace:traceName :traceKey :callback];
97+
OCMVerify([mock startExecutionTraceWithName:traceName]);
98+
}
99+
100+
- (void) testSetExecutionTraceAttribute {
101+
NSString* traceName = @"Trace_1";
102+
NSString* traceId = @"Id_1";
103+
NSString* traceKey = @"Key_1";
104+
NSString* traceValue = @"1";
105+
RCTResponseSenderBlock callback = ^(NSArray *response) {};
106+
IBGExecutionTrace * trace = [IBGExecutionTrace alloc];
107+
id mock = OCMClassMock([IBGAPM class]);
108+
id traceMock = OCMPartialMock(trace);
109+
110+
OCMStub([mock startExecutionTraceWithName:traceName]).andReturn(trace);
111+
[self.instabugBridge startExecutionTrace:traceName :traceId :callback];
112+
113+
OCMStub([traceMock setAttributeWithKey:traceKey value:traceValue]);
114+
[self.instabugBridge setExecutionTraceAttribute:traceId :traceKey :traceValue];
115+
OCMVerify([traceMock setAttributeWithKey:traceKey value:traceValue]);
116+
}
117+
118+
- (void) testEndExecutionTrace {
119+
NSString* traceName = @"Trace_1";
120+
NSString* traceId = @"Id_1";
121+
RCTResponseSenderBlock callback = ^(NSArray *response) {};
122+
IBGExecutionTrace * trace = [IBGExecutionTrace alloc];
123+
id apmMock = OCMClassMock([IBGAPM class]);
124+
id<ExecutionTraceCPTestProtocol> traceMock = OCMPartialMock(trace);
125+
126+
OCMStub([apmMock startExecutionTraceWithName:traceName]).andReturn(trace);
127+
[self.instabugBridge startExecutionTrace:traceName :traceId :callback];
128+
129+
OCMStub([traceMock end]);
130+
[self.instabugBridge endExecutionTrace:traceId];
131+
OCMVerify([traceMock end]);
132+
}
133+
134+
- (void) testStartUITrace {
135+
id mock = OCMClassMock([IBGAPM class]);
136+
NSString* traceName = @"UITrace_1";
137+
138+
OCMStub([mock startUITraceWithName:traceName]);
139+
[self.instabugBridge startUITrace:traceName];
140+
OCMVerify([mock startUITraceWithName:traceName]);
141+
}
142+
143+
- (void) testEndUITrace {
144+
id mock = OCMClassMock([IBGAPM class]);
145+
146+
OCMStub([mock endUITrace]);
147+
[self.instabugBridge endUITrace];
148+
OCMVerify([mock endUITrace]);
149+
}
150+
151+
@end

0 commit comments

Comments
 (0)