Skip to content

Commit 7fde0fe

Browse files
authored
fix: Set relatedNodes on color/link-in-block rules (#407)
1 parent 0039977 commit 7fde0fe

File tree

4 files changed

+38
-8
lines changed

4 files changed

+38
-8
lines changed

lib/checks/color/color-contrast.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,14 +41,14 @@ var data = {
4141

4242
this.data(data);
4343

44-
if (!cr.isValid || equalRatio) {
45-
this.relatedNodes(bgNodes);
46-
}
47-
4844
//We don't know, so we'll put it into Can't Tell
4945
if (fgColor === null || bgColor === null || equalRatio) {
5046
missing = null;
5147
axe.commons.color.incompleteData.clear();
48+
this.relatedNodes(bgNodes);
5249
return undefined;
50+
51+
} else if (!cr.isValid) {
52+
this.relatedNodes(bgNodes);
5353
}
5454
return cr.isValid;

lib/checks/color/link-in-text-block.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ while (parentBlock.nodeType === 1 && !isBlock(parentBlock)) {
2424
parentBlock = parentBlock.parentNode;
2525
}
2626

27+
this.relatedNodes([ parentBlock ]);
28+
2729
// TODO: Check the :visited state of the link
2830
if (color.elementIsDistinct(node, parentBlock)) {
2931
return true;

test/checks/color/color-contrast.js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -212,4 +212,23 @@ describe('color-contrast', function () {
212212
assert.equal(checkContext._data.missingData, 'equalRatio');
213213
assert.equal(checkContext._data.contrastRatio, 1);
214214
});
215+
216+
it('returns relatedNodes with undefined', function () {
217+
var dataURI = 'data:image/gif;base64,R0lGODlhEAAQAMQAAORHHOVSKudfOulrSOp3WOyDZu6QdvCchPGolfO0o/' +
218+
'XBs/fNwfjZ0frl3/zy7////wAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAACH5BAkA' +
219+
'ABAALAAAAAAQABAAAAVVICSOZGlCQAosJ6mu7fiyZeKqNKToQGDsM8hBADgUXoGAiqhSvp5QAnQKGIgUhwFUYLCVDFCrKU' +
220+
'E1lBavAViFIDlTImbKC5Gm2hB0SlBCBMQiB0UjIQA7';
221+
222+
fixture.innerHTML = '<div id="background" style="background:url('+ dataURI +') no-repeat left center; padding: 5px 0 5px 25px;">' +
223+
'<p id="target">Text 1</p>' +
224+
'</div>';
225+
226+
var target = fixture.querySelector('#target');
227+
assert.isUndefined(checks['color-contrast'].evaluate.call(checkContext, target));
228+
229+
assert.equal(
230+
checkContext._relatedNodes[0],
231+
document.querySelector('#background')
232+
);
233+
});
215234
});

test/checks/color/link-in-text-block.js

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -207,8 +207,17 @@ describe('link-in-text-block', function () {
207207

208208
});
209209

210-
it('looks at the :visited state');
211-
212-
it('looks at selectors using :link');
213-
210+
it('returns relatedNodes with undefined', function () {
211+
var linkElm = getLinkElm({ }, {
212+
color: '#000010',
213+
backgroundImage: 'url(data:image/gif;base64,R0lGODlhEAAQAMQAAORHHOVSKudfOulrSOp3WOyDZu6QdvCchPGolfO0o/XBs/fNwfjZ0frl3/zy7////wAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAACH5BAkAABAALAAAAAAQABAAAAVVICSOZGlCQAosJ6mu7fiyZeKqNKToQGDsM8hBADgUXoGAiqhSvp5QAnQKGIgUhwFUYLCVDFCrKUE1lBavAViFIDlTImbKC5Gm2hB0SlBCBMQiB0UjIQA7)'
214+
}, {
215+
color: '#000000'
216+
});
217+
assert.isUndefined(checks['link-in-text-block'].evaluate.call(checkContext, linkElm));
218+
assert.equal(
219+
checkContext._relatedNodes[0],
220+
linkElm.parentNode
221+
);
222+
});
214223
});

0 commit comments

Comments
 (0)