99#import < XCTest/XCTest.h>
1010#import " BNCFacebookMock.h"
1111#import " BNCFacebookAppLinks.h"
12- #import " Branch.h"
1312
1413@interface BNCFacebookAppLinks ()
1514- (BOOL )isDeepLinkingClassAvailable ;
1615@end
1716
1817@interface BNCFacebookAppLinksTests : XCTestCase
1918@property (nonatomic , strong , readwrite ) BNCFacebookAppLinks *applinks;
20- @property (nonatomic , strong , readwrite ) Branch *branch;
21- @property (nonatomic , strong , readwrite ) BNCPreferenceHelper *preferenceHelper;
2219@end
2320
2421@implementation BNCFacebookAppLinksTests
2522
2623- (void )setUp {
27- self.branch = [Branch getInstance ];
2824 self.applinks = [BNCFacebookAppLinks new ];
29- self.preferenceHelper = [BNCPreferenceHelper preferenceHelper ];
3025}
3126
3227- (void )tearDown {
@@ -53,6 +48,7 @@ - (void)testFetchFacebookAppLink {
5348 [self .applinks registerFacebookDeepLinkingClass: [BNCFacebookMock new ]];
5449 [self .applinks fetchFacebookAppLinkWithCompletion: ^(NSURL * _Nullable appLink, NSError * _Nullable error) {
5550 XCTAssertTrue ([[appLink absoluteString ] isEqualToString: @" https://branch.io" ]);
51+ XCTAssertTrue ([NSThread isMainThread ]);
5652 [expectation fulfill ];
5753 }];
5854
@@ -63,28 +59,19 @@ - (void)testFetchFacebookAppLink {
6359
6460// check if FBSDKAppLinkUtility.fetchDeferredAppLink is called on the main thread
6561// https://developers.facebook.com/docs/reference/ios/current/class/FBSDKAppLinkUtility
66- - (void )testCheckFacebookAppLinks {
62+ - (void )testFetchFacebookAppLink_BackgroundThead {
6763 __block XCTestExpectation *expectation = [self expectationWithDescription: @" " ];
6864
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" ]);
65+ dispatch_async (dispatch_get_global_queue (DISPATCH_QUEUE_PRIORITY_DEFAULT, 0 ), ^{
66+ [self .applinks registerFacebookDeepLinkingClass: [BNCFacebookMock new ]];
67+ [self .applinks fetchFacebookAppLinkWithCompletion: ^(NSURL * _Nullable appLink, NSError * _Nullable error) {
68+ XCTAssertTrue ([[appLink absoluteString ] isEqualToString: @" https://branch.io" ]);
69+ XCTAssertTrue ([NSThread isMainThread ]);
8070 [expectation fulfill ];
81- } else {
82- XCTFail (@" BNCPreferenceHelper.faceBookAppLink is nil after 2 seconds" );
83- }
71+ }];
8472 });
8573
86- // wait 3 secs, then check if expectation's been fulfilled
87- [self waitForExpectationsWithTimeout: 3 handler: ^(NSError * _Nullable error) {
74+ [self waitForExpectationsWithTimeout: 2 handler: ^(NSError * _Nullable error) {
8875 NSLog (@" %@ " , error);
8976 }];
9077}
0 commit comments