diff --git a/Integration Tests/Tests/SLTextFieldTest.m b/Integration Tests/Tests/SLTextFieldTest.m index 7e25148..2e012bd 100644 --- a/Integration Tests/Tests/SLTextFieldTest.m +++ b/Integration Tests/Tests/SLTextFieldTest.m @@ -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) || @@ -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."); @@ -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."); diff --git a/Integration Tests/Tests/SLTextFieldTestViewController.m b/Integration Tests/Tests/SLTextFieldTestViewController.m index 36b1df2..0fb5c4d 100644 --- a/Integration Tests/Tests/SLTextFieldTestViewController.m +++ b/Integration Tests/Tests/SLTextFieldTestViewController.m @@ -25,7 +25,7 @@ #import #import -@interface SLTextFieldTestViewController : SLTestCaseViewController +@interface SLTextFieldTestViewController : SLTestCaseViewController @end @implementation SLTextFieldTestViewController { @@ -33,6 +33,7 @@ @implementation SLTextFieldTestViewController { UISearchBar *_searchBar; UIWebView *_webView; UITableView *_tableView; + UICollectionView *_collectionView; BOOL _webViewDidFinishLoad; } @@ -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) || @@ -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]; } @@ -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"; @@ -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 @@ -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) || @@ -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