Skip to content

Commit

Permalink
feat(avoid-inline-spacing): add option for which css properties to lo…
Browse files Browse the repository at this point in the history
…ok at (#2244)

* feat(avoid-inline-spacing): add option for which css properties to look at

* Update test/checks/shared/avoid-inline-spacing.js

Co-authored-by: Wilco Fiers <WilcoFiers@users.noreply.github.com>

Co-authored-by: Wilco Fiers <WilcoFiers@users.noreply.github.com>
  • Loading branch information
straker and WilcoFiers authored May 26, 2020
1 parent b544554 commit 93c027a
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 21 deletions.
10 changes: 2 additions & 8 deletions lib/checks/shared/avoid-inline-spacing-evaluate.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,5 @@
function avoidInlineSpacingEvaluate(node) {
const inlineSpacingCssProperties = [
'line-height',
'letter-spacing',
'word-spacing'
];

const overriddenProperties = inlineSpacingCssProperties.filter(property => {
function avoidInlineSpacingEvaluate(node, options) {
const overriddenProperties = options.cssProperties.filter(property => {
if (node.style.getPropertyPriority(property) === `important`) {
return property;
}
Expand Down
3 changes: 3 additions & 0 deletions lib/checks/shared/avoid-inline-spacing.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
{
"id": "avoid-inline-spacing",
"evaluate": "avoid-inline-spacing-evaluate",
"options": {
"cssProperties": ["line-height", "letter-spacing", "word-spacing"]
},
"metadata": {
"impact": "serious",
"messages": {
Expand Down
37 changes: 24 additions & 13 deletions test/checks/shared/avoid-inline-spacing.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ describe('avoid-inline-spacing tests', function() {

var fixture = document.getElementById('fixture');
var queryFixture = axe.testUtils.queryFixture;
var check = checks['avoid-inline-spacing'];
var checkEvaluate = axe.testUtils.getCheckEvaluate('avoid-inline-spacing');
var checkContext = axe.testUtils.MockCheckContext();

afterEach(function() {
Expand All @@ -15,7 +15,7 @@ describe('avoid-inline-spacing tests', function() {
var vNode = queryFixture(
'<p id="target" style="font-size: 200%;">The quick brown fox jumped over the lazy dog</p>'
);
var actual = check.evaluate.call(checkContext, vNode.actualNode);
var actual = checkEvaluate.call(checkContext, vNode.actualNode);
assert.isTrue(actual);
assert.isNull(checkContext._data);
});
Expand All @@ -24,7 +24,7 @@ describe('avoid-inline-spacing tests', function() {
var vNode = queryFixture(
'<p id="target" style="line-height: 5invalid;">The quick brown fox jumped over the lazy dog</p>'
);
var actual = check.evaluate.call(checkContext, vNode.actualNode);
var actual = checkEvaluate.call(checkContext, vNode.actualNode);
assert.isTrue(actual);
assert.isNull(checkContext._data);
});
Expand All @@ -33,7 +33,7 @@ describe('avoid-inline-spacing tests', function() {
var vNode = queryFixture(
'<p id="target" style="line-height: invalid !important;">The quick brown fox jumped over the lazy dog</p>'
);
var actual = check.evaluate.call(checkContext, vNode.actualNode);
var actual = checkEvaluate.call(checkContext, vNode.actualNode);
assert.isTrue(actual);
assert.isNull(checkContext._data);
});
Expand All @@ -42,7 +42,7 @@ describe('avoid-inline-spacing tests', function() {
var vNode = queryFixture(
'<p id="target" style="line-height: 1.5;">The quick brown fox jumped over the lazy dog</p>'
);
var actual = check.evaluate.call(checkContext, vNode.actualNode);
var actual = checkEvaluate.call(checkContext, vNode.actualNode);
assert.isTrue(actual);
assert.isNull(checkContext._data);
});
Expand All @@ -51,7 +51,7 @@ describe('avoid-inline-spacing tests', function() {
var vNode = queryFixture(
'<p id="target" style="letter-spacing: 50px;">The quick brown fox jumped over the lazy dog</p>'
);
var actual = check.evaluate.call(checkContext, vNode.actualNode);
var actual = checkEvaluate.call(checkContext, vNode.actualNode);
assert.isTrue(actual);
assert.isNull(checkContext._data);
});
Expand All @@ -60,7 +60,7 @@ describe('avoid-inline-spacing tests', function() {
var vNode = queryFixture(
'<p id="target" style="word-spacing: 10px;">The quick brown fox jumped over the lazy dog</p>'
);
var actual = check.evaluate.call(checkContext, vNode.actualNode);
var actual = checkEvaluate.call(checkContext, vNode.actualNode);
assert.isTrue(actual);
assert.isNull(checkContext._data);
});
Expand All @@ -69,7 +69,7 @@ describe('avoid-inline-spacing tests', function() {
var vNode = queryFixture(
'<p id="target" style="word-spacing: 20ch; letter-spacing: 50rem; line-height: 3;">The quick brown fox jumped over the lazy dog</p>'
);
var actual = check.evaluate.call(checkContext, vNode.actualNode);
var actual = checkEvaluate.call(checkContext, vNode.actualNode);
assert.isTrue(actual);
assert.isNull(checkContext._data);
});
Expand All @@ -78,7 +78,7 @@ describe('avoid-inline-spacing tests', function() {
var vNode = queryFixture(
'<p id="target" style="line-height: 1.5 !important;">The quick brown fox jumped over the lazy dog</p>'
);
var actual = check.evaluate.call(checkContext, vNode.actualNode);
var actual = checkEvaluate.call(checkContext, vNode.actualNode);
assert.isFalse(actual);
assert.deepEqual(checkContext._data, ['line-height']);
});
Expand All @@ -87,7 +87,7 @@ describe('avoid-inline-spacing tests', function() {
var vNode = queryFixture(
'<p id="target" style="letter-spacing: 100em !important;">The quick brown fox jumped over the lazy dog</p>'
);
var actual = check.evaluate.call(checkContext, vNode.actualNode);
var actual = checkEvaluate.call(checkContext, vNode.actualNode);
assert.isFalse(actual);
assert.deepEqual(checkContext._data, ['letter-spacing']);
});
Expand All @@ -96,7 +96,7 @@ describe('avoid-inline-spacing tests', function() {
var vNode = queryFixture(
'<p id="target" style="word-spacing: -.4ch !important;">The quick brown fox jumped over the lazy dog</p>'
);
var actual = check.evaluate.call(checkContext, vNode.actualNode);
var actual = checkEvaluate.call(checkContext, vNode.actualNode);
assert.isFalse(actual);
assert.deepEqual(checkContext._data, ['word-spacing']);
});
Expand All @@ -105,7 +105,7 @@ describe('avoid-inline-spacing tests', function() {
var vNode = queryFixture(
'<p id="target" style="word-spacing: 200%; letter-spacing: 50rem !important; line-height: 3;">The quick brown fox jumped over the lazy dog</p>'
);
var actual = check.evaluate.call(checkContext, vNode.actualNode);
var actual = checkEvaluate.call(checkContext, vNode.actualNode);
assert.isFalse(actual);
assert.deepEqual(checkContext._data, ['letter-spacing']);
});
Expand All @@ -114,8 +114,19 @@ describe('avoid-inline-spacing tests', function() {
var vNode = queryFixture(
'<p id="target" style="line-height: 3 !important; letter-spacing: 50rem !important;">The quick brown fox jumped over the lazy dog</p>'
);
var actual = check.evaluate.call(checkContext, vNode.actualNode);
var actual = checkEvaluate.call(checkContext, vNode.actualNode);
assert.isFalse(actual);
assert.deepEqual(checkContext._data, ['line-height', 'letter-spacing']);
});

it('supports options.cssProperties', function() {
var vNode = queryFixture(
'<p id="target" style="font-size: 14px !important; line-height: 3 !important; letter-spacing: 50rem !important">The quick brown fox jumped over the lazy dog</p>'
);
var actual = checkEvaluate.call(checkContext, vNode.actualNode, {
cssProperties: ['font-size']
});
assert.isFalse(actual);
assert.deepEqual(checkContext._data, ['font-size']);
});
});

0 comments on commit 93c027a

Please sign in to comment.