ComPDFKit_RNTests.m 2.0 KB

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 ComPDFKit_RNTests : XCTestCase
  8. @end
  9. @implementation ComPDFKit_RNTests
  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(
  30. ^(RCTLogLevel level, RCTLogSource source, NSString *fileName, NSNumber *lineNumber, NSString *message) {
  31. if (level >= RCTLogLevelError) {
  32. redboxError = message;
  33. }
  34. });
  35. #endif
  36. while ([date timeIntervalSinceNow] > 0 && !foundElement && !redboxError) {
  37. [[NSRunLoop mainRunLoop] runMode:NSDefaultRunLoopMode beforeDate:[NSDate dateWithTimeIntervalSinceNow:0.1]];
  38. [[NSRunLoop mainRunLoop] runMode:NSRunLoopCommonModes beforeDate:[NSDate dateWithTimeIntervalSinceNow:0.1]];
  39. foundElement = [self findSubviewInView:vc.view
  40. matching:^BOOL(UIView *view) {
  41. if ([view.accessibilityLabel isEqualToString:TEXT_TO_LOOK_FOR]) {
  42. return YES;
  43. }
  44. return NO;
  45. }];
  46. }
  47. #ifdef DEBUG
  48. RCTSetLogFunction(RCTDefaultLogFunction);
  49. #endif
  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