Skip to content

Commit

Permalink
Add tests to cover setting background images from a subdirectory with…
Browse files Browse the repository at this point in the history
…in the app bundle
  • Loading branch information
johntmcintosh committed Aug 6, 2014
1 parent 1d0199b commit 3687253
Show file tree
Hide file tree
Showing 5 changed files with 159 additions and 0 deletions.
10 changes: 10 additions & 0 deletions Demo/NUIDemo.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,9 @@
4AAAFE7C166FD32600A0D34D /* [email protected] in Resources */ = {isa = PBXBuildFile; fileRef = 4AAAFE7B166FD32600A0D34D /* [email protected] */; };
4ADA71C616A0F15C00BDCF81 /* UISearchBar+NUI.m in Sources */ = {isa = PBXBuildFile; fileRef = 4ADA71C516A0F15C00BDCF81 /* UISearchBar+NUI.m */; };
4ADA71CA16A103CD00BDCF81 /* NUISearchBarRenderer.m in Sources */ = {isa = PBXBuildFile; fileRef = 4ADA71C916A103CD00BDCF81 /* NUISearchBarRenderer.m */; };
5B5888C31992BD15005F1ACB /* Assets in Resources */ = {isa = PBXBuildFile; fileRef = 5B5888C21992BD15005F1ACB /* Assets */; };
5B5888C41992BD1C005F1ACB /* Assets in Resources */ = {isa = PBXBuildFile; fileRef = 5B5888C21992BD15005F1ACB /* Assets */; };
5B5888C61992BDA7005F1ACB /* NUIButtonRendererSubdirectoryImageTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 5B5888C51992BDA7005F1ACB /* NUIButtonRendererSubdirectoryImageTests.m */; };
832B9C1B176AEADA0054F06E /* iPad Storyboard.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 832B9C19176AEADA0054F06E /* iPad Storyboard.storyboard */; };
832B9C1E176AEAED0054F06E /* iPhone Storyboard.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 832B9C1C176AEAED0054F06E /* iPhone Storyboard.storyboard */; };
89B940701671418200850A9A /* NUIAppearance.m in Sources */ = {isa = PBXBuildFile; fileRef = 89B940241671418100850A9A /* NUIAppearance.m */; };
Expand Down Expand Up @@ -213,6 +216,8 @@
4ADA71C516A0F15C00BDCF81 /* UISearchBar+NUI.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "UISearchBar+NUI.m"; sourceTree = "<group>"; };
4ADA71C816A103CD00BDCF81 /* NUISearchBarRenderer.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = NUISearchBarRenderer.h; sourceTree = "<group>"; };
4ADA71C916A103CD00BDCF81 /* NUISearchBarRenderer.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = NUISearchBarRenderer.m; sourceTree = "<group>"; };
5B5888C21992BD15005F1ACB /* Assets */ = {isa = PBXFileReference; lastKnownFileType = folder; path = Assets; sourceTree = "<group>"; };
5B5888C51992BDA7005F1ACB /* NUIButtonRendererSubdirectoryImageTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = NUIButtonRendererSubdirectoryImageTests.m; sourceTree = "<group>"; };
7CC7736AC8944034A5E10550 /* libPods-NUITests.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = "libPods-NUITests.a"; sourceTree = BUILT_PRODUCTS_DIR; };
832B9C1A176AEADA0054F06E /* en */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = en; path = "en.lproj/iPad Storyboard.storyboard"; sourceTree = "<group>"; };
832B9C1D176AEAED0054F06E /* en */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = en; path = "en.lproj/iPhone Storyboard.storyboard"; sourceTree = "<group>"; };
Expand Down Expand Up @@ -335,6 +340,7 @@
0E55160E1938727100B293B7 /* TestResources */ = {
isa = PBXGroup;
children = (
5B5888C21992BD15005F1ACB /* Assets */,
0E55161E19388C1E00B293B7 /* foreground_image.png */,
0E55161F19388C1E00B293B7 /* [email protected] */,
0E5516111938738C00B293B7 /* background_image.png */,
Expand All @@ -359,6 +365,7 @@
0E55162619388EC900B293B7 /* NUIButtonRendererBackgroundColorTests.m */,
0E55161A1938891000B293B7 /* NUIButtonRendererBackgroundImageTests.m */,
0E55162419388CC500B293B7 /* NUIButtonRendererForegroundImageTests.m */,
5B5888C51992BDA7005F1ACB /* NUIButtonRendererSubdirectoryImageTests.m */,
0E55161B1938891000B293B7 /* NUIButtonRendererTests.m */,
);
path = UIButton;
Expand Down Expand Up @@ -742,6 +749,7 @@
0EE9CA7C191EC96D00C84934 /* TestTheme.NUI.nss in Resources */,
0E8A86B918EC07C40027F275 /* InfoPlist.strings in Resources */,
0E55162319388C1E00B293B7 /* [email protected] in Resources */,
5B5888C31992BD15005F1ACB /* Assets in Resources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand All @@ -752,6 +760,7 @@
0EE9CA7D191ECA0F00C84934 /* TestTheme.NUI.nss in Resources */,
4A0B8640165EE59A005B5756 /* InfoPlist.strings in Resources */,
4AAAFE7C166FD32600A0D34D /* [email protected] in Resources */,
5B5888C41992BD1C005F1ACB /* Assets in Resources */,
89B940811671418200850A9A /* NUIStyle.nss in Resources */,
89B940841671418200850A9A /* NUIViewBackground.png in Resources */,
4A9965E5169FB56800DAA38A /* Blue.NUI.nss in Resources */,
Expand Down Expand Up @@ -840,6 +849,7 @@
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
files = (
5B5888C61992BDA7005F1ACB /* NUIButtonRendererSubdirectoryImageTests.m in Sources */,
0E5516301938D61300B293B7 /* UIBarButtonRendererBackgroundImageTests.m in Sources */,
0E55162719388EC900B293B7 /* NUIButtonRendererBackgroundColorTests.m in Sources */,
0E55161D1938891000B293B7 /* NUIButtonRendererTests.m in Sources */,
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
15 changes: 15 additions & 0 deletions Demo/NUITests/TestTheme.NUI.nss
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,21 @@ ButtonWithImage {
image-selected-highlighted-insets: 2;
}

ButtonWithImageFromSubdirectory {
background-image: Assets/subdirectory_image;
background-image-disabled: Assets/subdirectory_image;
background-image-highlighted: Assets/subdirectory_image;
background-image-selected: Assets/subdirectory_image;
background-image-selected-disabled: Assets/subdirectory_image;
background-image-selected-highlighted: Assets/subdirectory_image;
image: Assets/subdirectory_image;
image-disabled: Assets/subdirectory_image;
image-highlighted: Assets/subdirectory_image;
image-selected: Assets/subdirectory_image;
image-selected-disabled: Assets/subdirectory_image;
image-selected-highlighted: Assets/subdirectory_image;
}

ButtonWithColor {
background-color: red;
background-color-disabled: green;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,134 @@
//
// NUIButtonRendererSubdirectoryImageTests.m
// NUIDemo
//
// Created by Paul Williamson on 06/08/2014.
// Copyright (c) 2014 John McIntosh. All rights reserved.
//

#import <XCTest/XCTest.h>

#import "UIButton+NUI.h"
#import <UIImage+Compare.h>

static NSString * const NUIButtonSubdirectoryImageTestsStyleClass = @"ButtonWithImageFromSubdirectory";

@interface NUIButtonRendererSubdirectoryImageTests : XCTestCase
@property (strong, nonatomic) UIButton *sut;
@end

@implementation NUIButtonRendererSubdirectoryImageTests

- (void)setUp
{
[super setUp];

[NUISettings initWithStylesheet:@"TestTheme.NUI"];

_sut = [[UIButton alloc] init];
_sut.nuiClass = NUIButtonSubdirectoryImageTestsStyleClass;
[_sut setTitle:@"button" forState:UIControlStateNormal];

[_sut applyNUI];
}

- (void)tearDown
{
_sut = nil;

[super tearDown];
}

#pragma mark - Background Image

- (BOOL)equalBackgroundImagesWithState:(UIControlState)state
{
UIImage *image = [UIImage imageNamed:@"Assets/subdirectory_image"];
UIImage *buttonImage = [_sut backgroundImageForState:state];

return [buttonImage compareWithImage:image];
}

- (BOOL)equalForegroundImagesWithState:(UIControlState)state
{
UIImage *image = [UIImage imageNamed:@"Assets/subdirectory_image"];
UIImage *buttonImage = [_sut imageForState:state];

return [buttonImage compareWithImage:image];
}

// background-image (Image)
- (void)testSetBackgroundImage
{
XCTAssertTrue([self equalBackgroundImagesWithState:UIControlStateNormal], @"NUI should set button background image");
}

// background-image-disabled (Image)
- (void)testSetBackgroundImageDisabled
{
XCTAssertTrue([self equalBackgroundImagesWithState:UIControlStateDisabled], @"NUI should set button background image for disabled state");
}

// background-image-highlighted (Image)
- (void)testSetBackgroundImageHighlighted
{
XCTAssertTrue([self equalBackgroundImagesWithState:UIControlStateHighlighted], @"NUI should set button background image for highlighted state");
}

// background-image-selected (Image)
- (void)testSetBackgroundImageSelected
{
XCTAssertTrue([self equalBackgroundImagesWithState:UIControlStateSelected], @"NUI should set button background image for selected state");
}

// background-image-selected-disabled (Image)
- (void)testSetBackgroundImageSelectedDisabled
{
XCTAssertTrue([self equalBackgroundImagesWithState:UIControlStateSelected|UIControlStateDisabled], @"NUI should set button background image when selected and disabled");
}

// background-image-selected-highlighted (Image)
- (void)testSetBackgroundImageSelectedHighlighted
{
XCTAssertTrue([self equalBackgroundImagesWithState:UIControlStateSelected|UIControlStateHighlighted], @"NUI should set button background image when selected and highlighted");
}

#pragma mark - Foreground Image

// image (Image)
- (void)testSetImage
{
XCTAssertTrue([self equalForegroundImagesWithState:UIControlStateNormal], @"NUI should set button image");
}

// -image-disabled (Image)
- (void)testSetImageDisabled
{
XCTAssertTrue([self equalForegroundImagesWithState:UIControlStateDisabled], @"NUI should set button image for disabled state");
}

// -image-highlighted (Image)
- (void)testSetImageHighlighted
{
XCTAssertTrue([self equalForegroundImagesWithState:UIControlStateHighlighted], @"NUI should set button image for highlighted state");
}

// -image-selected (Image)
- (void)testSetImageSelected
{
XCTAssertTrue([self equalForegroundImagesWithState:UIControlStateSelected], @"NUI should set button image for selected state");
}

// -image-selected-disabled (Image)
- (void)testSetImageSelectedDisabled
{
XCTAssertTrue([self equalForegroundImagesWithState:UIControlStateSelected|UIControlStateDisabled], @"NUI should set button image when selected and disabled");
}

// -image-selected-highlighted (Image)
- (void)testSetImageSelectedHighlighted
{
XCTAssertTrue([self equalForegroundImagesWithState:UIControlStateSelected|UIControlStateHighlighted], @"NUI should set button image when selected and highlighted");
}

@end

0 comments on commit 3687253

Please sign in to comment.