Skip to content

Commit

Permalink
Java baseline bug (#2097)
Browse files Browse the repository at this point in the history
Co-authored-by: Shunguo Yan <[email protected]>
  • Loading branch information
tombrunet and shunguoy committed Dec 3, 2024
1 parent f32af03 commit f131be6
Show file tree
Hide file tree
Showing 6 changed files with 43 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ module.exports = {
// optional - Specify the rule archive
// Default: latest
// Run `npx aat archives` for a list of valid ruleArchive ids and policy ids
ruleArchive: 'latest',
ruleArchive: 'versioned',

// optional - Specify one or many policies to scan.
// Run `npx aat archives` for a list of valid ruleArchive ids and policy ids
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ dependencies {
testImplementation libs.junit

implementation 'com.microsoft.playwright:playwright:1.46.0'
implementation 'com.ibm.able:accessibility-checker:1.0.0-beta-4'
implementation 'com.ibm.able:accessibility-checker:3.1.77'
}

// Apply a specific Java toolchain to ease working on different environments.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ dependencies {

// https://mvnrepository.com/artifact/org.seleniumhq.selenium/selenium-java
implementation 'org.seleniumhq.selenium:selenium-java:4.23.0'
implementation 'com.ibm.able:accessibility-checker:1.0.0-beta-4'
implementation 'com.ibm.able:accessibility-checker:3.1.77'
}

// Apply a specific Java toolchain to ease working on different environments.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -163,8 +163,8 @@ public static ACReport getBaseline(String label) {
* }
* ]
*/
public static DiffResult[] diffResultsWithExpected(ACReport actual, ACReport expected) {
return BaselineManager.diffResultsWithExpected(actual, expected);
public static DiffResult[] diffResultsWithExpected(ACReport actual, ACReport expected, boolean clean) {
return BaselineManager.diffResultsWithExpected(actual, expected, clean);
}

// export function addRuleset(ruleset) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

package com.ibm.able.equalaccess.engine;
import java.lang.reflect.Type;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.HashSet;
Expand Down Expand Up @@ -118,6 +119,17 @@ public Object clone() {
return super.clone();
}

public Result copyClean() {
Result issue = new Result();
issue.ruleId = this.ruleId;
issue.reasonId = this.reasonId;
// Make sure that the xpath in the case there is a [1] we replace it with ""
// to support some browser which return it differently
issue.path = new HashMap<String, String>();
issue.path.put("dom", this.path.get("dom").replaceAll("\\[1\\]", ""));
return issue;
}

public String toHelpData() {
return gsonMinimal.toJson(this);
}
Expand Down Expand Up @@ -301,6 +313,20 @@ public Object clone() {
return ret;
}

public ACReport copyClean() {
// Shallow copy
ACReport ret = new ACReport();
ret.label = this.label;
ArrayList<Result> temp = new ArrayList<Result>(results.length);
for (int idx=0; idx<results.length; ++idx) {
if (!("pass".equals(results[idx].level.toString()))) {
temp.add(results[idx].copyClean());
}
}
ret.results = temp.toArray(new Result[temp.size()]);
return ret;
}

public String toString() {
if (results == null) {
return "ERROR: results null";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ public static eAssertResult assertCompliance(ACReport actualResults) {
// check to make sure there are no violations that are listed in the fails on.
if (expected != null) {
// Run the diff algo to get the list of differences
DiffResult[] differences = BaselineManager.diffResultsWithExpected(actualResults, expected);
DiffResult[] differences = BaselineManager.diffResultsWithExpected(actualResults, expected, false);

// console.log("difference=" + JSON.stringify(differences, null, ' '));

Expand All @@ -145,7 +145,7 @@ public static eAssertResult assertCompliance(ACReport actualResults) {
modActual.sortResults();
ACReport modExpected = (ACReport) expected.clone();
modExpected.sortResults();
DiffResult[] differences2 = BaselineManager.diffResultsWithExpected(modActual, modExpected);
DiffResult[] differences2 = BaselineManager.diffResultsWithExpected(modActual, modExpected, false);
if (differences2 == null || differences2.length == 0) {
return eAssertResult.PASS;
} else {
Expand Down Expand Up @@ -203,7 +203,16 @@ public static eAssertResult assertCompliance(ACReport actualResults) {
* }
* ]
*/
public static DiffResult[] diffResultsWithExpected(ACReport actual, ACReport expected) {
public static DiffResult[] diffResultsWithExpected(ACReport actual, ACReport expected, boolean clean) {
// In the case clean is set to true then run the cleanComplianceObjectBeforeCompare function on
// both the actual and expected objects passed in. This is to make sure that the objcet follow a
// simalar structure before compareing the objects.
if (clean) {
// Clean actual and expected objects
actual = actual.copyClean();
expected = expected.copyClean();
}

// Run Deep diff function to compare the actual and expected values.
DiffResult[] differences = diff(actual, expected);
if (differences != null && differences.length > 0) {
Expand Down

0 comments on commit f131be6

Please sign in to comment.