Няма описание

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