Skip to content

Commit

Permalink
Enum to strings
Browse files Browse the repository at this point in the history
  • Loading branch information
FriggaHel committed May 2, 2024
1 parent 07260da commit ed3a4f2
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 55 deletions.
25 changes: 12 additions & 13 deletions visual-java/src/main/java/com/saucelabs/visual/CheckOptions.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package com.saucelabs.visual;

import com.saucelabs.visual.model.DiffingOption;
import com.saucelabs.visual.model.FullPageScreenshotConfig;
import com.saucelabs.visual.model.IgnoreRegion;
import java.util.ArrayList;
Expand All @@ -26,8 +25,8 @@ public CheckOptions(
Boolean captureDom,
String clipSelector,
FullPageScreenshotConfig fullPageScreenshotConfig,
List<DiffingOption> enableOnly,
List<DiffingOption> disableOnly) {
List<String> enableOnly,
List<String> disableOnly) {
this.ignoreElements = ignoreElements;
this.ignoreRegions = ignoreRegions;
this.testName = testName;
Expand All @@ -50,8 +49,8 @@ public CheckOptions(
private String clipSelector;

private FullPageScreenshotConfig fullPageScreenshotConfig;
private List<DiffingOption> enableOnly;
private List<DiffingOption> disableOnly;
private List<String> enableOnly;
private List<String> disableOnly;

public static class Builder {
private List<WebElement> ignoreElements = new ArrayList<>();
Expand All @@ -62,8 +61,8 @@ public static class Builder {
private Boolean captureDom;
private String clipSelector;
private FullPageScreenshotConfig fullPageScreenshotConfig;
private List<DiffingOption> enableOnly;
private List<DiffingOption> disableOnly;
private List<String> enableOnly;
private List<String> disableOnly;

public Builder withIgnoreElements(List<WebElement> ignoreElements) {
this.ignoreElements = ignoreElements;
Expand Down Expand Up @@ -105,12 +104,12 @@ public Builder withFullPageConfig(FullPageScreenshotConfig fullPageScreenshotCon
return this;
}

public Builder enableOnly(List<DiffingOption> enableOnly) {
public Builder enableOnly(List<String> enableOnly) {
this.enableOnly = enableOnly;
return this;
}

public Builder disableOnly(List<DiffingOption> disableOnly) {
public Builder disableOnly(List<String> disableOnly) {
this.disableOnly = disableOnly;
return this;
}
Expand Down Expand Up @@ -198,19 +197,19 @@ public void enableFullPageScreenshots() {
this.fullPageScreenshotConfig = new FullPageScreenshotConfig.Builder().build();
}

public void setEnableOnly(List<DiffingOption> enableOnly) {
public void setEnableOnly(List<String> enableOnly) {
this.enableOnly = enableOnly;
}

public List<DiffingOption> getEnableOnly() {
public List<String> getEnableOnly() {
return enableOnly;
}

public void setDisableOnly(List<DiffingOption> disableOnly) {
public void setDisableOnly(List<String> disableOnly) {
this.disableOnly = disableOnly;
}

public List<DiffingOption> getDisableOnly() {
public List<String> getDisableOnly() {
return disableOnly;
}
}
10 changes: 5 additions & 5 deletions visual-java/src/main/java/com/saucelabs/visual/VisualApi.java
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
package com.saucelabs.visual;

import static com.saucelabs.visual.model.DiffingOption.*;
import static com.saucelabs.visual.utils.EnvironmentVariables.isNotBlank;
import static com.saucelabs.visual.utils.EnvironmentVariables.valueOrDefault;

import com.saucelabs.visual.exception.VisualApiException;
import com.saucelabs.visual.graphql.*;
import com.saucelabs.visual.graphql.type.*;
import com.saucelabs.visual.model.DiffingOption;
import com.saucelabs.visual.model.IgnoreRegion;
import com.saucelabs.visual.utils.ConsoleColors;
import com.saucelabs.visual.utils.EnvironmentVariables;
Expand Down Expand Up @@ -373,7 +373,7 @@ public void sauceVisualCheck(String snapshotName, CheckOptions options) {
}

private DiffingOptionsIn.Builder setDiffingOptionValue(
DiffingOptionsIn.Builder builder, DiffingOption key, boolean value) {
DiffingOptionsIn.Builder builder, String key, boolean value) {
switch (key) {
case Content:
return builder.withContent(value);
Expand All @@ -392,18 +392,18 @@ private DiffingOptionsIn.Builder setDiffingOptionValue(
}

private Optional<DiffingOptionsIn> generateDiffingOptions(
List<DiffingOption> enableOnly, List<DiffingOption> disableOnly) {
List<String> enableOnly, List<String> disableOnly) {
if (enableOnly != null && !enableOnly.isEmpty()) {
DiffingOptionsIn.Builder builder = DiffingOptionsIn.builder();
for (DiffingOption option : DiffingOption.values()) {
for (String option : DiffingOptionValues) {
setDiffingOptionValue(builder, option, enableOnly.contains(option));
}
return Optional.of(builder.build());
}

if (disableOnly != null && !disableOnly.isEmpty()) {
DiffingOptionsIn.Builder builder = DiffingOptionsIn.builder();
for (DiffingOption option : DiffingOption.values()) {
for (String option : DiffingOptionValues) {
setDiffingOptionValue(builder, option, !disableOnly.contains(option));
}
return Optional.of(builder.build());
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,16 @@
package com.saucelabs.visual.model;

public enum DiffingOption {
Content,
Dimensions,
Position,
Structure,
Style,
Visual,
import java.util.Arrays;
import java.util.List;

public class DiffingOption {
public static final String Content = "content";
public static final String Dimensions = "dimensions";
public static final String Position = "position";
public static final String Structure = "structure";
public static final String Style = "style";
public static final String Visual = "visual";

public static final List<String> DiffingOptionValues =
Arrays.asList(Content, Dimensions, Position, Structure, Style, Visual);
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ public class IgnoreRegion {
private int width;
private int x;
private int y;
private List<DiffingOption> enableOnly;
private List<DiffingOption> disableOnly;
private List<String> enableOnly;
private List<String> disableOnly;

public IgnoreRegion(String name, int x, int y, int width, int height) {
this.name = name;
Expand All @@ -24,22 +24,6 @@ public IgnoreRegion(String name, int x, int y, int width, int height) {
this.y = y;
}

public IgnoreRegion(
String name,
int x,
int y,
int width,
int height,
List<DiffingOption> enableOnly,
List<DiffingOption> disableOnly) {
this.name = name;
this.height = height;
this.width = width;
this.x = x;
this.y = y;
this.enableOnly = enableOnly;
}

public IgnoreRegion(int x, int y, int width, int height) {
this.name = "";
this.height = height;
Expand All @@ -48,14 +32,6 @@ public IgnoreRegion(int x, int y, int width, int height) {
this.y = y;
}

public IgnoreRegion(int x, int y, int width, int height, DiffingOption opts) {
this.name = "";
this.height = height;
this.width = width;
this.x = x;
this.y = y;
}

public String getName() {
return name;
}
Expand Down Expand Up @@ -96,19 +72,27 @@ public void setY(int y) {
this.y = y;
}

public void setDisableOnly(List<DiffingOption> disableOnly) {
public void disableOnly(List<String> options) {
disableOnly = options;
}

public void setDisableOnly(List<String> disableOnly) {
this.disableOnly = disableOnly;
}

public List<DiffingOption> getDisableOnly() {
public List<String> getDisableOnly() {
return disableOnly;
}

public void setEnableOnly(List<DiffingOption> enableOnly) {
public void enableOnly(List<String> options) {
enableOnly = options;
}

public void setEnableOnly(List<String> enableOnly) {
this.enableOnly = enableOnly;
}

public List<DiffingOption> getEnableOnly() {
public List<String> getEnableOnly() {
return enableOnly;
}

Expand Down

0 comments on commit ed3a4f2

Please sign in to comment.