123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596 |
- #import <XCTest/XCTest.h>
- #import "UIViewController+RNNOptions.h"
- #import <OCMock/OCMock.h>
- #import "RNNBottomTabOptions.h"
-
- @interface UIViewController_RNNOptionsTest : XCTestCase
-
- @property(nonatomic, retain) id uut;
-
- @end
-
- @implementation UIViewController_RNNOptionsTest
-
- - (void)setUp {
- [super setUp];
- self.uut = [OCMockObject partialMockForObject:[UIViewController new]];
- }
-
- - (void)test_setTabBarItemBadge_shouldSetValidValue {
- NSDictionary *dict = @{@"badge": @"badge"};
- RNNBottomTabOptions * options = [[RNNBottomTabOptions alloc] initWithDict:dict];
- [self.uut rnn_setTabBarItemBadge:options];
- XCTAssertEqual([self.uut tabBarItem].badgeValue, @"badge");
- }
-
- - (void)test_setTabBarItemBadge_shouldResetWhenValueIsEmptyString {
- [self.uut rnn_setTabBarItemBadge:[[RNNBottomTabOptions alloc] initWithDict:@{@"badge": @"badge"}]];
-
- RNNBottomTabOptions * optionsWithEmptyBadge = [[RNNBottomTabOptions alloc] initWithDict:@{@"badge": @""}];
- [self.uut rnn_setTabBarItemBadge:optionsWithEmptyBadge];
- XCTAssertEqual([self.uut tabBarItem].badgeValue, nil);
- }
-
- - (void)test_setTabBarItemBadge_shouldResetWhenValueIsNullObject {
- [self.uut rnn_setTabBarItemBadge:[[RNNBottomTabOptions alloc] initWithDict:@{@"badge": @"badge"}]];
- [self.uut rnn_setTabBarItemBadge:[[RNNBottomTabOptions alloc] initWithDict:@{@"badge": [NSNull new]}]];
- XCTAssertEqual([self.uut tabBarItem].badgeValue, nil);
- }
-
- - (void)testSetDrawBehindTopBarTrue_shouldSetExtendedLayoutTrue {
- [[self.uut expect] setExtendedLayoutIncludesOpaqueBars:YES];
- [self.uut rnn_setDrawBehindTopBar:YES];
- [self.uut verify];
- }
-
- - (void)testSetDrawBehindTabBarTrue_shouldSetExtendedLayoutTrue {
- [[self.uut expect] setExtendedLayoutIncludesOpaqueBars:YES];
- [self.uut rnn_setDrawBehindTabBar:YES];
- [self.uut verify];
- }
-
- - (void)testSetDrawBehindTopBarFalse_shouldNotCallExtendedLayout {
- [[self.uut reject] setExtendedLayoutIncludesOpaqueBars:NO];
- [self.uut rnn_setDrawBehindTopBar:NO];
- [self.uut verify];
- }
-
- - (void)testSetDrawBehindTabBarFalse_shouldNotCallExtendedLayout {
- [[self.uut reject] setExtendedLayoutIncludesOpaqueBars:NO];
- [self.uut rnn_setDrawBehindTabBar:NO];
- [self.uut verify];
- }
-
- - (void)testSetDrawBehindTopBarFalse_shouldSetCorrectEdgesForExtendedLayout {
- [self.uut rnn_setDrawBehindTopBar:NO];
- UIRectEdge expectedRectEdge = UIRectEdgeLeft | UIRectEdgeBottom | UIRectEdgeRight;
- XCTAssertEqual([self.uut edgesForExtendedLayout], expectedRectEdge);
- }
-
- - (void)testSetDrawBehindTapBarFalse_shouldSetCorrectEdgesForExtendedLayout {
- [self.uut rnn_setDrawBehindTabBar:NO];
- UIRectEdge expectedRectEdge = UIRectEdgeTop | UIRectEdgeLeft | UIRectEdgeRight;
- XCTAssertEqual([self.uut edgesForExtendedLayout], expectedRectEdge);
- }
-
- - (void)testSetBackgroundImageShouldNotAddViewIfImageNil {
- NSUInteger subviewsCount = [[[self.uut view] subviews] count];
- [self.uut rnn_setBackgroundImage:nil];
- XCTAssertEqual([[[self.uut view] subviews] count], subviewsCount);
- }
-
- - (void)testSetBackgroundImageShouldAddUIImageViewSubview {
- NSUInteger subviewsCount = [[[self.uut view] subviews] count];
- [self.uut rnn_setBackgroundImage:[UIImage new]];
- XCTAssertEqual([[[self.uut view] subviews] count], subviewsCount + 1);
- }
-
- - (void)testSetBackgroundImageShouldAddUIImageViewSubviewWithImage {
- UIImage *image = [UIImage new];
- [self.uut rnn_setBackgroundImage:image];
- UIImageView *imageView = [[[self.uut view] subviews] firstObject];
- XCTAssertEqual(imageView.image, image);
- }
-
- @end
|