Skip to content

Commit

Permalink
fix(deprecatedrole,color-contrast): fix message to properly include d…
Browse files Browse the repository at this point in the history
…eprecated role, improve color-contrast pass messages (#3387)

* fix(deprecatedrole): fix message to properly include deprecated role

* add tests

* ie11
  • Loading branch information
straker authored Feb 28, 2022
1 parent 3c0f10f commit c8b4b27
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 2 deletions.
2 changes: 1 addition & 1 deletion lib/checks/aria/deprecatedrole.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"impact": "minor",
"messages": {
"pass": "ARIA role is not deprecated",
"fail": "The role used is deprecated: ${data.values}"
"fail": "The role used is deprecated: ${data}"
}
}
}
2 changes: 2 additions & 0 deletions lib/checks/color/color-contrast-evaluate.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ export default function colorContrastEvaluate(node, options, virtualNode) {
} = options;

if (!isVisible(node, false)) {
this.data({ messageKey: 'hidden' });
return true;
}

Expand Down Expand Up @@ -97,6 +98,7 @@ export default function colorContrastEvaluate(node, options, virtualNode) {
(typeof minThreshold === 'number' && contrast < minThreshold) ||
(typeof maxThreshold === 'number' && contrast > maxThreshold)
) {
this.data({ contrastRatio: contrast });
return true;
}

Expand Down
5 changes: 4 additions & 1 deletion lib/checks/color/color-contrast.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,10 @@
"metadata": {
"impact": "serious",
"messages": {
"pass": "Element has sufficient color contrast of ${data.contrastRatio}",
"pass": {
"default": "Element has sufficient color contrast of ${data.contrastRatio}",
"hidden": "Element is hidden"
},
"fail": {
"default": "Element has insufficient color contrast of ${data.contrastRatio} (foreground color: ${data.fgColor}, background color: ${data.bgColor}, font size: ${data.fontSize}, font weight: ${data.fontWeight}). Expected contrast ratio of ${data.expectedContrastRatio}",
"fgOnShadowColor": "Element has insufficient color contrast of ${data.contrastRatio} between the foreground and shadow color (foreground color: ${data.fgColor}, text-shadow color: ${data.shadowColor}, font size: ${data.fontSize}, font weight: ${data.fontWeight}). Expected contrast ratio of ${data.expectedContrastRatio}",
Expand Down
25 changes: 25 additions & 0 deletions test/testutils.js
Original file line number Diff line number Diff line change
Expand Up @@ -483,6 +483,31 @@ testUtils.getCheckEvaluate = function getCheckEvaluate(checkId, testOptions) {
result +
noneCheckMessage
);

var message = axe.utils.processMessage(
messages[key][messageKey],
this._data
);
assert.isTrue(
message.indexOf('${') === -1,
'Data object missing properties for ' +
key +
' message key "' +
messageKey +
'": "' +
message +
'"'
);
} else {
var message = axe.utils.processMessage(messages[key], this._data);
assert.isTrue(
message.indexOf('${') === -1,
'Data object missing properties for ' +
key +
' message: "' +
message +
'"'
);
}
}

Expand Down

0 comments on commit c8b4b27

Please sign in to comment.