選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

LessPassTests.m 1.7 KiB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  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 LessPassTests : XCTestCase
  8. @end
  9. @implementation LessPassTests
  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