forked from dequelabs/axe-core
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathaggregate-result.js
More file actions
39 lines (34 loc) · 1.22 KB
/
aggregate-result.js
File metadata and controls
39 lines (34 loc) · 1.22 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
import constants from '../constants';
function copyToGroup(resultObject, subResult, group) {
const resultCopy = Object.assign({}, subResult);
resultCopy.nodes = (resultCopy[group] || []).concat();
constants.resultGroups.forEach(resultGroup => {
delete resultCopy[resultGroup];
});
resultObject[group].push(resultCopy);
}
/**
* Calculates the result of a Rule based on its types and the result of its child Checks
* @param {RuleResult} ruleResult The RuleResult to calculate the result of
*/
function aggregateResult(results) {
const resultObject = {};
// Create an array for each type
constants.resultGroups.forEach(groupName => (resultObject[groupName] = []));
// Fill the array with nodes
results.forEach(subResult => {
if (subResult.error) {
copyToGroup(resultObject, subResult, constants.CANTTELL_GROUP);
} else if (subResult.result === constants.NA) {
copyToGroup(resultObject, subResult, constants.NA_GROUP);
} else {
constants.resultGroups.forEach(group => {
if (Array.isArray(subResult[group]) && subResult[group].length > 0) {
copyToGroup(resultObject, subResult, group);
}
});
}
});
return resultObject;
}
export default aggregateResult;