react-native-navigation的迁移库

UIViewController+RNNOptionsTest.m 3.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. #import <XCTest/XCTest.h>
  2. #import "UIViewController+RNNOptions.h"
  3. #import <OCMock/OCMock.h>
  4. #import "RNNBottomTabOptions.h"
  5. @interface UIViewController_RNNOptionsTest : XCTestCase
  6. @property(nonatomic, retain) id uut;
  7. @end
  8. @implementation UIViewController_RNNOptionsTest
  9. - (void)setUp {
  10. [super setUp];
  11. self.uut = [OCMockObject partialMockForObject:[UIViewController new]];
  12. }
  13. - (void)test_setTabBarItemBadge_shouldSetValidValue {
  14. NSDictionary *dict = @{@"badge": @"badge"};
  15. RNNBottomTabOptions * options = [[RNNBottomTabOptions alloc] initWithDict:dict];
  16. [self.uut rnn_setTabBarItemBadge:options];
  17. XCTAssertEqual([self.uut tabBarItem].badgeValue, @"badge");
  18. }
  19. - (void)test_setTabBarItemBadge_shouldResetWhenValueIsEmptyString {
  20. [self.uut rnn_setTabBarItemBadge:[[RNNBottomTabOptions alloc] initWithDict:@{@"badge": @"badge"}]];
  21. RNNBottomTabOptions * optionsWithEmptyBadge = [[RNNBottomTabOptions alloc] initWithDict:@{@"badge": @""}];
  22. [self.uut rnn_setTabBarItemBadge:optionsWithEmptyBadge];
  23. XCTAssertEqual([self.uut tabBarItem].badgeValue, nil);
  24. }
  25. - (void)test_setTabBarItemBadge_shouldResetWhenValueIsNullObject {
  26. [self.uut rnn_setTabBarItemBadge:[[RNNBottomTabOptions alloc] initWithDict:@{@"badge": @"badge"}]];
  27. [self.uut rnn_setTabBarItemBadge:[[RNNBottomTabOptions alloc] initWithDict:@{@"badge": [NSNull new]}]];
  28. XCTAssertEqual([self.uut tabBarItem].badgeValue, nil);
  29. }
  30. - (void)testSetDrawBehindTopBarTrue_shouldSetExtendedLayoutTrue {
  31. [[self.uut expect] setExtendedLayoutIncludesOpaqueBars:YES];
  32. [self.uut rnn_setDrawBehindTopBar:YES];
  33. [self.uut verify];
  34. }
  35. - (void)testSetDrawBehindTabBarTrue_shouldSetExtendedLayoutTrue {
  36. [[self.uut expect] setExtendedLayoutIncludesOpaqueBars:YES];
  37. [self.uut rnn_setDrawBehindTabBar:YES];
  38. [self.uut verify];
  39. }
  40. - (void)testSetDrawBehindTopBarFalse_shouldNotCallExtendedLayout {
  41. [[self.uut reject] setExtendedLayoutIncludesOpaqueBars:NO];
  42. [self.uut rnn_setDrawBehindTopBar:NO];
  43. [self.uut verify];
  44. }
  45. - (void)testSetDrawBehindTabBarFalse_shouldNotCallExtendedLayout {
  46. [[self.uut reject] setExtendedLayoutIncludesOpaqueBars:NO];
  47. [self.uut rnn_setDrawBehindTabBar:NO];
  48. [self.uut verify];
  49. }
  50. - (void)testSetDrawBehindTopBarFalse_shouldSetCorrectEdgesForExtendedLayout {
  51. [self.uut rnn_setDrawBehindTopBar:NO];
  52. UIRectEdge expectedRectEdge = UIRectEdgeLeft | UIRectEdgeBottom | UIRectEdgeRight;
  53. XCTAssertEqual([self.uut edgesForExtendedLayout], expectedRectEdge);
  54. }
  55. - (void)testSetDrawBehindTapBarFalse_shouldSetCorrectEdgesForExtendedLayout {
  56. [self.uut rnn_setDrawBehindTabBar:NO];
  57. UIRectEdge expectedRectEdge = UIRectEdgeTop | UIRectEdgeLeft | UIRectEdgeRight;
  58. XCTAssertEqual([self.uut edgesForExtendedLayout], expectedRectEdge);
  59. }
  60. - (void)testSetBackgroundImageShouldNotAddViewIfImageNil {
  61. NSUInteger subviewsCount = [[[self.uut view] subviews] count];
  62. [self.uut rnn_setBackgroundImage:nil];
  63. XCTAssertEqual([[[self.uut view] subviews] count], subviewsCount);
  64. }
  65. - (void)testSetBackgroundImageShouldAddUIImageViewSubview {
  66. NSUInteger subviewsCount = [[[self.uut view] subviews] count];
  67. [self.uut rnn_setBackgroundImage:[UIImage new]];
  68. XCTAssertEqual([[[self.uut view] subviews] count], subviewsCount + 1);
  69. }
  70. - (void)testSetBackgroundImageShouldAddUIImageViewSubviewWithImage {
  71. UIImage *image = [UIImage new];
  72. [self.uut rnn_setBackgroundImage:image];
  73. UIImageView *imageView = [[[self.uut view] subviews] firstObject];
  74. XCTAssertEqual(imageView.image, image);
  75. }
  76. @end