Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  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"
  13. @interface newExampleTests : XCTestCase
  14. @end
  15. @implementation newExampleTests
  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. #ifdef DEBUG
  35. RCTSetLogFunction(^(RCTLogLevel level, RCTLogSource source, NSString *fileName, NSNumber *lineNumber, NSString *message) {
  36. if (level >= RCTLogLevelError) {
  37. redboxError = message;
  38. }
  39. });
  40. #endif
  41. while ([date timeIntervalSinceNow] > 0 && !foundElement && !redboxError) {
  42. [[NSRunLoop mainRunLoop] runMode:NSDefaultRunLoopMode beforeDate:[NSDate dateWithTimeIntervalSinceNow:0.1]];
  43. [[NSRunLoop mainRunLoop] runMode:NSRunLoopCommonModes beforeDate:[NSDate dateWithTimeIntervalSinceNow:0.1]];
  44. foundElement = [self findSubviewInView:vc.view matching:^BOOL(UIView *view) {
  45. if ([view.accessibilityLabel isEqualToString:TEXT_TO_LOOK_FOR]) {
  46. return YES;
  47. }
  48. return NO;
  49. }];
  50. }
  51. #ifdef DEBUG
  52. RCTSetLogFunction(RCTDefaultLogFunction);
  53. #endif
  54. XCTAssertNil(redboxError, @"RedBox error: %@", redboxError);
  55. XCTAssertTrue(foundElement, @"Couldn't find element with text '%@' in %d seconds", TEXT_TO_LOOK_FOR, TIMEOUT_SECONDS);
  56. }
  57. @end