Skip to content

Commit

Permalink
fix(color-contrast): incl. elements w/ line breaks
Browse files Browse the repository at this point in the history
Closes #607
Closes #556
  • Loading branch information
Marcy Sutton committed Nov 8, 2017
1 parent 15065f7 commit 806db4b
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
3 changes: 3 additions & 0 deletions lib/commons/color/get-background-color.js
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,9 @@ function elmPartiallyObscured(elm, bgElm, bgColor) {
* @param {Element} elm
*/
function includeMissingElements(elmStack, elm) {
if (!elmStack.includes(elm)) {
elmStack.unshift(elm);
}
const elementMap = {'TD': ['TR', 'TBODY'], 'TH': ['TR', 'THEAD'], 'INPUT': ['LABEL']};
const tagArray = elmStack.map((elm) => {
return elm.tagName;
Expand Down
15 changes: 15 additions & 0 deletions test/checks/color/color-contrast.js
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,21 @@ describe('color-contrast', function () {
assert.deepEqual(checkContext._relatedNodes, []);
});

it('should return true for inline elements with sufficient contrast spanning multiple lines', function () {
fixture.innerHTML = '<p>Text oh heyyyy <a href="#" id="target">and here\'s <br>a link</a></p>';
var target = fixture.querySelector('#target');
assert.isTrue(checks['color-contrast'].evaluate.call(checkContext, target));
assert.deepEqual(checkContext._relatedNodes, []);
});

it('should return true for inline elements with sufficient contrast', function () {
fixture.innerHTML = '<p>Text oh heyyyy <b id="target">and here\'s bold text</b></p>';
var target = fixture.querySelector('#target');
var result = checks['color-contrast'].evaluate.call(checkContext, target);
assert.isTrue(result);
assert.deepEqual(checkContext._relatedNodes, []);
});

it('should return false when there is not sufficient contrast', function () {
fixture.innerHTML = '<div style="color: yellow; background-color: white;" id="target">' +
'My text</div>';
Expand Down

0 comments on commit 806db4b

Please sign in to comment.