Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions Integration Tests/Tests/SLTextFieldTest.m
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,11 @@ - (void)setUpTestCaseWithSelector:(SEL)testSelector {

if (testSelector == @selector(testSetText) ||
testSelector == @selector(testSetTextWithinTableViewCell) ||
testSelector == @selector(testSetTextWithinCollectionViewCell) ||
testSelector == @selector(testSetTextCanHandleTapHoldCharacters) ||
testSelector == @selector(testSetTextClearsCurrentText) ||
testSelector == @selector(testSetTextClearsCurrentTextWithinTableViewCell) ||
testSelector == @selector(testSetTextClearsCurrentTextWithinCollectionViewCell) ||
testSelector == @selector(testSetTextWhenFieldClearsOnBeginEditing) ||
testSelector == @selector(testGetText) ||
testSelector == @selector(testDoNotMatchEditorAccessibilityObjects) ||
Expand Down Expand Up @@ -76,6 +78,13 @@ - (void)testSetTextWithinTableViewCell {
SLAssertTrue([SLAskApp(text) isEqualToString:expectedText], @"Text was not set to expected value.");
}

- (void)testSetTextWithinCollectionViewCell {
NSString *const expectedText = @"foo";
[self wait:5];
SLAssertNoThrow([UIAElement(_textField) setText:expectedText], @"Should not have thrown.");
SLAssertTrue([SLAskApp(text) isEqualToString:expectedText], @"Text was not set to expected value.");
}

- (void)testSetTextCanHandleTapHoldCharacters {
NSString *const expectedText = @"foo’s a difficult string to type!";
SLAssertNoThrow([UIAElement(_textField) setText:expectedText], @"Should not have thrown.");
Expand All @@ -102,6 +111,16 @@ - (void)testSetTextClearsCurrentTextWithinTableViewCell {
SLAssertTrue([SLAskApp(text) isEqualToString:expectedText2], @"Text was not set to expected value.");
}

- (void)testSetTextClearsCurrentTextWithinCollectionViewCell {
NSString *const expectedText1 = @"foo";
SLAssertNoThrow([UIAElement(_textField) setText:expectedText1], @"Should not have thrown.");
SLAssertTrue([SLAskApp(text) isEqualToString:expectedText1], @"Text was not set to expected value.");

NSString *const expectedText2 = @"bar";
SLAssertNoThrow([UIAElement(_textField) setText:expectedText2], @"Should not have thrown.");
SLAssertTrue([SLAskApp(text) isEqualToString:expectedText2], @"Text was not set to expected value.");
}

- (void)testSetTextWhenFieldClearsOnBeginEditing {
NSString *const expectedText = @"foo";
SLAssertNoThrow([UIAElement(_textField) setText:expectedText], @"Should not have thrown.");
Expand Down
39 changes: 37 additions & 2 deletions Integration Tests/Tests/SLTextFieldTestViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,15 @@
#import <Subliminal/SLTestController+AppHooks.h>
#import <QuartzCore/QuartzCore.h>

@interface SLTextFieldTestViewController : SLTestCaseViewController <UIWebViewDelegate,UITableViewDataSource>
@interface SLTextFieldTestViewController : SLTestCaseViewController <UIWebViewDelegate,UITableViewDataSource,UICollectionViewDataSource>
@end

@implementation SLTextFieldTestViewController {
UITextField *_textField;
UISearchBar *_searchBar;
UIWebView *_webView;
UITableView *_tableView;
UICollectionView *_collectionView;
BOOL _webViewDidFinishLoad;
}

Expand All @@ -42,9 +43,11 @@ - (void)loadViewForTestCase:(SEL)testCase {

if (testCase == @selector(testSetText) ||
testCase == @selector(testSetTextWithinTableViewCell) ||
testCase == @selector(testSetTextWithinCollectionViewCell) ||
testCase == @selector(testSetTextCanHandleTapHoldCharacters) ||
testCase == @selector(testSetTextClearsCurrentText) ||
testCase == @selector(testSetTextClearsCurrentTextWithinTableViewCell) ||
testCase == @selector(testSetTextClearsCurrentTextWithinCollectionViewCell) ||
testCase == @selector(testSetTextWhenFieldClearsOnBeginEditing) ||
testCase == @selector(testGetText) ||
testCase == @selector(testDoNotMatchEditorAccessibilityObjects) ||
Expand All @@ -59,6 +62,12 @@ - (void)loadViewForTestCase:(SEL)testCase {
_tableView = [[UITableView alloc] initWithFrame:(CGRect){CGPointZero, CGSizeMake(320.0f, 44.0f)}];
_tableView.dataSource = self;
[view addSubview:_tableView];
} else if (testCase == @selector(testSetTextWithinCollectionViewCell) ||
testCase == @selector(testSetTextClearsCurrentTextWithinCollectionViewCell)) {
_collectionView = [[UICollectionView alloc] initWithFrame:(CGRect){CGPointZero, CGSizeMake(320.0f, 44.0f)} collectionViewLayout:[[UICollectionViewFlowLayout alloc] init]];
[_collectionView registerClass:[UICollectionViewCell class] forCellWithReuseIdentifier:@"TestCell"];
_collectionView.dataSource = self;
[view addSubview:_collectionView];
} else {
[view addSubview:_textField];
}
Expand Down Expand Up @@ -110,8 +119,10 @@ - (void)viewDidLoad {

if (self.testCase != @selector(testSetText) &&
self.testCase != @selector(testSetTextWithinTableViewCell) &&
self.testCase != @selector(testSetTextWithinCollectionViewCell) &&
self.testCase != @selector(testSetTextClearsCurrentText) &&
self.testCase != @selector(testSetTextClearsCurrentTextWithinTableViewCell) &&
self.testCase != @selector(testSetTextClearsCurrentTextWithinCollectionViewCell) &&
self.testCase != @selector(testSetTextWhenFieldClearsOnBeginEditing) &&
self.testCase != @selector(testDoNotMatchEditorAccessibilityObjects)) {
_textField.text = @"foo";
Expand Down Expand Up @@ -140,7 +151,7 @@ - (void)webViewDidFinishLoad:(UIWebView *)webView {
- (void)viewWillLayoutSubviews {
[super viewWillLayoutSubviews];

if (_tableView != nil)
if ((_tableView != nil) || (_collectionView != nil))
return;

// move the textfield above the keyboard
Expand All @@ -161,9 +172,11 @@ - (NSString *)text {
NSString *text;
if (self.testCase == @selector(testSetText) ||
self.testCase == @selector(testSetTextWithinTableViewCell) ||
self.testCase == @selector(testSetTextWithinCollectionViewCell) ||
self.testCase == @selector(testSetTextCanHandleTapHoldCharacters) ||
self.testCase == @selector(testSetTextClearsCurrentText) ||
self.testCase == @selector(testSetTextClearsCurrentTextWithinTableViewCell) ||
self.testCase == @selector(testSetTextClearsCurrentTextWithinCollectionViewCell) ||
self.testCase == @selector(testSetTextWhenFieldClearsOnBeginEditing) ||
self.testCase == @selector(testGetText) ||
self.testCase == @selector(testDoNotMatchEditorAccessibilityObjects) ||
Expand Down Expand Up @@ -206,4 +219,26 @@ - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(N
return tableViewCell;
}

#pragma mark - UICollectionViewDataSource

- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
{
return 1;
}

- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
UICollectionViewCell *collectionViewCell = [collectionView dequeueReusableCellWithReuseIdentifier:@"TestCell" forIndexPath:indexPath];
collectionViewCell.frame = CGRectMake(0, 0, 320.0f, 44.0f);
collectionViewCell.contentView.backgroundColor = [UIColor lightGrayColor];

_textField.frame = (CGRect){CGPointZero, CGSizeMake(100.0f, 30.0f)};
_textField.textColor = [UIColor blackColor];
[_textField becomeFirstResponder];

[collectionViewCell.contentView addSubview:_textField];

return collectionViewCell;
}

@end