|
5 | 5 | * LICENSE file in the root directory of this source tree.
|
6 | 6 | */
|
7 | 7 |
|
8 |
| -#import <UIKit/UIKit.h> |
9 | 8 | #import <XCTest/XCTest.h>
|
| 9 | +#import <RNAzureNotificationHub/RCTAzureNotificationHubManager.h> |
10 | 10 |
|
11 |
| -#import <React/RCTLog.h> |
12 |
| -#import <React/RCTRootView.h> |
13 |
| - |
14 |
| -#define TIMEOUT_SECONDS 600 |
15 |
| -#define TEXT_TO_LOOK_FOR @"Welcome to React" |
| 11 | +@import OCMockito; |
16 | 12 |
|
17 | 13 | @interface ReactNativeAzureNotificationHubSampleTests : XCTestCase
|
18 |
| - |
19 | 14 | @end
|
20 | 15 |
|
21 | 16 | @implementation ReactNativeAzureNotificationHubSampleTests
|
| 17 | +{ |
| 18 | + RCTAzureNotificationHubManager *hubManager; |
| 19 | + NSMutableDictionary *config; |
| 20 | + RCTPromiseResolveBlock resolver; |
| 21 | + RCTPromiseRejectBlock rejecter; |
| 22 | +} |
22 | 23 |
|
23 |
| -- (BOOL)findSubviewInView:(UIView *)view matching:(BOOL(^)(UIView *view))test |
| 24 | +- (void)setUp |
24 | 25 | {
|
25 |
| - if (test(view)) { |
26 |
| - return YES; |
27 |
| - } |
28 |
| - for (UIView *subview in [view subviews]) { |
29 |
| - if ([self findSubviewInView:subview matching:test]) { |
30 |
| - return YES; |
31 |
| - } |
32 |
| - } |
33 |
| - return NO; |
| 26 | + [super setUp]; |
| 27 | + hubManager = [[RCTAzureNotificationHubManager alloc] init]; |
| 28 | + config = [[NSMutableDictionary alloc] init]; |
| 29 | + resolver = ^(id result) {}; |
| 30 | + rejecter = ^(NSString *code, NSString *message, NSError *error) {}; |
34 | 31 | }
|
35 | 32 |
|
36 |
| -- (void)testRendersWelcomeScreen |
| 33 | +- (void)testRegisterNoConnectionString |
37 | 34 | {
|
38 |
| - UIViewController *vc = [[[RCTSharedApplication() delegate] window] rootViewController]; |
39 |
| - NSDate *date = [NSDate dateWithTimeIntervalSinceNow:TIMEOUT_SECONDS]; |
40 |
| - BOOL foundElement = NO; |
| 35 | + __block NSString *errorMsg; |
| 36 | + rejecter = ^(NSString *code, NSString *message, NSError *error) |
| 37 | + { |
| 38 | + errorMsg = message; |
| 39 | + }; |
41 | 40 |
|
42 |
| - __block NSString *redboxError = nil; |
43 |
| -#ifdef DEBUG |
44 |
| - RCTSetLogFunction(^(RCTLogLevel level, RCTLogSource source, NSString *fileName, NSNumber *lineNumber, NSString *message) { |
45 |
| - if (level >= RCTLogLevelError) { |
46 |
| - redboxError = message; |
47 |
| - } |
48 |
| - }); |
49 |
| -#endif |
| 41 | + [hubManager register:@"" |
| 42 | + config:config |
| 43 | + resolver:resolver |
| 44 | + rejecter:rejecter]; |
50 | 45 |
|
51 |
| - while ([date timeIntervalSinceNow] > 0 && !foundElement && !redboxError) { |
52 |
| - [[NSRunLoop mainRunLoop] runMode:NSDefaultRunLoopMode beforeDate:[NSDate dateWithTimeIntervalSinceNow:0.1]]; |
53 |
| - [[NSRunLoop mainRunLoop] runMode:NSRunLoopCommonModes beforeDate:[NSDate dateWithTimeIntervalSinceNow:0.1]]; |
| 46 | + XCTAssertEqualObjects(errorMsg, @"Connection string cannot be null."); |
| 47 | +} |
54 | 48 |
|
55 |
| - foundElement = [self findSubviewInView:vc.view matching:^BOOL(UIView *view) { |
56 |
| - if ([view.accessibilityLabel isEqualToString:TEXT_TO_LOOK_FOR]) { |
57 |
| - return YES; |
58 |
| - } |
59 |
| - return NO; |
60 |
| - }]; |
61 |
| - } |
62 |
| - |
63 |
| -#ifdef DEBUG |
64 |
| - RCTSetLogFunction(RCTDefaultLogFunction); |
65 |
| -#endif |
| 49 | +- (void)testRegisterNoHubName |
| 50 | +{ |
| 51 | + __block NSString *errorMsg; |
| 52 | + rejecter = ^(NSString *code, NSString *message, NSError *error) |
| 53 | + { |
| 54 | + errorMsg = message; |
| 55 | + }; |
66 | 56 |
|
67 |
| - XCTAssertNil(redboxError, @"RedBox error: %@", redboxError); |
68 |
| - XCTAssertTrue(foundElement, @"Couldn't find element with text '%@' in %d seconds", TEXT_TO_LOOK_FOR, TIMEOUT_SECONDS); |
| 57 | + [config setObject:@"Connection String" forKey:@"connectionString"]; |
| 58 | + [hubManager register:@"" |
| 59 | + config:config |
| 60 | + resolver:resolver |
| 61 | + rejecter:rejecter]; |
| 62 | + |
| 63 | + XCTAssertEqualObjects(errorMsg, @"Hub name cannot be null."); |
69 | 64 | }
|
70 | 65 |
|
| 66 | +- (void)testRegisterSuccessfully |
| 67 | +{ |
| 68 | + __block bool hasError = false; |
| 69 | + rejecter = ^(NSString *code, NSString *message, NSError *error) |
| 70 | + { |
| 71 | + hasError = true; |
| 72 | + }; |
| 73 | + |
| 74 | + [config setObject:@"Connection String" forKey:@"connectionString"]; |
| 75 | + [config setObject:@"Hub Name" forKey:@"hubName"]; |
| 76 | + [hubManager register:@"" |
| 77 | + config:config |
| 78 | + resolver:resolver |
| 79 | + rejecter:rejecter]; |
| 80 | + |
| 81 | + XCTAssertEqual(hasError, false); |
| 82 | +} |
71 | 83 |
|
72 | 84 | @end
|
0 commit comments