landmark-is-unique-after.js 834 B

123456789101112131415161718192021222324252627
  1. function landmarkIsUniqueAfter(results) {
  2. var uniqueLandmarks = [];
  3. // filter out landmark elements that share the same role and accessible text
  4. // so every non-unique landmark isn't reported as a failure (just the first)
  5. return results.filter(currentResult => {
  6. var findMatch = someResult => {
  7. return (
  8. currentResult.data.role === someResult.data.role &&
  9. currentResult.data.accessibleText === someResult.data.accessibleText
  10. );
  11. };
  12. var matchedResult = uniqueLandmarks.find(findMatch);
  13. if (matchedResult) {
  14. matchedResult.result = false;
  15. matchedResult.relatedNodes.push(currentResult.relatedNodes[0]);
  16. return false;
  17. }
  18. uniqueLandmarks.push(currentResult);
  19. currentResult.relatedNodes = [];
  20. return true;
  21. });
  22. }
  23. export default landmarkIsUniqueAfter;