Skip to content

Commit

Permalink
Clean up
Browse files Browse the repository at this point in the history
  • Loading branch information
ebekebe committed May 7, 2024
1 parent 90263f6 commit 445b208
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 59 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ public Builder enable(DiffingFlag flags) {
return this;
}

public Builder withRegion(VisualRegion region) {
public Builder addRegion(VisualRegion region) {
if (this.regions == null) {
this.regions = new ArrayList<>();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,30 +3,20 @@
import com.saucelabs.visual.graphql.type.DiffingOptionsIn;

public enum DiffingFlag {
Content(1 << 0),
Dimensions(1 << 1),
Position(1 << 2),
Structure(1 << 3),
Style(1 << 4),
Visual(1 << 5);

private final long value;

DiffingFlag(long value) {
this.value = value;
}

public long getValue() {
return value;
}
Content,
Dimensions,
Position,
Structure,
Style,
Visual;

public void apply(DiffingOptionsIn options, boolean value) {
if (0 < (this.value & Content.value)) options.setContent(value);
if (0 < (this.value & Dimensions.value)) options.setDimensions(value);
if (0 < (this.value & Position.value)) options.setPosition(value);
if (0 < (this.value & Structure.value)) options.setStructure(value);
if (0 < (this.value & Style.value)) options.setStyle(value);
if (0 < (this.value & Visual.value)) options.setVisual(value);
if (this == Content) options.setContent(value);
if (this == Dimensions) options.setDimensions(value);
if (this == Position) options.setPosition(value);
if (this == Structure) options.setStructure(value);
if (this == Style) options.setStyle(value);
if (this == Visual) options.setVisual(value);
}

public static void setAll(DiffingOptionsIn options, boolean value) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,7 @@

import com.saucelabs.visual.graphql.type.DiffingOptionsIn;
import com.saucelabs.visual.graphql.type.RegionIn;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import org.openqa.selenium.JavascriptExecutor;
import org.openqa.selenium.Rectangle;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;

public class VisualRegion {
Expand Down Expand Up @@ -143,37 +138,6 @@ public VisualRegion except(DiffingFlag flags) {
return this;
}

public static List<IgnoreRegion> forElement(WebDriver driver, List<WebElement> elements) {
JavascriptExecutor js = (JavascriptExecutor) driver;

List<Map<String, Long>> rects =
(List<Map<String, Long>>)
js.executeScript(
"return Array.from(arguments[0]).map(function(element) {"
+ " const rect = element.getBoundingClientRect();"
+ " return {"
+ " top: Math.round(rect.top),"
+ " left: Math.round(rect.left),"
+ " width: Math.round(rect.width),"
+ " height: Math.round(rect.height)"
+ " };"
+ "});",
elements);

List<IgnoreRegion> ignoreRegions = new ArrayList<>(rects.size());
for (Map<String, Long> rect : rects) {
// Convert the rect to an IgnoreRegion
int x = rect.get("left").intValue();
int y = rect.get("top").intValue();
int width = rect.get("width").intValue();
int height = rect.get("height").intValue();

ignoreRegions.add(new IgnoreRegion(x, y, width, height));
}

return ignoreRegions;
}

public RegionIn toRegionIn() {
RegionIn r = new RegionIn();
r.setName(this.name);
Expand Down

0 comments on commit 445b208

Please sign in to comment.