|
9 | 9 | #import <XCTest/XCTest.h> |
10 | 10 | #import "BNCFacebookMock.h" |
11 | 11 | #import "BNCFacebookAppLinks.h" |
| 12 | +#import "Branch.h" |
12 | 13 |
|
13 | 14 | @interface BNCFacebookAppLinks() |
14 | 15 | - (BOOL)isDeepLinkingClassAvailable; |
15 | 16 | @end |
16 | 17 |
|
17 | 18 | @interface BNCFacebookAppLinksTests : XCTestCase |
18 | 19 | @property (nonatomic, strong, readwrite) BNCFacebookAppLinks *applinks; |
| 20 | +@property (nonatomic, strong, readwrite) Branch *branch; |
| 21 | +@property (nonatomic, strong, readwrite) BNCPreferenceHelper *preferenceHelper; |
19 | 22 | @end |
20 | 23 |
|
21 | 24 | @implementation BNCFacebookAppLinksTests |
22 | 25 |
|
23 | 26 | - (void)setUp { |
| 27 | + self.branch = [Branch getInstance]; |
24 | 28 | self.applinks = [BNCFacebookAppLinks new]; |
| 29 | + self.preferenceHelper = [BNCPreferenceHelper preferenceHelper]; |
25 | 30 | } |
26 | 31 |
|
27 | 32 | - (void)tearDown { |
@@ -56,4 +61,32 @@ - (void)testFetchFacebookAppLink { |
56 | 61 | }]; |
57 | 62 | } |
58 | 63 |
|
| 64 | +// check if FBSDKAppLinkUtility.fetchDeferredAppLink is called on the main thread |
| 65 | +// https://developers.facebook.com/docs/reference/ios/current/class/FBSDKAppLinkUtility |
| 66 | +- (void)testCheckFacebookAppLinks { |
| 67 | + __block XCTestExpectation *expectation = [self expectationWithDescription:@""]; |
| 68 | + |
| 69 | + [self.branch registerFacebookDeepLinkingClass:[BNCFacebookMock new]]; |
| 70 | + |
| 71 | + // checkFacebookAppLinks is not public, so use reflection to call it |
| 72 | + SEL selector = NSSelectorFromString(@"checkFacebookAppLinks"); |
| 73 | + ((void (*)(id, SEL))[self.branch methodForSelector:selector])(self.branch, selector); |
| 74 | + |
| 75 | + // wait 2 secs, then fulfill expectation, if checkFacebookAppLinks succeeded in setting |
| 76 | + // BNCPreferenceHelper's property 'faceBookAppLink' |
| 77 | + dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(2 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{ |
| 78 | + if ([self.preferenceHelper faceBookAppLink]) { |
| 79 | + XCTAssertTrue([[self.preferenceHelper faceBookAppLink].absoluteString isEqualToString:@"https://branch.io"]); |
| 80 | + [expectation fulfill]; |
| 81 | + } else { |
| 82 | + XCTFail(@"BNCPreferenceHelper.faceBookAppLink is nil after 2 seconds"); |
| 83 | + } |
| 84 | + }); |
| 85 | + |
| 86 | + // wait 3 secs, then check if expectation's been fulfilled |
| 87 | + [self waitForExpectationsWithTimeout:3 handler:^(NSError * _Nullable error) { |
| 88 | + NSLog(@"%@", error); |
| 89 | + }]; |
| 90 | +} |
| 91 | + |
59 | 92 | @end |
0 commit comments