react-native-navigation的迁移库

UIViewController+RNNOptionsTest.m 3.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  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. [self.uut rnn_setTabBarItemBadge:@"badge"];
  15. XCTAssertEqual([self.uut tabBarItem].badgeValue, @"badge");
  16. }
  17. - (void)test_setTabBarItemBadge_shouldResetWhenValueIsEmptyString {
  18. [self.uut rnn_setTabBarItemBadge:@"badge"];
  19. [self.uut rnn_setTabBarItemBadge:@""];
  20. XCTAssertEqual([self.uut tabBarItem].badgeValue, nil);
  21. }
  22. - (void)test_setTabBarItemBadge_shouldResetWhenValueIsNullObject {
  23. [self.uut rnn_setTabBarItemBadge:@"badge"];
  24. [self.uut rnn_setTabBarItemBadge:(id) [NSNull new]];
  25. XCTAssertEqual([self.uut tabBarItem].badgeValue, nil);
  26. }
  27. - (void)testSetDrawBehindTopBarTrue_shouldSetExtendedLayoutTrue {
  28. [[self.uut expect] setExtendedLayoutIncludesOpaqueBars:YES];
  29. [self.uut rnn_setDrawBehindTopBar:YES];
  30. [self.uut verify];
  31. }
  32. - (void)testSetDrawBehindTabBarTrue_shouldSetExtendedLayoutTrue {
  33. [[self.uut expect] setExtendedLayoutIncludesOpaqueBars:YES];
  34. [self.uut rnn_setDrawBehindTabBar:YES];
  35. [self.uut verify];
  36. }
  37. - (void)testSetDrawBehindTopBarFalse_shouldNotCallExtendedLayout {
  38. [[self.uut reject] setExtendedLayoutIncludesOpaqueBars:NO];
  39. [self.uut rnn_setDrawBehindTopBar:NO];
  40. [self.uut verify];
  41. }
  42. - (void)testSetDrawBehindTabBarFalse_shouldNotCallExtendedLayout {
  43. [[self.uut reject] setExtendedLayoutIncludesOpaqueBars:NO];
  44. [self.uut rnn_setDrawBehindTabBar:NO];
  45. [self.uut verify];
  46. }
  47. - (void)testSetDrawBehindTopBarFalse_shouldSetCorrectEdgesForExtendedLayout {
  48. [self.uut rnn_setDrawBehindTopBar:NO];
  49. UIRectEdge expectedRectEdge = UIRectEdgeLeft | UIRectEdgeBottom | UIRectEdgeRight;
  50. XCTAssertEqual([self.uut edgesForExtendedLayout], expectedRectEdge);
  51. }
  52. - (void)testSetDrawBehindTapBarFalse_shouldSetCorrectEdgesForExtendedLayout {
  53. [self.uut rnn_setDrawBehindTabBar:NO];
  54. UIRectEdge expectedRectEdge = UIRectEdgeTop | UIRectEdgeLeft | UIRectEdgeRight;
  55. XCTAssertEqual([self.uut edgesForExtendedLayout], expectedRectEdge);
  56. }
  57. - (void)testSetBackgroundImageShouldNotAddViewIfImageNil {
  58. NSUInteger subviewsCount = [[[self.uut view] subviews] count];
  59. [self.uut rnn_setBackgroundImage:nil];
  60. XCTAssertEqual([[[self.uut view] subviews] count], subviewsCount);
  61. }
  62. - (void)testSetBackgroundImageShouldAddUIImageViewSubview {
  63. NSUInteger subviewsCount = [[[self.uut view] subviews] count];
  64. [self.uut rnn_setBackgroundImage:[UIImage new]];
  65. XCTAssertEqual([[[self.uut view] subviews] count], subviewsCount + 1);
  66. }
  67. - (void)testSetBackgroundImageShouldAddUIImageViewSubviewWithImage {
  68. UIImage *image = [UIImage new];
  69. [self.uut rnn_setBackgroundImage:image];
  70. UIImageView *imageView = [[[self.uut view] subviews] firstObject];
  71. XCTAssertEqual(imageView.image, image);
  72. }
  73. @end