Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix defect in calling code when building the ElementRoleMap #555

Merged
merged 2 commits into from
Jul 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion __tests__/src/elementRoleMap-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ describe('elementRolesMap', function () {
});
describe('spread operator', function () {
it('should have a specific length', function () {
expect([...elementRoleMap].length).toEqual(113);
expect([...elementRoleMap].length).toEqual(112);
});
test.each([...elementRoleMap])('Testing element: %o', (obj, roles) => {
expect(entriesList).toEqual(
Expand Down
15 changes: 8 additions & 7 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

54 changes: 53 additions & 1 deletion src/elementRoleMap.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,27 @@ for (let i = 0; i < keys.length; i++) {
if (relation.module === 'HTML') {
const concept = relation.concept;
if (concept) {
elementRoles.push([concept, [key]]);
const elementRoleRelation: ?ElementARIARoleRelationTuple = elementRoles.find(relation => ariaRoleRelationConceptEquals(relation[0], concept));
let roles: RoleSet;

if (elementRoleRelation) {
roles = elementRoleRelation[1];
} else {
roles = [];
}
let isUnique = true;
for (let i = 0; i < roles.length; i++) {
if (roles[i] === key) {
isUnique = false;
break;
}
}
if (isUnique) {
roles.push(key);
}
if (!elementRoleRelation) {
elementRoles.push([concept, roles]);
}
}
}
}
Expand Down Expand Up @@ -63,6 +83,38 @@ const elementRoleMap: TAriaQueryMap<
},
};

function ariaRoleRelationConceptEquals(a: ARIARoleRelationConcept, b: ARIARoleRelationConcept): boolean {
return (
a.name === b.name &&
ariaRoleRelationConstraintsEquals(a.constraints, b.constraints) &&
ariaRoleRelationConceptAttributeEquals(a.attributes, b.attributes)
)
}

function ariaRoleRelationConstraintsEquals(a?: ARIARoleRelationConcept['constraints'], b?: ARIARoleRelationConcept['constraints']): boolean {
if (a === undefined && b !== undefined) {
return false;
}

if (a !== undefined && b === undefined) {
return false;
}

if (a !== undefined && b !== undefined) {
if (a.length !== b.length) {
return false;
}

for (let i = 0; i < a.length; i++) {
if (a[i] !== b[i]) {
return false;
}
}
}

return true;
}

function ariaRoleRelationConceptAttributeEquals(
a?: Array<ARIARoleRelationConceptAttribute>,
b?: Array<ARIARoleRelationConceptAttribute>,
Expand Down
Loading