Skip to content

Commit

Permalink
Merge pull request #81 from velga/master
Browse files Browse the repository at this point in the history
Added callback for custom button being pressed
  • Loading branch information
skywinder committed Oct 31, 2014
2 parents b8418ee + fb35e25 commit f17c731
Show file tree
Hide file tree
Showing 13 changed files with 612 additions and 47 deletions.
18 changes: 9 additions & 9 deletions Example-for-iOS-7-and-6/Storyboard.storyboard
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="6250" systemVersion="14A388b" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" initialViewController="HIQ-mT-eIh">
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="6245" systemVersion="14A388b" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" initialViewController="HIQ-mT-eIh">
<dependencies>
<deployment identifier="iOS"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="6244"/>
<deployment defaultVersion="1552" identifier="iOS"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="6238"/>
<capability name="Constraints to layout margins" minToolsVersion="6.0"/>
</dependencies>
<scenes>
Expand Down Expand Up @@ -88,14 +88,14 @@
<outlet property="delegate" destination="LWr-l1-uYK" id="35p-3a-Gyq"/>
</connections>
</textField>
<label opaque="NO" clipsSubviews="YES" userInteractionEnabled="NO" contentMode="left" text="Made improvements?" textAlignment="center" lineBreakMode="tailTruncation" minimumFontSize="10" translatesAutoresizingMaskIntoConstraints="NO" id="EV1-n7-TvQ">
<rect key="frame" x="16" y="378" width="285" height="17"/>
<label opaque="NO" clipsSubviews="YES" userInteractionEnabled="NO" contentMode="left" misplaced="YES" text="Made improvements?" textAlignment="center" lineBreakMode="tailTruncation" minimumFontSize="10" translatesAutoresizingMaskIntoConstraints="NO" id="EV1-n7-TvQ">
<rect key="frame" x="16" y="378" width="293" height="17"/>
<fontDescription key="fontDescription" type="system" size="system"/>
<color key="textColor" cocoaTouchSystemColor="darkTextColor"/>
<nil key="highlightedColor"/>
</label>
<label opaque="NO" clipsSubviews="YES" userInteractionEnabled="NO" contentMode="left" text="Share them here:" textAlignment="center" lineBreakMode="tailTruncation" minimumFontSize="10" translatesAutoresizingMaskIntoConstraints="NO" id="jYm-Eq-vOm">
<rect key="frame" x="104" y="403" width="110" height="17"/>
<label opaque="NO" clipsSubviews="YES" userInteractionEnabled="NO" contentMode="left" misplaced="YES" text="Share them here:" textAlignment="center" lineBreakMode="tailTruncation" minimumFontSize="10" translatesAutoresizingMaskIntoConstraints="NO" id="jYm-Eq-vOm">
<rect key="frame" x="108" y="403" width="110" height="17"/>
<fontDescription key="fontDescription" type="system" size="system"/>
<color key="textColor" cocoaTouchSystemColor="darkTextColor"/>
<nil key="highlightedColor"/>
Expand Down Expand Up @@ -136,8 +136,8 @@
<action selector="popoverButtonPressed:" destination="LWr-l1-uYK" eventType="touchUpInside" id="IL1-Uc-4kv"/>
</connections>
</button>
<textView clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="scaleToFill" editable="NO" text="https://github.com/skywinder/ActionSheetPicker-iOS6-7-3.0" textAlignment="center" translatesAutoresizingMaskIntoConstraints="NO" id="Xed-fo-wWj">
<rect key="frame" x="0.0" y="428" width="312" height="20"/>
<textView clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="scaleToFill" misplaced="YES" editable="NO" text="https://github.com/skywinder/ActionSheetPicker-iOS6-7-3.0" textAlignment="center" translatesAutoresizingMaskIntoConstraints="NO" id="Xed-fo-wWj">
<rect key="frame" x="4" y="428" width="312" height="20"/>
<constraints>
<constraint firstAttribute="width" constant="312" id="niE-2p-Xlc"/>
<constraint firstAttribute="height" constant="20" id="zdQ-5h-rir"/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,18 @@
#import <UIKit/UIKit.h>
#import <XCTest/XCTest.h>
#import <CoreActionSheetPicker/ActionSheetStringPicker.h>
#import "AbstractActionSheetPicker+CustomButton.h"
static UIView *origin;

@interface AbstractActionSheetPickerTestCase : XCTestCase
@property(nonatomic, strong) ActionSheetStringPicker *sheetStringPicker;
@property(nonatomic, strong) UIView *origin;

@end

@implementation AbstractActionSheetPickerTestCase
{
NSString *_title;
}

+(void)setUp{
UIWindow *window = [[UIApplication sharedApplication] keyWindow];
Expand All @@ -28,8 +31,8 @@ +(void)setUp{
- (void)setUp
{
[super setUp];

_sheetStringPicker = [[ActionSheetStringPicker alloc] initWithTitle:@"Title" rows:@[@"1",@"2", @"3"] initialSelection:0 doneBlock:nil cancelBlock:nil origin:origin];
_title = @"Title";
_sheetStringPicker = [[ActionSheetStringPicker alloc] initWithTitle:_title rows:@[@"1", @"2", @"3"] initialSelection:0 doneBlock:nil cancelBlock:nil origin:origin];
// Put setup code here. This method is called before the invocation of each test method in the class.
}

Expand Down Expand Up @@ -74,5 +77,105 @@ - (void)testCustomFontNameWithAttributedTextAndTextAttributes
XCTAssertNotNil(_sheetStringPicker);
}

- (void)testPickerWithCustomActionBlockOnButton
{
NSString *custom_title = @"Custom label:";

[_sheetStringPicker addCustomButtonWithTitle:custom_title actionBlock:^{
NSLog(@"Test block invoked");
}];
[_sheetStringPicker showActionSheetPicker];

[_sheetStringPicker pressFirstCustomButton];

XCTAssertNotNil(_sheetStringPicker);
}

- (void)testPickerWithCustomActionBlockOnButtonAndNilString
{
[_sheetStringPicker addCustomButtonWithTitle:nil actionBlock:^{
NSLog(@"Test block invoked");
}];
[_sheetStringPicker showActionSheetPicker];

[_sheetStringPicker pressFirstCustomButton];

XCTAssertNotNil(_sheetStringPicker);
}

- (void)testPickerWithNilCustomActionBlockOnButton
{
[_sheetStringPicker addCustomButtonWithTitle:_title actionBlock:nil];
[_sheetStringPicker showActionSheetPicker];

[_sheetStringPicker pressFirstCustomButton];

XCTAssertNotNil(_sheetStringPicker);
}

- (void)testPickerWithNilCustomActionBlockOnButtonAndNilString
{
[_sheetStringPicker addCustomButtonWithTitle:nil actionBlock:nil];
[_sheetStringPicker showActionSheetPicker];

[_sheetStringPicker pressFirstCustomButton];

XCTAssertNotNil(_sheetStringPicker);
}

- (void)testPickerWithCustomActionSelectorOnButton
{
[_sheetStringPicker addCustomButtonWithTitle:_title target:self selector:@selector(exampleSelector)];
[_sheetStringPicker showActionSheetPicker];

[_sheetStringPicker pressFirstCustomButton];

XCTAssertNotNil(_sheetStringPicker);
}

- (void)testPickerWithCustomActionSelectorOnButtonAndNilString
{
[_sheetStringPicker addCustomButtonWithTitle:nil target:self selector:@selector(exampleSelector)];
[_sheetStringPicker showActionSheetPicker];

[_sheetStringPicker pressFirstCustomButton];

XCTAssertNotNil(_sheetStringPicker);
}

- (void)testPickerWithNilCustomActionSelectorOnButton
{
[_sheetStringPicker addCustomButtonWithTitle:_title target:self selector:nil];
[_sheetStringPicker showActionSheetPicker];

[_sheetStringPicker pressFirstCustomButton];

XCTAssertNotNil(_sheetStringPicker);
}

- (void)testPickerWithCustomActionSelectorOnButtonAndNilTarget
{
[_sheetStringPicker addCustomButtonWithTitle:_title target:nil selector:@selector(exampleSelector)];
[_sheetStringPicker showActionSheetPicker];

[_sheetStringPicker pressFirstCustomButton];

XCTAssertNotNil(_sheetStringPicker);
}

- (void)testPickerWithNilCustomActionSelectorOnButtonNilTargetAndNilString
{
[_sheetStringPicker addCustomButtonWithTitle:nil target:nil selector:nil];
[_sheetStringPicker showActionSheetPicker];

[_sheetStringPicker pressFirstCustomButton];

XCTAssertNotNil(_sheetStringPicker);
}

- (void)exampleSelector
{
NSLog(@"Test selector invoked");
}

@end
142 changes: 142 additions & 0 deletions ObjC-Example/ActionSheetPicker Tests/ActionSheetDatePickerTestCase.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,142 @@
//
// ActionSheetDatePickerTestCase.m
// ActionSheetPicker
//
// Created by Vladislava Kirichenko on 10/22/14.
//
//

#import <XCTest/XCTest.h>
#import <CoreActionSheetPicker/CoreActionSheetPicker.h>
#import "AbstractActionSheetPicker+CustomButton.h"
UIView *origin;

@interface ActionSheetDatePickerTestCase : XCTestCase
@property(nonatomic, strong) ActionSheetDatePicker *actionSheetDatePicker;
@end

@implementation ActionSheetDatePickerTestCase
{
NSString *_title;
}

+(void)setUp{
UIWindow *window = [[UIApplication sharedApplication] keyWindow];
UIView *topView = window.rootViewController.view;
origin = topView;
}

- (void)setUp {
[super setUp];
_title = @"Title";
_actionSheetDatePicker = [[ActionSheetDatePicker alloc] initWithTitle:@"Test title" datePickerMode:UIDatePickerModeDate selectedDate:[NSDate date] target:nil action:nil origin:origin cancelAction:nil];
// Put setup code here. This method is called before the invocation of each test method in the class.
}

- (void)tearDown {
// Put teardown code here. This method is called after the invocation of each test method in the class.
[super tearDown];
}

- (void)testPickerWithCustomActionBlockOnButton
{
NSString *custom_title = @"Custom label:";

[_actionSheetDatePicker addCustomButtonWithTitle:custom_title actionBlock:^{
NSLog(@"Test block invoked");
}];
[_actionSheetDatePicker showActionSheetPicker];

[_actionSheetDatePicker pressFirstCustomButton];

XCTAssertNotNil(_actionSheetDatePicker);
}

- (void)testPickerWithCustomActionBlockOnButtonAndNilString
{
[_actionSheetDatePicker addCustomButtonWithTitle:nil actionBlock:^{
NSLog(@"Test block invoked");
}];
[_actionSheetDatePicker showActionSheetPicker];

[_actionSheetDatePicker pressFirstCustomButton];

XCTAssertNotNil(_actionSheetDatePicker);
}

- (void)testPickerWithNilCustomActionBlockOnButton
{
[_actionSheetDatePicker addCustomButtonWithTitle:_title actionBlock:nil];
[_actionSheetDatePicker showActionSheetPicker];

[_actionSheetDatePicker pressFirstCustomButton];

XCTAssertNotNil(_actionSheetDatePicker);
}

- (void)testPickerWithNilCustomActionBlockOnButtonAndNilString
{
[_actionSheetDatePicker addCustomButtonWithTitle:nil actionBlock:nil];
[_actionSheetDatePicker showActionSheetPicker];

[_actionSheetDatePicker pressFirstCustomButton];

XCTAssertNotNil(_actionSheetDatePicker);
}

- (void)testPickerWithCustomActionSelectorOnButton
{
[_actionSheetDatePicker addCustomButtonWithTitle:_title target:self selector:@selector(exampleSelector)];
[_actionSheetDatePicker showActionSheetPicker];

[_actionSheetDatePicker pressFirstCustomButton];

XCTAssertNotNil(_actionSheetDatePicker);
}

- (void)testPickerWithCustomActionSelectorOnButtonAndNilString
{
[_actionSheetDatePicker addCustomButtonWithTitle:nil target:self selector:@selector(exampleSelector)];
[_actionSheetDatePicker showActionSheetPicker];

[_actionSheetDatePicker pressFirstCustomButton];

XCTAssertNotNil(_actionSheetDatePicker);
}

- (void)testPickerWithNilCustomActionSelectorOnButton
{
[_actionSheetDatePicker addCustomButtonWithTitle:_title target:self selector:nil];
[_actionSheetDatePicker showActionSheetPicker];

[_actionSheetDatePicker pressFirstCustomButton];

XCTAssertNotNil(_actionSheetDatePicker);
}

- (void)testPickerWithCustomActionSelectorOnButtonAndNilTarget
{
[_actionSheetDatePicker addCustomButtonWithTitle:_title target:nil selector:@selector(exampleSelector)];
[_actionSheetDatePicker showActionSheetPicker];

[_actionSheetDatePicker pressFirstCustomButton];

XCTAssertNotNil(_actionSheetDatePicker);
}

- (void)testPickerWithNilCustomActionSelectorOnButtonNilTargetAndNilString
{
[_actionSheetDatePicker addCustomButtonWithTitle:nil target:nil selector:nil];
[_actionSheetDatePicker showActionSheetPicker];

[_actionSheetDatePicker pressFirstCustomButton];

XCTAssertNotNil(_actionSheetDatePicker);
}

- (void)exampleSelector
{
NSLog(@"Test selector invoked");
}

@end
Loading

0 comments on commit f17c731

Please sign in to comment.