Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support viewForRow in grey_pickerColumnSetToValue matcher #1810

Open
wants to merge 1 commit into
base: earlgrey2
Choose a base branch
from
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
14 changes: 14 additions & 0 deletions AppFramework/Matcher/GREYMatchers.m
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
#include <tgmath.h>

#import "UISwitch+GREYApp.h"
#import "UIView+GREYApp.h"
#import "GREYElementFinder.h"
#import "GREYAllOf+Private.h"
#import "GREYAllOf.h"
Expand Down Expand Up @@ -607,6 +608,7 @@ + (void)initialize {
id<UIPickerViewDelegate> delegate = element.delegate;
SEL attributedTitleSelector = @selector(pickerView:attributedTitleForRow:forComponent:);
SEL nonAttributedTitleSelector = @selector(pickerView:titleForRow:forComponent:);
SEL viewForRowSelector = @selector(pickerView:viewForRow:forComponent:reusingView:);
if ([delegate respondsToSelector:attributedTitleSelector]) {
attributedRowLabel = [delegate pickerView:element
attributedTitleForRow:row
Expand All @@ -616,6 +618,18 @@ + (void)initialize {
}
} else if ([delegate respondsToSelector:nonAttributedTitleSelector]) {
rowLabel = [delegate pickerView:element titleForRow:row forComponent:column];
} else if ([delegate respondsToSelector:viewForRowSelector]) {
UIView *rowView = [delegate pickerView:element
viewForRow:row
forComponent:column
reusingView:nil];
if (![rowView isKindOfClass:[UILabel class]]) {
NSArray<UILabel *> *labels = [rowView grey_childrenAssignableFromClass:[UILabel class]];
UILabel *label = (labels.count > 0 ? labels[0] : nil);
rowLabel = label.text;
} else {
rowLabel = [((UILabel *)rowView) text];
}
}
return rowLabel == value || [rowLabel isEqualToString:value] ||
[attributedRowLabel.string isEqualToString:value];
Expand Down
7 changes: 3 additions & 4 deletions Tests/TestRig/Sources/PickerViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -58,15 +58,14 @@ - (UIView *)pickerView:(UIPickerView *)pickerView
UILabel *columnView =
[[UILabel alloc] initWithFrame:CGRectMake(35, 0, pickerView.frame.size.width / 2,
pickerView.frame.size.height)];
columnView.text = [self pickerView:pickerView titleForRow:row forComponent:component];
columnView.text = [self titleForRow:row forComponent:component];
columnView.textAlignment = NSTextAlignmentCenter;

return columnView;
}

- (NSString *)pickerView:(UIPickerView *)pickerView
titleForRow:(NSInteger)row
forComponent:(NSInteger)component {
- (NSString *)titleForRow:(NSInteger)row
forComponent:(NSInteger)component {
switch (component) {
case 0:
return self.customColumn1Array[(NSUInteger)row];
Expand Down