Skip to content

Commit

Permalink
fix: Set relatedNodes on color/link-in-block rules (#407)
Browse files Browse the repository at this point in the history
  • Loading branch information
WilcoFiers authored Jul 7, 2017
1 parent 0039977 commit 7fde0fe
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 8 deletions.
8 changes: 4 additions & 4 deletions lib/checks/color/color-contrast.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
2 changes: 2 additions & 0 deletions lib/checks/color/link-in-text-block.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
19 changes: 19 additions & 0 deletions test/checks/color/color-contrast.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = '<div id="background" style="background:url('+ dataURI +') no-repeat left center; padding: 5px 0 5px 25px;">' +
'<p id="target">Text 1</p>' +
'</div>';

var target = fixture.querySelector('#target');
assert.isUndefined(checks['color-contrast'].evaluate.call(checkContext, target));

assert.equal(
checkContext._relatedNodes[0],
document.querySelector('#background')
);
});
});
17 changes: 13 additions & 4 deletions test/checks/color/link-in-text-block.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
);
});
});

0 comments on commit 7fde0fe

Please sign in to comment.