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

Display accessibilityLabel for view description if no mas_key #534

Open
wants to merge 1 commit into
base: master
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
3 changes: 3 additions & 0 deletions Masonry/NSLayoutConstraint+MASDebugAdditions.m
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,9 @@ + (NSString *)descriptionForObject:(id)obj {
if ([obj respondsToSelector:@selector(mas_key)] && [obj mas_key]) {
return [NSString stringWithFormat:@"%@:%@", [obj class], [obj mas_key]];
}
if ([obj respondsToSelector:@selector(accessibilityLabel)] && [obj accessibilityLabel]) {
return [NSString stringWithFormat:@"%@:%@", [obj class], [obj accessibilityLabel]];
}
return [NSString stringWithFormat:@"%@:%p", [obj class], obj];
}

Expand Down
21 changes: 14 additions & 7 deletions Tests/Specs/NSLayoutConstraint+MASDebugAdditionsSpec.m
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,22 @@
SpecBegin(NSLayoutConstraint_MASDebugAdditions)

- (void)testDisplayViewKey {
MAS_VIEW *newView = MAS_VIEW.new;
newView.mas_key = @"newView";
MAS_VIEW *newView1 = MAS_VIEW.new;
newView1.mas_key = @"newView1";
MAS_VIEW *newView2 = MAS_VIEW.new;
newView2.accessibilityLabel = @"newView2";

MASLayoutConstraint *layoutConstraint = [MASLayoutConstraint constraintWithItem:newView attribute:NSLayoutAttributeWidth relatedBy:NSLayoutRelationGreaterThanOrEqual toItem:nil attribute:NSLayoutAttributeNotAnAttribute multiplier:1 constant:300];
MASLayoutConstraint *layoutConstraint1 = [MASLayoutConstraint constraintWithItem:newView1 attribute:NSLayoutAttributeWidth relatedBy:NSLayoutRelationGreaterThanOrEqual toItem:nil attribute:NSLayoutAttributeNotAnAttribute multiplier:1 constant:300];
MASLayoutConstraint *layoutConstraint2 = [MASLayoutConstraint constraintWithItem:newView2 attribute:NSLayoutAttributeWidth relatedBy:NSLayoutRelationGreaterThanOrEqual toItem:nil attribute:NSLayoutAttributeNotAnAttribute multiplier:1 constant:300];

layoutConstraint.priority = MASLayoutPriorityDefaultLow;
layoutConstraint1.priority = MASLayoutPriorityDefaultLow;
layoutConstraint2.priority = MASLayoutPriorityDefaultLow;

NSString *description = [NSString stringWithFormat:@"<MASLayoutConstraint:%p %@:newView.width >= 300 ^low>", layoutConstraint, MAS_VIEW.class];
expect([layoutConstraint description]).to.equal(description);
NSString *description1 = [NSString stringWithFormat:@"<MASLayoutConstraint:%p %@:newView1.width >= 300 ^low>", layoutConstraint1, MAS_VIEW.class];
expect([layoutConstraint1 description]).to.equal(description1);

NSString *description2 = [NSString stringWithFormat:@"<MASLayoutConstraint:%p %@:newView2.width >= 300 ^low>", layoutConstraint2, MAS_VIEW.class];
expect([layoutConstraint2 description]).to.equal(description2);
}

- (void)testDisplayLayoutConstraintKey {
Expand Down Expand Up @@ -57,4 +64,4 @@ - (void)testDisplayConstraintKey {
expect([superview.constraints[0] description]).to.equal(description);
}

SpecEnd
SpecEnd