From 7fde0fe8ae690bf1756788a28da203fb14413988 Mon Sep 17 00:00:00 2001 From: Wilco Fiers Date: Fri, 7 Jul 2017 12:00:25 +0200 Subject: [PATCH] fix: Set relatedNodes on color/link-in-block rules (#407) --- lib/checks/color/color-contrast.js | 8 ++++---- lib/checks/color/link-in-text-block.js | 2 ++ test/checks/color/color-contrast.js | 19 +++++++++++++++++++ test/checks/color/link-in-text-block.js | 17 +++++++++++++---- 4 files changed, 38 insertions(+), 8 deletions(-) diff --git a/lib/checks/color/color-contrast.js b/lib/checks/color/color-contrast.js index b59a49103d..349eb8e0b1 100644 --- a/lib/checks/color/color-contrast.js +++ b/lib/checks/color/color-contrast.js @@ -41,14 +41,14 @@ var data = { this.data(data); -if (!cr.isValid || equalRatio) { - this.relatedNodes(bgNodes); -} - //We don't know, so we'll put it into Can't Tell if (fgColor === null || bgColor === null || equalRatio) { missing = null; axe.commons.color.incompleteData.clear(); + this.relatedNodes(bgNodes); return undefined; + +} else if (!cr.isValid) { + this.relatedNodes(bgNodes); } return cr.isValid; diff --git a/lib/checks/color/link-in-text-block.js b/lib/checks/color/link-in-text-block.js index f91a49c485..8bcf7eddae 100644 --- a/lib/checks/color/link-in-text-block.js +++ b/lib/checks/color/link-in-text-block.js @@ -24,6 +24,8 @@ while (parentBlock.nodeType === 1 && !isBlock(parentBlock)) { parentBlock = parentBlock.parentNode; } +this.relatedNodes([ parentBlock ]); + // TODO: Check the :visited state of the link if (color.elementIsDistinct(node, parentBlock)) { return true; diff --git a/test/checks/color/color-contrast.js b/test/checks/color/color-contrast.js index 82b9ab56e2..340dd3c2f6 100644 --- a/test/checks/color/color-contrast.js +++ b/test/checks/color/color-contrast.js @@ -212,4 +212,23 @@ describe('color-contrast', function () { assert.equal(checkContext._data.missingData, 'equalRatio'); assert.equal(checkContext._data.contrastRatio, 1); }); + + it('returns relatedNodes with undefined', function () { + var dataURI = 'data:image/gif;base64,R0lGODlhEAAQAMQAAORHHOVSKudfOulrSOp3WOyDZu6QdvCchPGolfO0o/' + + 'XBs/fNwfjZ0frl3/zy7////wAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAACH5BAkA' + + 'ABAALAAAAAAQABAAAAVVICSOZGlCQAosJ6mu7fiyZeKqNKToQGDsM8hBADgUXoGAiqhSvp5QAnQKGIgUhwFUYLCVDFCrKU' + + 'E1lBavAViFIDlTImbKC5Gm2hB0SlBCBMQiB0UjIQA7'; + + fixture.innerHTML = '
' + + '

Text 1

' + + '
'; + + var target = fixture.querySelector('#target'); + assert.isUndefined(checks['color-contrast'].evaluate.call(checkContext, target)); + + assert.equal( + checkContext._relatedNodes[0], + document.querySelector('#background') + ); + }); }); diff --git a/test/checks/color/link-in-text-block.js b/test/checks/color/link-in-text-block.js index 9c8d5584f3..d37444f631 100644 --- a/test/checks/color/link-in-text-block.js +++ b/test/checks/color/link-in-text-block.js @@ -207,8 +207,17 @@ describe('link-in-text-block', function () { }); - it('looks at the :visited state'); - - it('looks at selectors using :link'); - + it('returns relatedNodes with undefined', function () { + var linkElm = getLinkElm({ }, { + color: '#000010', + backgroundImage: 'url(data:image/gif;base64,R0lGODlhEAAQAMQAAORHHOVSKudfOulrSOp3WOyDZu6QdvCchPGolfO0o/XBs/fNwfjZ0frl3/zy7////wAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAACH5BAkAABAALAAAAAAQABAAAAVVICSOZGlCQAosJ6mu7fiyZeKqNKToQGDsM8hBADgUXoGAiqhSvp5QAnQKGIgUhwFUYLCVDFCrKUE1lBavAViFIDlTImbKC5Gm2hB0SlBCBMQiB0UjIQA7)' + }, { + color: '#000000' + }); + assert.isUndefined(checks['link-in-text-block'].evaluate.call(checkContext, linkElm)); + assert.equal( + checkContext._relatedNodes[0], + linkElm.parentNode + ); + }); }); \ No newline at end of file