Skip to content

Commit aed587a

Browse files
committed
got rid of toPixels in min/maxOffset
1 parent ab9b1f8 commit aed587a

File tree

1 file changed

+30
-18
lines changed

1 file changed

+30
-18
lines changed

src/main/java/net/itarray/automotion/internal/UIValidatorBase.java

Lines changed: 30 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package net.itarray.automotion.internal;
22

3+
import net.itarray.automotion.internal.geometry.Direction;
34
import net.itarray.automotion.internal.geometry.Rectangle;
45
import net.itarray.automotion.internal.geometry.Scalar;
56
import net.itarray.automotion.internal.properties.Context;
@@ -437,12 +438,30 @@ public UIValidatorBase hasDifferentSizeAs(List<WebElement> elements) {
437438
*/
438439
@Override
439440
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);
442443
}
443444
return this;
444445
}
445446

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+
446465
public UIElementValidator hasLeftOffsetToPage(Condition<Scalar> condition) {
447466
rootElement.validateLeftOffset(condition, page, getContext(), errors);
448467
return this;
@@ -474,12 +493,19 @@ public UIElementValidator hasBottomOffsetToPage(Condition<Scalar> condition) {
474493
*/
475494
@Override
476495
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);
479498
}
480499
return this;
481500
}
482501

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+
483509
/**
484510
* Verify that element has correct CSS values
485511
*
@@ -552,20 +578,6 @@ public UIValidatorBase isInsideOf(WebElement containerElement, String readableCo
552578
return this;
553579
}
554580

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-
569581
private void validateNotSameSize(UIElement element) {
570582
rootElement.validateNotSameSize(element, errors);
571583
}

0 commit comments

Comments
 (0)