forked from BlocksKit/BlocksKit
-
Notifications
You must be signed in to change notification settings - Fork 0
/
UIAlertViewBlocksKitTest.m
80 lines (57 loc) · 3 KB
/
UIAlertViewBlocksKitTest.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
//
// UIAlertViewBlocksKitTest.m
// BlocksKit Unit Tests
//
#import <XCTest/XCTest.h>
#import <BlocksKit/UIAlertView+BlocksKit.h>
#import <BlocksKit/A2DynamicDelegate.h>
@interface UIAlertViewBlocksKitTest : XCTestCase
@end
@implementation UIAlertViewBlocksKitTest {
UIAlertView *_subject;
}
- (void)setUp {
_subject = [[UIAlertView alloc] bk_initWithTitle:@"Hello BlocksKit" message:@"This is a message."];
}
- (void)testInit {
XCTAssertTrue([_subject isKindOfClass:[UIAlertView class]],@"subject is UIAlertView");
XCTAssertTrue([_subject.delegate isEqual:_subject.bk_dynamicDelegate], @"the delegate is not dynamic");
XCTAssertEqualObjects(_subject.title,@"Hello BlocksKit",@"the UIAlertView title is %@",_subject.title);
XCTAssertEqual(_subject.numberOfButtons, (NSInteger)0,@"the action sheet has %ld buttons", (long)_subject.numberOfButtons);
XCTAssertFalse(_subject.isVisible,@"the action sheet is not visible");
}
- (void)testAddButtonWithHandler {
__block NSInteger total = 0;
NSInteger index1 = [_subject bk_addButtonWithTitle:@"Button 1" handler:^{ total++; }];
NSInteger index2 = [_subject bk_addButtonWithTitle:@"Button 2" handler:^{ total += 2; }];
XCTAssertEqual(_subject.numberOfButtons,(NSInteger)2,@"the alert view has %ld buttons", (long)_subject.numberOfButtons);
NSString *title = @"Button";
title = [_subject buttonTitleAtIndex:index1];
XCTAssertEqualObjects(title,@"Button 1",@"the UIActionSheet adds a button with title %@",title);
title = [_subject buttonTitleAtIndex:index2];
XCTAssertEqualObjects(title,@"Button 2",@"the UIActionSheet adds a button with title %@",title);
[_subject.bk_dynamicDelegate alertView:_subject clickedButtonAtIndex:index1];
[_subject.bk_dynamicDelegate alertView:_subject clickedButtonAtIndex:index2];
XCTAssertEqual(total, (NSInteger)3, @"Not all block handlers were called.");
}
- (void)testSetCancelButtonWithHandler {
__block BOOL blockCalled = NO;
NSInteger index = [_subject bk_setCancelButtonWithTitle:@"Cancel" handler:^{ blockCalled = YES; }];
XCTAssertEqual(_subject.numberOfButtons,(NSInteger)1,@"the alert view has %ld buttons", (long)_subject.numberOfButtons);
XCTAssertEqual(_subject.cancelButtonIndex,(NSInteger)index,@"the alert view cancel button index is %ld", (long)_subject.cancelButtonIndex);
NSString *title = [_subject buttonTitleAtIndex:index];
XCTAssertEqualObjects(title,@"Cancel",@"the UIActionSheet adds a button with title %@",title);
[_subject.bk_dynamicDelegate alertViewCancel:_subject];
XCTAssertTrue(blockCalled, @"Block handler was not called.");
}
- (void)testDelegationBlocks {
__block BOOL willShow = NO;
__block BOOL didShow = NO;
_subject.bk_willShowBlock = ^(UIAlertView *view) { willShow = YES; };
_subject.bk_didShowBlock = ^(UIAlertView *view) { didShow = YES; };
[_subject.bk_dynamicDelegate willPresentAlertView:_subject];
[_subject.bk_dynamicDelegate didPresentAlertView:_subject];
XCTAssertTrue(willShow, @"willShowBlock not fired.");
XCTAssertTrue(didShow, @"didShowblock not fired.");
}
@end