|
1 | 1 | package net.itarray.automotion.internal; |
2 | 2 |
|
| 3 | +import net.itarray.automotion.internal.geometry.Direction; |
3 | 4 | import net.itarray.automotion.internal.geometry.Rectangle; |
4 | 5 | import net.itarray.automotion.internal.geometry.Scalar; |
5 | 6 | import net.itarray.automotion.internal.properties.Context; |
@@ -437,12 +438,30 @@ public UIValidatorBase hasDifferentSizeAs(List<WebElement> elements) { |
437 | 438 | */ |
438 | 439 | @Override |
439 | 440 | public UIValidatorBase minOffset(int top, int right, int bottom, int left) { |
440 | | - if (toPixelsVertically(top) > MIN_OFFSET && toPixelsHorizontally(right) > MIN_OFFSET && toPixelsVertically(bottom) > MIN_OFFSET && toPixelsHorizontally(left) > MIN_OFFSET) { |
441 | | - validateMinOffset(toPixelsVertically(top), toPixelsHorizontally(right), toPixelsVertically(bottom), toPixelsHorizontally(left)); |
| 441 | + if (isNotSwitchedOff(top, right, bottom, left)) { |
| 442 | + validateMinOffsetNew(top, right, bottom, left); |
442 | 443 | } |
443 | 444 | return this; |
444 | 445 | } |
445 | 446 |
|
| 447 | + public boolean isNotSwitchedOff(int top, int right, int bottom, int left) { |
| 448 | + return isNotSwitchedOff(top, Direction.UP) && |
| 449 | + isNotSwitchedOff(right, Direction.RIGHT) && |
| 450 | + isNotSwitchedOff(bottom, Direction.DOWN) && |
| 451 | + isNotSwitchedOff(left, Direction.LEFT); |
| 452 | + } |
| 453 | + |
| 454 | + public boolean isNotSwitchedOff(int value, Direction direction) { |
| 455 | + return percentOrPixels(value).evaluateIn(getContext(), direction).isGreaterThan(new Scalar(MIN_OFFSET)); |
| 456 | + } |
| 457 | + |
| 458 | + public void validateMinOffsetNew(int top, int right, int bottom, int left) { |
| 459 | + rootElement.validateLeftOffset(greaterOrEqualTo(percentOrPixels(left)), page, getContext(), errors); |
| 460 | + rootElement.validateTopOffset(greaterOrEqualTo(percentOrPixels(top)), page, getContext(), errors); |
| 461 | + rootElement.validateRightOffset(greaterOrEqualTo(percentOrPixels(right)), page, getContext(), errors); |
| 462 | + rootElement.validateBottomOffset(greaterOrEqualTo(percentOrPixels(bottom)), page, getContext(), errors); |
| 463 | + } |
| 464 | + |
446 | 465 | public UIElementValidator hasLeftOffsetToPage(Condition<Scalar> condition) { |
447 | 466 | rootElement.validateLeftOffset(condition, page, getContext(), errors); |
448 | 467 | return this; |
@@ -474,12 +493,19 @@ public UIElementValidator hasBottomOffsetToPage(Condition<Scalar> condition) { |
474 | 493 | */ |
475 | 494 | @Override |
476 | 495 | public UIValidatorBase maxOffset(int top, int right, int bottom, int left) { |
477 | | - if (toPixelsVertically(top) > MIN_OFFSET && toPixelsHorizontally(right) > MIN_OFFSET && toPixelsVertically(bottom) > MIN_OFFSET && toPixelsHorizontally(left) > MIN_OFFSET) { |
478 | | - validateMaxOffset(toPixelsVertically(top), toPixelsHorizontally(right), toPixelsVertically(bottom), toPixelsHorizontally(left)); |
| 496 | + if (isNotSwitchedOff(top, right, bottom, left)) { |
| 497 | + validateMaxOffsetNew(top, right, bottom, left); |
479 | 498 | } |
480 | 499 | return this; |
481 | 500 | } |
482 | 501 |
|
| 502 | + public void validateMaxOffsetNew(int top, int right, int bottom, int left) { |
| 503 | + rootElement.validateLeftOffset(lessOrEqualTo(percentOrPixels(left)), page, getContext(), errors); |
| 504 | + rootElement.validateTopOffset(lessOrEqualTo(percentOrPixels(top)), page, getContext(), errors); |
| 505 | + rootElement.validateRightOffset(lessOrEqualTo(percentOrPixels(right)), page, getContext(), errors); |
| 506 | + rootElement.validateBottomOffset(lessOrEqualTo(percentOrPixels(bottom)), page, getContext(), errors); |
| 507 | + } |
| 508 | + |
483 | 509 | /** |
484 | 510 | * Verify that element has correct CSS values |
485 | 511 | * |
@@ -552,20 +578,6 @@ public UIValidatorBase isInsideOf(WebElement containerElement, String readableCo |
552 | 578 | return this; |
553 | 579 | } |
554 | 580 |
|
555 | | - private void validateMaxOffset(int top, int right, int bottom, int left) { |
556 | | - rootElement.validateLeftOffset(lessOrEqualTo(left), page, getContext(), errors); |
557 | | - rootElement.validateTopOffset(lessOrEqualTo(top), page, getContext(), errors); |
558 | | - rootElement.validateRightOffset(lessOrEqualTo(right), page, getContext(), errors); |
559 | | - rootElement.validateBottomOffset(lessOrEqualTo(bottom), page, getContext(), errors); |
560 | | - } |
561 | | - |
562 | | - private void validateMinOffset(int top, int right, int bottom, int left) { |
563 | | - rootElement.validateLeftOffset(greaterOrEqualTo(left), page, getContext(), errors); |
564 | | - rootElement.validateTopOffset(greaterOrEqualTo(top), page, getContext(), errors); |
565 | | - rootElement.validateRightOffset(greaterOrEqualTo(right), page, getContext(), errors); |
566 | | - rootElement.validateBottomOffset(greaterOrEqualTo(bottom), page, getContext(), errors); |
567 | | - } |
568 | | - |
569 | 581 | private void validateNotSameSize(UIElement element) { |
570 | 582 | rootElement.validateNotSameSize(element, errors); |
571 | 583 | } |
|
0 commit comments