react-native-navigation的迁移库

RNNLayoutManagerTest.m 3.2KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. #import <XCTest/XCTest.h>
  2. #import <OCMock/OCMock.h>
  3. #import "RNNLayoutManager.h"
  4. #import "UIViewController+LayoutProtocol.m"
  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 windows]).andReturn(windows);
  24. }
  25. - (void)testFindComponentForIdShouldReturnVCInFirstWindowRoot {
  26. _firstWindow.rootViewController = _vc1;
  27. UIViewController *resultVC = [RNNLayoutManager findComponentForId:@"vc1"];
  28. XCTAssertEqual(resultVC, _vc1);
  29. }
  30. - (void)testFindComponentForIdShouldReturnVCFromSecondWindowRoot {
  31. _secondWindow.rootViewController = _vc1;
  32. UIViewController *resultVC = [RNNLayoutManager findComponentForId:@"vc1"];
  33. XCTAssertEqual(resultVC, _vc1);
  34. }
  35. - (void)testFindComponentShouldReturnModalFromFirstWindow {
  36. UIViewController* rootViewController = [OCMockObject partialMockForObject:[UIViewController new]];
  37. UIViewController* modal = _vc1;
  38. OCMStub([rootViewController presentedViewController]).andReturn(modal);
  39. _firstWindow.rootViewController = rootViewController;
  40. UIViewController *resultVC = [RNNLayoutManager findComponentForId:@"vc1"];
  41. XCTAssertEqual(resultVC, modal);
  42. }
  43. - (void)testFindComponentShouldReturnModalFromSecondWindow {
  44. UIViewController* rootViewController = [OCMockObject partialMockForObject:[UIViewController new]];
  45. UIViewController* modal = _vc1;
  46. OCMStub([rootViewController presentedViewController]).andReturn(modal);
  47. _secondWindow.rootViewController = rootViewController;
  48. UIViewController *resultVC = [RNNLayoutManager findComponentForId:@"vc1"];
  49. XCTAssertEqual(resultVC, modal);
  50. }
  51. - (void)testFindComponentShouldReturnNilForUndefindComponent {
  52. _firstWindow.rootViewController = _vc1;
  53. UIViewController *resultVC = [RNNLayoutManager findComponentForId:@"vvc"];
  54. XCTAssertNil(resultVC);
  55. }
  56. - (void)testFindComponentShouldFindRootViewControllerChildViewController {
  57. UINavigationController* nvc = [[UINavigationController alloc] init];
  58. [nvc setViewControllers:@[_vc1, _vc2, _vc3]];
  59. _secondWindow.rootViewController = nvc;
  60. UIViewController *resultVC = [RNNLayoutManager findComponentForId:@"vc3"];
  61. XCTAssertEqual(resultVC, _vc3);
  62. }
  63. - (UIViewController *)createMockViewControllerWithComponentId:(NSString *)componentId {
  64. RNNLayoutInfo* layoutInfo = [RNNLayoutInfo new];
  65. layoutInfo.componentId = componentId;
  66. UIViewController* vc = [UIViewController new];
  67. vc.layoutInfo = layoutInfo;
  68. return vc;
  69. }
  70. @end