efunbox_mobile_8Tests.m 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. /**
  2. * Copyright (c) Facebook, Inc. and its affiliates.
  3. *
  4. * This source code is licensed under the MIT license found in the
  5. * LICENSE file in the root directory of this source tree.
  6. */
  7. #import <UIKit/UIKit.h>
  8. #import <XCTest/XCTest.h>
  9. #import <React/RCTLog.h>
  10. #import <React/RCTRootView.h>
  11. #define TIMEOUT_SECONDS 600
  12. #define TEXT_TO_LOOK_FOR @"Welcome to React Native!"
  13. @interface efunbox_mobile_8Tests : XCTestCase
  14. @end
  15. @implementation efunbox_mobile_8Tests
  16. - (BOOL)findSubviewInView:(UIView *)view matching:(BOOL(^)(UIView *view))test
  17. {
  18. if (test(view)) {
  19. return YES;
  20. }
  21. for (UIView *subview in [view subviews]) {
  22. if ([self findSubviewInView:subview matching:test]) {
  23. return YES;
  24. }
  25. }
  26. return NO;
  27. }
  28. - (void)testRendersWelcomeScreen
  29. {
  30. UIViewController *vc = [[[RCTSharedApplication() delegate] window] rootViewController];
  31. NSDate *date = [NSDate dateWithTimeIntervalSinceNow:TIMEOUT_SECONDS];
  32. BOOL foundElement = NO;
  33. __block NSString *redboxError = nil;
  34. RCTSetLogFunction(^(RCTLogLevel level, RCTLogSource source, NSString *fileName, NSNumber *lineNumber, NSString *message) {
  35. if (level >= RCTLogLevelError) {
  36. redboxError = message;
  37. }
  38. });
  39. while ([date timeIntervalSinceNow] > 0 && !foundElement && !redboxError) {
  40. [[NSRunLoop mainRunLoop] runMode:NSDefaultRunLoopMode beforeDate:[NSDate dateWithTimeIntervalSinceNow:0.1]];
  41. [[NSRunLoop mainRunLoop] runMode:NSRunLoopCommonModes beforeDate:[NSDate dateWithTimeIntervalSinceNow:0.1]];
  42. foundElement = [self findSubviewInView:vc.view matching:^BOOL(UIView *view) {
  43. if ([view.accessibilityLabel isEqualToString:TEXT_TO_LOOK_FOR]) {
  44. return YES;
  45. }
  46. return NO;
  47. }];
  48. }
  49. RCTSetLogFunction(RCTDefaultLogFunction);
  50. XCTAssertNil(redboxError, @"RedBox error: %@", redboxError);
  51. XCTAssertTrue(foundElement, @"Couldn't find element with text '%@' in %d seconds", TEXT_TO_LOOK_FOR, TIMEOUT_SECONDS);
  52. }
  53. @end