From 833f40f1902d6f16d5604523a95e97d0fdd73ed4 Mon Sep 17 00:00:00 2001 From: Jordan Zucker Date: Mon, 4 Aug 2014 17:11:31 -0700 Subject: [PATCH 1/2] Added an integration test for UITextField in UICollectionViewCell Found some issues we had with UICollectionViewCells and a child UITextField. Created an integration test for regression checking. --- Integration Tests/Tests/SLTextFieldTest.m | 8 +++++ .../Tests/SLTextFieldTestViewController.m | 35 +++++++++++++++++-- 2 files changed, 41 insertions(+), 2 deletions(-) diff --git a/Integration Tests/Tests/SLTextFieldTest.m b/Integration Tests/Tests/SLTextFieldTest.m index 7e25148..39a5d2b 100644 --- a/Integration Tests/Tests/SLTextFieldTest.m +++ b/Integration Tests/Tests/SLTextFieldTest.m @@ -41,6 +41,7 @@ - (void)setUpTestCaseWithSelector:(SEL)testSelector { if (testSelector == @selector(testSetText) || testSelector == @selector(testSetTextWithinTableViewCell) || + testSelector == @selector(testSetTextWithinCollectionViewCell) || testSelector == @selector(testSetTextCanHandleTapHoldCharacters) || testSelector == @selector(testSetTextClearsCurrentText) || testSelector == @selector(testSetTextClearsCurrentTextWithinTableViewCell) || @@ -76,6 +77,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."); diff --git a/Integration Tests/Tests/SLTextFieldTestViewController.m b/Integration Tests/Tests/SLTextFieldTestViewController.m index 36b1df2..9154c56 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,6 +43,7 @@ - (void)loadViewForTestCase:(SEL)testCase { if (testCase == @selector(testSetText) || testCase == @selector(testSetTextWithinTableViewCell) || + testCase == @selector(testSetTextWithinCollectionViewCell) || testCase == @selector(testSetTextCanHandleTapHoldCharacters) || testCase == @selector(testSetTextClearsCurrentText) || testCase == @selector(testSetTextClearsCurrentTextWithinTableViewCell) || @@ -59,6 +61,11 @@ - (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)) { + _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,6 +117,7 @@ - (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(testSetTextWhenFieldClearsOnBeginEditing) && @@ -140,7 +148,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,6 +169,7 @@ - (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) || @@ -206,4 +215,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 From 6bf80db3919850ac2433ba79a56d7baf37bdc7f3 Mon Sep 17 00:00:00 2001 From: Jordan Zucker Date: Mon, 4 Aug 2014 19:03:00 -0700 Subject: [PATCH 2/2] Added a test to check clears text for thoroughness --- Integration Tests/Tests/SLTextFieldTest.m | 11 +++++++++++ .../Tests/SLTextFieldTestViewController.m | 6 +++++- 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/Integration Tests/Tests/SLTextFieldTest.m b/Integration Tests/Tests/SLTextFieldTest.m index 39a5d2b..2e012bd 100644 --- a/Integration Tests/Tests/SLTextFieldTest.m +++ b/Integration Tests/Tests/SLTextFieldTest.m @@ -45,6 +45,7 @@ - (void)setUpTestCaseWithSelector:(SEL)testSelector { testSelector == @selector(testSetTextCanHandleTapHoldCharacters) || testSelector == @selector(testSetTextClearsCurrentText) || testSelector == @selector(testSetTextClearsCurrentTextWithinTableViewCell) || + testSelector == @selector(testSetTextClearsCurrentTextWithinCollectionViewCell) || testSelector == @selector(testSetTextWhenFieldClearsOnBeginEditing) || testSelector == @selector(testGetText) || testSelector == @selector(testDoNotMatchEditorAccessibilityObjects) || @@ -110,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 9154c56..0fb5c4d 100644 --- a/Integration Tests/Tests/SLTextFieldTestViewController.m +++ b/Integration Tests/Tests/SLTextFieldTestViewController.m @@ -47,6 +47,7 @@ - (void)loadViewForTestCase:(SEL)testCase { testCase == @selector(testSetTextCanHandleTapHoldCharacters) || testCase == @selector(testSetTextClearsCurrentText) || testCase == @selector(testSetTextClearsCurrentTextWithinTableViewCell) || + testCase == @selector(testSetTextClearsCurrentTextWithinCollectionViewCell) || testCase == @selector(testSetTextWhenFieldClearsOnBeginEditing) || testCase == @selector(testGetText) || testCase == @selector(testDoNotMatchEditorAccessibilityObjects) || @@ -61,7 +62,8 @@ - (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)) { + } 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; @@ -120,6 +122,7 @@ - (void)viewDidLoad { 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"; @@ -173,6 +176,7 @@ - (NSString *)text { 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) ||