Skip to content

Commit bf61b60

Browse files
a7medevHeshamMegid
authored andcommitted
[MOB-10594] Add More Native iOS Tests (#307)
* Test native iOS APM * Test native iOS Instabug * Test native iOS bug reporting * Test native iOS crash reporting * Test native iOS feature requests * Test native iOS Instabug log * Test native iOS replies * Test native iOS surveys * Test native iOS ArgsRegistry * Verify that iOS completion handler are called * Test native iOS `setValueForStringWithKey` branches
1 parent 0ce098f commit bf61b60

14 files changed

+1459
-39
lines changed
Lines changed: 150 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,150 @@
1+
#import <XCTest/XCTest.h>
2+
#import "OCMock/OCMock.h"
3+
#import "ApmApi.h"
4+
#import "Instabug/IBGAPM.h"
5+
#import "Instabug/Instabug.h"
6+
7+
@interface ApmApiTests : XCTestCase
8+
9+
@property (nonatomic, strong) id mAPM;
10+
@property (nonatomic, strong) ApmApi *api;
11+
12+
@end
13+
14+
@implementation ApmApiTests
15+
16+
- (void)setUp {
17+
self.mAPM = OCMClassMock([IBGAPM class]);
18+
self.api = [[ApmApi alloc] init];
19+
}
20+
21+
- (IBGExecutionTrace *)mockTraceWithId:(NSString *)traceId {
22+
NSString* name = @"trace-name";
23+
IBGExecutionTrace *mTrace = OCMClassMock([IBGExecutionTrace class]);
24+
25+
OCMStub([self.mAPM startExecutionTraceWithName:name]).andReturn(mTrace);
26+
27+
[self.api startExecutionTraceId:traceId name:name completion:^(NSString * _Nullable _, FlutterError * _Nullable __) {}];
28+
29+
return mTrace;
30+
}
31+
32+
- (void)testSetEnabled {
33+
NSNumber *isEnabled = @1;
34+
FlutterError *error;
35+
36+
[self.api setEnabledIsEnabled:isEnabled error:&error];
37+
38+
OCMVerify([self.mAPM setEnabled:YES]);
39+
}
40+
41+
- (void)testSetColdAppLaunchEnabled {
42+
NSNumber *isEnabled = @1;
43+
FlutterError *error;
44+
45+
[self.api setColdAppLaunchEnabledIsEnabled:isEnabled error:&error];
46+
47+
OCMVerify([self.mAPM setAppLaunchEnabled:YES]);
48+
}
49+
50+
- (void)testSetAutoUITraceEnabled {
51+
NSNumber *isEnabled = @1;
52+
FlutterError *error;
53+
54+
[self.api setAutoUITraceEnabledIsEnabled:isEnabled error:&error];
55+
56+
OCMVerify([self.mAPM setAutoUITraceEnabled:YES]);
57+
}
58+
59+
- (void)testSetLogLevel {
60+
NSString *level = @"LogLevel.warning";
61+
FlutterError *error;
62+
63+
[self.api setLogLevelLevel:level error:&error];
64+
65+
OCMVerify([self.mAPM setLogLevel:IBGLogLevelWarning]);
66+
}
67+
68+
- (void)testStartExecutionTraceWhenTraceNotNil {
69+
NSString *expectedId = @"trace-id";
70+
NSString *name = @"trace-name";
71+
XCTestExpectation *expectation = [self expectationWithDescription:@"Call completion handler"];
72+
73+
OCMStub([self.mAPM startExecutionTraceWithName:name]).andReturn([IBGExecutionTrace new]);
74+
75+
[self.api startExecutionTraceId:expectedId name:name completion:^(NSString *actualId, FlutterError *error) {
76+
[expectation fulfill];
77+
XCTAssertEqual(actualId, expectedId);
78+
XCTAssertNil(error);
79+
}];
80+
81+
OCMVerify([self.mAPM startExecutionTraceWithName:name]);
82+
[self waitForExpectations:@[expectation] timeout:5.0];
83+
}
84+
85+
- (void)testStartExecutionTraceWhenTraceIsNil {
86+
NSString *traceId = @"trace-id";
87+
NSString *name = @"trace-name";
88+
XCTestExpectation *expectation = [self expectationWithDescription:@"Call completion handler"];
89+
90+
OCMStub([self.mAPM startExecutionTraceWithName:name]).andReturn(nil);
91+
92+
[self.api startExecutionTraceId:traceId name:name completion:^(NSString *actualId, FlutterError *error) {
93+
[expectation fulfill];
94+
XCTAssertNil(actualId);
95+
XCTAssertNil(error);
96+
}];
97+
98+
OCMVerify([self.mAPM startExecutionTraceWithName:name]);
99+
[self waitForExpectations:@[expectation] timeout:5.0];
100+
}
101+
102+
103+
- (void)testSetExecutionTraceAttribute {
104+
NSString *traceId = @"trace-id";
105+
NSString *key = @"is_premium";
106+
NSString *value = @"true";
107+
FlutterError *error;
108+
id mTrace = [self mockTraceWithId:traceId];
109+
110+
[self.api setExecutionTraceAttributeId:traceId key:key value:value error:&error];
111+
112+
OCMVerify([mTrace setAttributeWithKey:key value:value]);
113+
}
114+
115+
- (void)testEndExecutionTrace {
116+
NSString *traceId = @"trace-id";
117+
FlutterError *error;
118+
IBGExecutionTrace *mTrace = [self mockTraceWithId:traceId];
119+
120+
[self.api endExecutionTraceId:traceId error:&error];
121+
122+
OCMVerify([mTrace end]);
123+
}
124+
125+
- (void)testStartUITrace {
126+
NSString *name = @"login";
127+
FlutterError *error;
128+
129+
[self.api startUITraceName:name error:&error];
130+
131+
OCMVerify([self.mAPM startUITraceWithName:name]);
132+
}
133+
134+
- (void)testEndUITrace {
135+
FlutterError *error;
136+
137+
[self.api endUITraceWithError:&error];
138+
139+
OCMVerify([self.mAPM endUITrace]);
140+
}
141+
142+
- (void)testEndAppLaunch {
143+
FlutterError *error;
144+
145+
[self.api endAppLaunchWithError:&error];
146+
147+
OCMVerify([self.mAPM endAppLaunch]);
148+
}
149+
150+
@end

0 commit comments

Comments
 (0)