react-native-navigation的迁移库

UIViewController+RNNOptionsTest.m 3.1KB

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