react-native-navigation的迁移库

RNNLayoutManagerTest.m 3.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. #import <XCTest/XCTest.h>
  2. #import <OCMock/OCMock.h>
  3. #import "RNNLayoutManager.h"
  4. #import "UIViewController+LayoutProtocol.h"
  5. @interface RNNLayoutManagerTest : XCTestCase
  6. @property (nonatomic, strong) UIViewController* vc1;
  7. @property (nonatomic, strong) UIViewController* vc2;
  8. @property (nonatomic, strong) UIViewController* vc3;
  9. @property (nonatomic, strong) UIWindow* firstWindow;
  10. @property (nonatomic, strong) UIWindow* secondWindow;
  11. @end
  12. @implementation RNNLayoutManagerTest
  13. - (void)setUp {
  14. _vc1 = [self createMockViewControllerWithComponentId:@"vc1"];
  15. _vc2 = [self createMockViewControllerWithComponentId:@"vc2"];
  16. _vc3 = [self createMockViewControllerWithComponentId:@"vc3"];
  17. _firstWindow = [[UIWindow alloc] init];
  18. _secondWindow = [[UIWindow alloc] init];
  19. NSArray* windows = @[_firstWindow, _secondWindow];
  20. UIApplication* sharedApplication = [OCMockObject mockForClass:[UIApplication class]];
  21. id mockedApplicationClass = OCMClassMock([UIApplication class]);
  22. OCMStub(ClassMethod([mockedApplicationClass sharedApplication])).andReturn(sharedApplication);
  23. OCMStub(sharedApplication.keyWindow).andReturn(_firstWindow);
  24. OCMStub([sharedApplication windows]).andReturn(windows);
  25. }
  26. - (void)testFindComponentForIdShouldReturnVCInFirstWindowRoot {
  27. _firstWindow.rootViewController = _vc1;
  28. UIViewController *resultVC = [RNNLayoutManager findComponentForId:@"vc1"];
  29. XCTAssertEqual(resultVC, _vc1);
  30. }
  31. - (void)testFindComponentForIdShouldReturnVCFromSecondWindowRoot {
  32. _secondWindow.rootViewController = _vc1;
  33. UIViewController *resultVC = [RNNLayoutManager findComponentForId:@"vc1"];
  34. XCTAssertEqual(resultVC, _vc1);
  35. }
  36. - (void)testFindComponentShouldReturnModalFromFirstWindow {
  37. UIViewController* rootViewController = [OCMockObject partialMockForObject:[UIViewController new]];
  38. UIViewController* modal = _vc1;
  39. OCMStub([rootViewController presentedViewController]).andReturn(modal);
  40. _firstWindow.rootViewController = rootViewController;
  41. UIViewController *resultVC = [RNNLayoutManager findComponentForId:@"vc1"];
  42. XCTAssertEqual(resultVC, modal);
  43. }
  44. - (void)testFindComponentShouldReturnModalFromSecondWindow {
  45. UIViewController* rootViewController = [OCMockObject partialMockForObject:[UIViewController new]];
  46. UIViewController* modal = _vc1;
  47. OCMStub([rootViewController presentedViewController]).andReturn(modal);
  48. _secondWindow.rootViewController = rootViewController;
  49. UIViewController *resultVC = [RNNLayoutManager findComponentForId:@"vc1"];
  50. XCTAssertEqual(resultVC, modal);
  51. }
  52. - (void)testFindComponentShouldReturnNilForUndefindComponent {
  53. _firstWindow.rootViewController = _vc1;
  54. UIViewController *resultVC = [RNNLayoutManager findComponentForId:@"vvc"];
  55. XCTAssertNil(resultVC);
  56. }
  57. - (void)testFindComponentShouldFindRootViewControllerChildViewController {
  58. UINavigationController* nvc = [[UINavigationController alloc] init];
  59. [nvc setViewControllers:@[_vc1, _vc2, _vc3]];
  60. _secondWindow.rootViewController = nvc;
  61. UIViewController *resultVC = [RNNLayoutManager findComponentForId:@"vc3"];
  62. XCTAssertEqual(resultVC, _vc3);
  63. }
  64. - (UIViewController *)createMockViewControllerWithComponentId:(NSString *)componentId {
  65. RNNLayoutInfo* layoutInfo = [RNNLayoutInfo new];
  66. layoutInfo.componentId = componentId;
  67. UIViewController* vc = [UIViewController new];
  68. vc.layoutInfo = layoutInfo;
  69. return vc;
  70. }
  71. @end