react-native-navigation的迁移库

RNNLayoutManagerTest.m 3.0KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  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* modal = _vc1;
  37. OCMStub([_vc2 presentedViewController]).andReturn(modal);
  38. _firstWindow.rootViewController = _vc2;
  39. UIViewController *resultVC = [RNNLayoutManager findComponentForId:@"vc1"];
  40. XCTAssertEqual(resultVC, modal);
  41. }
  42. - (void)testFindComponentShouldReturnModalFromSecondWindow {
  43. UIViewController* modal = _vc1;
  44. OCMStub([_vc2 presentedViewController]).andReturn(modal);
  45. _secondWindow.rootViewController = _vc2;
  46. UIViewController *resultVC = [RNNLayoutManager findComponentForId:@"vc1"];
  47. XCTAssertEqual(resultVC, modal);
  48. }
  49. - (void)testFindComponentShouldReturnNilForUndefindComponent {
  50. _firstWindow.rootViewController = _vc1;
  51. UIViewController *resultVC = [RNNLayoutManager findComponentForId:@"vvc"];
  52. XCTAssertNil(resultVC);
  53. }
  54. - (void)testFindComponentShouldFindRootViewControllerChildViewController {
  55. UINavigationController* nvc = [[UINavigationController alloc] init];
  56. [nvc setViewControllers:@[_vc1, _vc2, _vc3]];
  57. _secondWindow.rootViewController = nvc;
  58. UIViewController *resultVC = [RNNLayoutManager findComponentForId:@"vc3"];
  59. XCTAssertEqual(resultVC, _vc3);
  60. }
  61. - (UIViewController *)createMockViewControllerWithComponentId:(NSString *)componentId {
  62. RNNLayoutInfo* layoutInfo = [RNNLayoutInfo new];
  63. layoutInfo.componentId = componentId;
  64. UIViewController* vc = [OCMockObject partialMockForObject:[UIViewController new]];
  65. OCMStub([vc layoutInfo]).andReturn(layoutInfo);
  66. return vc;
  67. }
  68. @end