Skip to content

Commit ad3434c

Browse files
authored
Merge pull request #977 from BranchMetrics/SDK-686-simplify-FB-unit-test
SDK-686 simplify FB unit test
2 parents 3bc6437 + 8351918 commit ad3434c

File tree

2 files changed

+10
-23
lines changed

2 files changed

+10
-23
lines changed

Branch-SDK-Tests/BNCFacebookAppLinksTests.m

Lines changed: 9 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -9,24 +9,19 @@
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
}

Branch-SDK/Branch-SDK/BNCFacebookAppLinks.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ - (void)fetchFacebookAppLinkWithCompletion:(void (^_Nullable)(NSURL *__nullable
6464
};
6565

6666
dispatch_async(dispatch_get_main_queue(), ^{
67-
((void (*)(id, SEL, void (^ __nullable)(NSURL *__nullable appLink, NSError * __nullable error)))[self.appLinkUtility methodForSelector:self.fetchDeferredAppLink])(self.appLinkUtility, self.fetchDeferredAppLink, completionBlock);
67+
((void (*)(id, SEL, void (^ __nullable)(NSURL *__nullable appLink, NSError * __nullable error)))[self.appLinkUtility methodForSelector:self.fetchDeferredAppLink])(self.appLinkUtility, self.fetchDeferredAppLink, completionBlock);
6868
});
6969
}
7070

0 commit comments

Comments
 (0)