linkedin / LayoutTest-iOS

Write unit tests which test the layout of a view in multiple configurations
https://linkedin.github.io/LayoutTest-iOS/
Apache License 2.0
564 stars 45 forks source link

Investigate why everything returns false for hasAmbiguousLayout #2

Open plivesey opened 8 years ago

plivesey commented 8 years ago

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.

plivesey commented 8 years ago

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]];
plivesey commented 8 years ago

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.