linkedin/LayoutTest-iOS

Investigate why everything returns false for hasAmbiguousLayout

plivesey opened this issue · 2 comments

See UnitTestViews.m

For unit testing, the test has yet to come up with a view which actually has ambiguous layout according to the OS. It always seems to return true.

Maybe looking up some examples from WWDC videos would give some good examples.

Here is some code which I think should produce an ambiguous layout:

NSDictionary *viewsDictionary = @{
                                  @"view1": view1,
                                  @"view2": view2
                                  };
[superview addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"V:|-[view1]-|" options:0 metrics:nil views:viewsDictionary]];
[superview addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"V:|-[view2]-|" options:0 metrics:nil views:viewsDictionary]];
[superview addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"H:|-[view1]-[view2]-|" options:0 metrics:nil views:viewsDictionary]];
[superview addConstraint:[NSLayoutConstraint constraintWithItem:superview
                                                      attribute:NSLayoutAttributeWidth
                                                      relatedBy:NSLayoutRelationEqual
                                                         toItem:nil
                                                      attribute:NSLayoutAttributeNotAnAttribute
                                                     multiplier:1
                                                       constant:100]];
[superview addConstraint:[NSLayoutConstraint constraintWithItem:superview
                                                      attribute:NSLayoutAttributeHeight
                                                      relatedBy:NSLayoutRelationEqual
                                                         toItem:nil
                                                      attribute:NSLayoutAttributeNotAnAttribute
                                                     multiplier:1
                                                       constant:100]];

For others looking at this ticket, I have managed to reproduce ambiguous layout errors in another project. I haven't updated the unit tests in the library yet, but the check is still valid and useful.