Skip to content

Commit

Permalink
feat(getRules): return actIds when set (#3470)
Browse files Browse the repository at this point in the history
* feat(getRules): return actIds when set

* Update doc/API.md
  • Loading branch information
WilcoFiers committed May 19, 2022
1 parent d84273a commit a3d5cef
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 3 deletions.
1 change: 1 addition & 0 deletions axe.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,7 @@ declare namespace axe {
help: string;
helpUrl: string;
tags: string[];
actIds?: string[];
}
interface SerialDqElement {
source: string;
Expand Down
3 changes: 2 additions & 1 deletion doc/API.md
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,8 @@ In this example, we pass in the WCAG 2 A and AA tags into `axe.getRules` to retr
"wcag412",
"section508",
"section508.22.a"
]
],
actIds: ['c487ae']
},
{
description: "Ensures ARIA attributes are allowed for an element's role",
Expand Down
10 changes: 10 additions & 0 deletions lib/core/base/rule.js
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,12 @@ function Rule(spec, parentAudit) {
*/
this.preload = spec.preload ? true : false;

/**
* IDs of ACT rules the axe-core rule maps to
* @type {Array|undefined}
*/
this.actIds = spec.actIds;

if (spec.matches) {
/**
* Optional function to test if rule should be run against a node, overrides Rule#matches
Expand Down Expand Up @@ -595,6 +601,10 @@ Rule.prototype.configure = function configure(spec) {
this.tags = spec.tags;
}

if (spec.hasOwnProperty('actIds')) {
this.actIds = spec.actIds;
}

if (spec.hasOwnProperty('matches')) {
this.matches = createExecutionContext(spec.matches);
}
Expand Down
3 changes: 2 additions & 1 deletion lib/core/public/get-rules.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ function getRules(tags) {
description: rd.description,
help: rd.help,
helpUrl: rd.helpUrl,
tags: matchingRule.tags
tags: matchingRule.tags,
actIds: matchingRule.actIds
};
});
}
Expand Down
15 changes: 15 additions & 0 deletions test/core/base/rule.js
Original file line number Diff line number Diff line change
Expand Up @@ -1875,6 +1875,7 @@ describe('Rule', function() {
assert.equal(new Rule(spec).matches(), 'blah');
});
});

describe('.tags', function() {
it('should be set', function() {
var spec = {
Expand All @@ -1888,6 +1889,20 @@ describe('Rule', function() {
assert.deepEqual(new Rule(spec).tags, []);
});
});

describe('.actIds', function() {
it('should be set', function() {
var spec = {
actIds: ['abc123', 'xyz789']
};
assert.deepEqual(new Rule(spec).actIds, spec.actIds);
});

it('should default to undefined', function() {
var spec = {};
assert.isUndefined(new Rule(spec).actIds);
});
});
});

describe('configure', function() {
Expand Down
7 changes: 6 additions & 1 deletion test/core/public/get-rules.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ describe('axe.getRules', function() {
{
id: 'awesomeRule2',
any: [],
tags: ['tag1', 'tag2']
tags: ['tag1', 'tag2'],
actIds: ['abc123', 'xyz789']
}
],
data: {
Expand Down Expand Up @@ -63,6 +64,7 @@ describe('axe.getRules', function() {
'/awesomeRule2?application=axeAPI'
);
assert.deepEqual(retValue[1].tags, ['tag1', 'tag2']);
assert.deepEqual(retValue[1].actIds, ['abc123', 'xyz789']);

retValue = axe.getRules(['tag2']);
assert.isArray(retValue);
Expand All @@ -77,6 +79,7 @@ describe('axe.getRules', function() {
'/awesomeRule2?application=axeAPI'
);
assert.deepEqual(retValue[0].tags, ['tag1', 'tag2']);
assert.deepEqual(retValue[0].actIds, ['abc123', 'xyz789']);
});

it('should not return nothing', function() {
Expand Down Expand Up @@ -108,6 +111,7 @@ describe('axe.getRules', function() {
'/awesomeRule2?application=axeAPI'
);
assert.deepEqual(retValue[1].tags, ['tag1', 'tag2']);
assert.deepEqual(retValue[1].actIds, ['abc123', 'xyz789']);
});

it('should return all rules if given empty array', function() {
Expand All @@ -133,5 +137,6 @@ describe('axe.getRules', function() {
'/awesomeRule2?application=axeAPI'
);
assert.deepEqual(retValue[1].tags, ['tag1', 'tag2']);
assert.deepEqual(retValue[1].actIds, ['abc123', 'xyz789']);
});
});

0 comments on commit a3d5cef

Please sign in to comment.