react-native-navigation的迁移库

UIViewController+LayoutProtocolTest.m 3.3KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. #import <XCTest/XCTest.h>
  2. #import <OCMock/OCMock.h>
  3. #import "UIViewController+LayoutProtocol.h"
  4. #import "UIViewController+RNNOptions.h"
  5. #import "RNNViewControllerPresenter.h"
  6. #import "RCTConvert+Modal.h"
  7. @interface UIViewController_LayoutProtocolTest : XCTestCase
  8. @property (nonatomic, retain) UIViewController* uut;
  9. @end
  10. @implementation UIViewController_LayoutProtocolTest
  11. - (void)setUp {
  12. [super setUp];
  13. self.uut = [OCMockObject partialMockForObject:[UIViewController new]];
  14. self.uut.layoutInfo = [[RNNLayoutInfo alloc] init];
  15. self.uut.layoutInfo.componentId = @"componentId";
  16. }
  17. - (void)testInitWithLayoutApplyDefaultOptions {
  18. RNNViewControllerPresenter* presenter = [[RNNViewControllerPresenter alloc] init];
  19. RNNNavigationOptions* options = [[RNNNavigationOptions alloc] initEmptyOptions];
  20. RNNNavigationOptions* defaultOptions = [[RNNNavigationOptions alloc] initEmptyOptions];
  21. defaultOptions.modalPresentationStyle = [[Text alloc] initWithValue:@"fullScreen"];
  22. UIViewController* uut = [[UIViewController alloc] initWithLayoutInfo:nil creator:nil options:options defaultOptions:defaultOptions presenter:presenter eventEmitter:nil childViewControllers:nil];
  23. XCTAssertEqual(uut.modalPresentationStyle, [RCTConvert UIModalPresentationStyle:@"fullScreen"]);
  24. }
  25. - (void)testInitWithLayoutInfoShouldSetChildViewControllers {
  26. UIViewController* child1 = [UIViewController new];
  27. UIViewController* child2 = [UIViewController new];
  28. NSArray* childViewControllers = @[child1, child2];
  29. UINavigationController* uut = [[UINavigationController alloc] initWithLayoutInfo:nil creator:nil options:nil defaultOptions:nil presenter:nil eventEmitter:nil childViewControllers:childViewControllers];
  30. XCTAssertEqual(uut.viewControllers[0], child1);
  31. XCTAssertEqual(uut.viewControllers[1], child2);
  32. }
  33. - (void)testSetBackButtonIcon_withColor_shouldSetColor {
  34. UIViewController* uut = [UIViewController new];
  35. [[UINavigationController alloc] initWithRootViewController:uut];
  36. UIColor* color = [UIColor blackColor];
  37. [uut rnn_setBackButtonIcon:nil withColor:color title:nil];
  38. XCTAssertEqual(color, uut.navigationItem.backBarButtonItem.tintColor);
  39. }
  40. - (void)testSetBackButtonIcon_withColor_shouldSetTitle {
  41. UIViewController* uut = [UIViewController new];
  42. UINavigationController* nav = [[UINavigationController alloc] initWithRootViewController:uut];
  43. NSString* title = @"Title";
  44. [uut rnn_setBackButtonIcon:nil withColor:nil title:title];
  45. XCTAssertEqual(title, uut.navigationItem.backBarButtonItem.title);
  46. }
  47. - (void)testSetBackButtonIcon_withColor_shouldSetIcon {
  48. UIViewController* uut = [UIViewController new];
  49. UINavigationController* nav = [[UINavigationController alloc] initWithRootViewController:uut];
  50. UIImage* icon = [UIImage new];
  51. [uut rnn_setBackButtonIcon:icon withColor:nil title:nil];
  52. XCTAssertEqual(icon, uut.navigationItem.backBarButtonItem.image);
  53. }
  54. - (void)testSetBackButtonIcon_shouldSetTitleOnPreviousViewControllerIfExists {
  55. UIViewController* uut = [UIViewController new];
  56. UIViewController* viewController2 = [UIViewController new];
  57. UINavigationController* nav = [[UINavigationController alloc] init];
  58. [nav setViewControllers:@[uut, viewController2]];
  59. NSString* title = @"Title";
  60. [uut rnn_setBackButtonIcon:nil withColor:nil title:title];
  61. XCTAssertEqual(title, uut.navigationItem.backBarButtonItem.title);
  62. }
  63. @end