-
Notifications
You must be signed in to change notification settings - Fork 54
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #243 from inkling/jeff/action_sheets_and_nav_bars
Add support for manipulating action sheets and nav bars.
- Loading branch information
Showing
25 changed files
with
1,010 additions
and
110 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,112 @@ | ||
// | ||
// SLActionSheetTest.m | ||
// Subliminal | ||
// | ||
// Created by Jeffrey Wear on 5/26/14. | ||
// Copyright (c) 2014 Inkling. All rights reserved. | ||
// | ||
|
||
#import "SLIntegrationTest.h" | ||
|
||
@interface SLActionSheetTest : SLIntegrationTest | ||
|
||
@end | ||
|
||
@implementation SLActionSheetTest | ||
|
||
+ (NSString *)testCaseViewControllerClassName { | ||
return @"SLActionSheetTestViewController"; | ||
} | ||
|
||
- (void)tearDownTestCaseWithSelector:(SEL)testCaseSelector { | ||
SLAskApp(dismissActionSheet); | ||
|
||
if (([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPad) && | ||
((testCaseSelector == @selector(testButtonsIncludesTheCancelButtonIfPresent)) || | ||
(testCaseSelector == @selector(testCanMatchCancelButton)))) { | ||
SLAskApp(dismissPopover); | ||
} | ||
|
||
[super tearDownTestCaseWithSelector:testCaseSelector]; | ||
} | ||
|
||
- (void)testCanMatchActionSheet { | ||
SLAskApp1(showActionSheetWithInfo:, @{ @"title": @"Action!" }); | ||
|
||
CGRect actionSheetRect, expectedActionSheetRect = [SLAskApp(actionSheetFrameValue) CGRectValue]; | ||
SLAssertNoThrow(actionSheetRect = [[SLActionSheet currentActionSheet] rect], | ||
@"An action sheet should exist."); | ||
SLAssertTrue(CGRectEqualToRect(actionSheetRect, expectedActionSheetRect), | ||
@"The action sheet's frame does not match the expected frame."); | ||
} | ||
|
||
- (void)testCanReadTitle { | ||
NSString *actualTitle, *expectedTitle = @"Action!"; | ||
SLAskApp1(showActionSheetWithInfo:, @{ @"title": expectedTitle }); | ||
|
||
SLAssertNoThrow(actualTitle = [[SLActionSheet currentActionSheet] title], | ||
@"Should have been able to read the action sheet's title."); | ||
SLAssertTrue([actualTitle isEqualToString:expectedTitle], | ||
@"The action sheet's title was not equal to the expected value."); | ||
} | ||
|
||
- (void)testCanMatchButtons { | ||
NSArray *actualButtonTitles, *expectedButtonTitles = @[ @"Other Button", @"Other Other Button" ]; | ||
// Note: the action sheet should not be presented with a cancel button here, | ||
// for contrast with `-testThatButtonsIncludesTheCancelButtonIfPresent`. | ||
SLAskApp1(showActionSheetWithInfo:, (@{ | ||
@"otherButtonTitle1": expectedButtonTitles[0], | ||
@"otherButtonTitle2": expectedButtonTitles[1] | ||
})); | ||
|
||
SLAssertNoThrow(actualButtonTitles = [[[SLActionSheet currentActionSheet] buttons] valueForKey:@"label"], | ||
@"Should have been able to retrieve the titles of the action sheet buttons."); | ||
SLAssertTrue([actualButtonTitles isEqualToArray:expectedButtonTitles], | ||
@"The titles of the action sheet buttons were not read as expected: %@", actualButtonTitles); | ||
} | ||
|
||
- (void)testButtonsIncludesTheCancelButtonIfPresent { | ||
NSArray *actualButtonTitles, *expectedButtonTitles = @[ @"Other Button", @"Other Other Button", @"Cancel" ]; | ||
// `-testCanMatchButtons` verifies that the array will not include an invalid | ||
// cancel button element if the cancel button isn't present. | ||
SLAskApp1(showActionSheetWithInfo:, (@{ | ||
@"otherButtonTitle1": expectedButtonTitles[0], | ||
@"otherButtonTitle2": expectedButtonTitles[1], | ||
@"cancelButtonTitle": expectedButtonTitles[2], | ||
// On the iPad, `UIActionSheet` will not show a cancel button unless it is shown in a popover. | ||
@"showInPopover": @([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPad) | ||
})); | ||
|
||
SLAssertNoThrow(actualButtonTitles = [[[SLActionSheet currentActionSheet] buttons] valueForKey:@"label"], | ||
@"Should have been able to retrieve the titles of the action sheet buttons."); | ||
SLAssertTrue([actualButtonTitles isEqualToArray:expectedButtonTitles], | ||
@"The titles of the action sheet buttons were not read as expected: %@", actualButtonTitles); | ||
} | ||
|
||
- (void)testCanMatchCancelButton { | ||
NSString *actualCancelButtonTitle, *expectedCancelButtonTitle = @"Get Out of Here"; | ||
SLAskApp1(showActionSheetWithInfo:, (@{ | ||
@"cancelButtonTitle": expectedCancelButtonTitle, | ||
// On the iPad, `UIActionSheet` will not show a cancel button unless it is shown in a popover. | ||
@"showInPopover": @([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPad) | ||
})); | ||
[self wait:5.0]; | ||
|
||
SLAssertNoThrow(actualCancelButtonTitle = [[[SLActionSheet currentActionSheet] cancelButton] label], | ||
@"Should have been able to retrieve the title of the action sheet's cancel button."); | ||
SLAssertTrue([actualCancelButtonTitle isEqualToString:expectedCancelButtonTitle], | ||
@"The action sheet's cancel button did not have the expected title."); | ||
} | ||
|
||
- (void)testCancelButtonIsInvalidIfThereIsNoCancelButton { | ||
SLAskApp1(showActionSheetWithInfo:, @{ @"title": @"Action!" }); | ||
|
||
BOOL cancelButtonIsValid = NO; | ||
SLAssertNoThrow(cancelButtonIsValid = [[[SLActionSheet currentActionSheet] cancelButton] isValid], | ||
@"It should have been safe to access the action sheet's cancel button even though the button doesn't exist."); | ||
SLAssertFalse(cancelButtonIsValid, | ||
@"The action sheet's cancel button should be invalid."); | ||
|
||
} | ||
|
||
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
// | ||
// SLActionSheetTestViewController.m | ||
// Subliminal | ||
// | ||
// Created by Jeffrey Wear on 5/26/14. | ||
// Copyright (c) 2014 Inkling. All rights reserved. | ||
// | ||
|
||
#import "SLTestCaseViewController.h" | ||
|
||
#import <Subliminal/SLTestController+AppHooks.h> | ||
|
||
@interface SLActionSheetTestViewController : SLTestCaseViewController | ||
|
||
@end | ||
|
||
@implementation SLActionSheetTestViewController { | ||
UIActionSheet *_actionSheet; | ||
UIPopoverController *_popoverController; | ||
} | ||
|
||
- (void)loadViewForTestCase:(SEL)testCase { | ||
[self loadGenericView]; | ||
} | ||
|
||
- (instancetype)initWithTestCaseWithSelector:(SEL)testCase { | ||
self = [super initWithTestCaseWithSelector:testCase]; | ||
if (self) { | ||
SLTestController *testController = [SLTestController sharedTestController]; | ||
[testController registerTarget:self forAction:@selector(showActionSheetWithInfo:)]; | ||
[testController registerTarget:self forAction:@selector(dismissActionSheet)]; | ||
[testController registerTarget:self forAction:@selector(actionSheetFrameValue)]; | ||
} | ||
return self; | ||
} | ||
|
||
- (void)dealloc { | ||
[[SLTestController sharedTestController] deregisterTarget:self]; | ||
} | ||
|
||
#pragma mark - App hooks | ||
|
||
- (void)showActionSheetWithInfo:(NSDictionary *)info { | ||
NSAssert(!_actionSheet, @"An action sheet is already showing."); | ||
|
||
_actionSheet = [[UIActionSheet alloc] initWithTitle:info[@"title"] | ||
delegate:nil | ||
cancelButtonTitle:info[@"cancelButtonTitle"] | ||
destructiveButtonTitle:nil | ||
otherButtonTitles:info[@"otherButtonTitle1"], info[@"otherButtonTitle2"], nil]; | ||
|
||
if ([info[@"showInPopover"] boolValue]) { | ||
SLActionSheetTestViewController *contentViewController = [[SLActionSheetTestViewController alloc] initWithTestCaseWithSelector:self.testCase]; | ||
_popoverController = [[UIPopoverController alloc] initWithContentViewController:contentViewController]; | ||
_popoverController.popoverContentSize = CGSizeMake(320.0f, 480.0f); | ||
[_popoverController presentPopoverFromRect:CGRectInset((CGRect){ .origin = self.view.center }, -10.0f, -10.0f) | ||
inView:self.view.superview | ||
permittedArrowDirections:UIPopoverArrowDirectionAny animated:NO]; | ||
|
||
// register this here vs. in init so the controller we just presented doesn't steal it | ||
[[SLTestController sharedTestController] registerTarget:self forAction:@selector(dismissPopover)]; | ||
[_actionSheet showInView:_popoverController.contentViewController.view]; | ||
} else { | ||
[_actionSheet showInView:self.view]; | ||
} | ||
} | ||
|
||
- (void)dismissActionSheet { | ||
[_actionSheet dismissWithClickedButtonIndex:0 animated:NO]; | ||
_actionSheet = nil; | ||
} | ||
|
||
- (NSValue *)actionSheetFrameValue { | ||
return [NSValue valueWithCGRect:_actionSheet.accessibilityFrame]; | ||
} | ||
|
||
- (void)dismissPopover { | ||
[_popoverController dismissPopoverAnimated:NO]; | ||
} | ||
|
||
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.