Skip to content

Commit

Permalink
add test for new init methods in #98
Browse files Browse the repository at this point in the history
  • Loading branch information
skywinder committed Dec 2, 2014
1 parent 5bc5ff4 commit 6abb206
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

#import <XCTest/XCTest.h>
#import <CoreActionSheetPicker/CoreActionSheetPicker.h>
#import <CoreActionSheetPicker/ActionSheetDatePicker.h>
#import "AbstractActionSheetPicker+CustomButton.h"

static const int countdownTestInt = 360;
Expand Down Expand Up @@ -73,6 +74,12 @@ - (void)testInitPicker5
XCTAssertNotNil(_actionSheetDatePicker);
}

- (void)testInitPicker6
{
_actionSheetDatePicker = [[ActionSheetDatePicker alloc] initWithTitle:@"" datePickerMode:UIDatePickerModeCountDownTimer selectedDate:NSDate.date minimumDate:NSDate.date maximumDate:NSDate.date target:self action:@selector(exampleSelector) cancelAction:@selector(exampleSelector) origin:origin];
XCTAssertNotNil(_actionSheetDatePicker);
}

- (void)testPickerWithCustomActionBlockOnButton
{
NSString *custom_title = @"Custom label:";
Expand Down
4 changes: 2 additions & 2 deletions Pickers/ActionSheetDatePicker.h
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ typedef void(^ActionDateCancelBlock)(ActionSheetDatePicker *picker);

- (id)initWithTitle:(NSString *)title datePickerMode:(UIDatePickerMode)datePickerMode selectedDate:(NSDate *)selectedDate target:(id)target action:(SEL)action origin:(id)origin cancelAction:(SEL)cancelAction;

- (id)initWithTitle:(NSString *)title datePickerMode:(UIDatePickerMode)datePickerMode selectedDate:(NSDate *)selectedDate minimumDate:(NSDate *)minimumDate maximumDate:(NSDate *)maximumDate target:(id)target action:(SEL)action origin:(id)origin cancelAction:(SEL)cancelAction;
- (id)initWithTitle:(NSString *)title datePickerMode:(UIDatePickerMode)datePickerMode selectedDate:(NSDate *)selectedDate minimumDate:(NSDate *)minimumDate maximumDate:(NSDate *)maximumDate target:(id)target action:(SEL)action cancelAction:(SEL)cancelAction origin:(id)origin;


- (instancetype)initWithTitle:(NSString *)title
Expand All @@ -90,4 +90,4 @@ typedef void(^ActionDateCancelBlock)(ActionSheetDatePicker *picker);

- (void)eventForDatePicker:(id)sender;

@end
@end
22 changes: 11 additions & 11 deletions Pickers/ActionSheetDatePicker.m
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ - (id)initWithTitle:(NSString *)title datePickerMode:(UIDatePickerMode)datePicke
return self;
}

- (id)initWithTitle:(NSString *)title datePickerMode:(UIDatePickerMode)datePickerMode selectedDate:(NSDate *)selectedDate minimumDate:(NSDate *)minimumDate maximumDate:(NSDate *)maximumDate target:(id)target action:(SEL)action origin:(id)origin cancelAction:(SEL)cancelAction
- (id)initWithTitle:(NSString *)title datePickerMode:(UIDatePickerMode)datePickerMode selectedDate:(NSDate *)selectedDate minimumDate:(NSDate *)minimumDate maximumDate:(NSDate *)maximumDate target:(id)target action:(SEL)action cancelAction:(SEL)cancelAction origin:(id)origin
{
self = [super initWithTarget:target successAction:action cancelAction:cancelAction origin:origin];
if (self) {
Expand Down Expand Up @@ -156,20 +156,20 @@ - (UIView *)configuredPickerView {
datePicker.calendar = self.calendar;
datePicker.timeZone = self.timeZone;
datePicker.locale = self.locale;

// if datepicker is set with a date in countDownMode then
// 1h is added to the initial countdown
if (self.datePickerMode == UIDatePickerModeCountDownTimer) {
datePicker.countDownDuration = self.countDownDuration;
} else {
[datePicker setDate:self.selectedDate animated:NO];
}

[datePicker addTarget:self action:@selector(eventForDatePicker:) forControlEvents:UIControlEventValueChanged];

//need to keep a reference to the picker so we can clear the DataSource / Delegate when dismissing (not used in this picker, but just in case somebody uses this as a template for another picker)
self.pickerView = datePicker;

return datePicker;
}

Expand All @@ -181,15 +181,15 @@ - (void)notifyTarget:(id)target didSucceedWithAction:(SEL)action origin:(id)orig
self.onActionSheetDone(self, @(((UIDatePicker *)self.pickerView).countDownDuration), origin);
else
self.onActionSheetDone(self, self.selectedDate, origin);

return;
}
else if ([target respondsToSelector:action])
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Warc-performSelector-leaks"
if (self.datePickerMode == UIDatePickerModeCountDownTimer) {
[target performSelector:action withObject:@(((UIDatePicker *)self.pickerView).countDownDuration) withObject:origin];

} else {
[target performSelector:action withObject:self.selectedDate withObject:origin];
}
Expand Down Expand Up @@ -230,7 +230,7 @@ - (void)customButtonPressed:(id)sender {
NSAssert((index >= 0 && index < self.customButtons.count), @"Bad custom button tag: %zd, custom button count: %zd", index, self.customButtons.count);
NSDictionary *buttonDetails = (self.customButtons)[(NSUInteger) index];
NSAssert(buttonDetails != NULL, @"Custom button dictionary is invalid");

ActionType actionType = (ActionType) [buttonDetails[kActionType] integerValue];
switch (actionType) {
case Value: {
Expand All @@ -244,16 +244,16 @@ - (void)customButtonPressed:(id)sender {
}
break;
}

case Block:
case Selector:
[super customButtonPressed:sender];
break;

default:
NSAssert(false, @"Unknown action type");
break;
}
}

@end
@end

0 comments on commit 6abb206

Please sign in to comment.