Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(audit): add lang query paramenter to help urls #1794

Merged
merged 3 commits into from
Sep 5, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 10 additions & 3 deletions lib/core/base/audit.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ function Audit(audit) {
this.brand = 'axe';
this.application = 'axeAPI';
this.tagExclude = ['experimental'];
this.lang = 'en';

this.defaultConfig = audit;
this._init();
Expand All @@ -60,7 +61,8 @@ Audit.prototype._setDefaultLocale = function() {

const locale = {
checks: {},
rules: {}
rules: {},
lang: this.lang
};

// XXX: unable to use `for-of` here, as doing so would
Expand Down Expand Up @@ -223,6 +225,10 @@ Audit.prototype.applyLocale = function(locale) {
if (locale.rules) {
this._applyRuleLocale(locale.rules);
}

if (locale.lang) {
this.lang = locale.lang;
}
};

/**
Expand Down Expand Up @@ -642,7 +648,7 @@ Audit.prototype.setBranding = function(branding) {
/**
* For all the rules, create the helpUrl and add it to the data for that rule
*/
function getHelpUrl({ brand, application }, ruleId, version) {
function getHelpUrl({ brand, application, lang }, ruleId, version) {
return (
axe.constants.helpUrlBase +
brand +
Expand All @@ -651,7 +657,8 @@ function getHelpUrl({ brand, application }, ruleId, version) {
'/' +
ruleId +
'?application=' +
application
encodeURIComponent(application) +
(lang && lang !== 'en' ? '&lang=' + encodeURIComponent(lang) : '')
);
}

Expand Down
28 changes: 28 additions & 0 deletions test/core/base/audit.js
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,24 @@ describe('Audit', function() {
'https://dequeuniversity.com/rules/axe/1.0/target?application=axeAPI'
);
});
it('sets the lang query if locale has been set', function() {
straker marked this conversation as resolved.
Show resolved Hide resolved
var audit = new Audit();
audit.addRule({
id: 'target',
matches: 'function () {return "hello";}',
selector: 'bob'
});
audit.applyLocale({
lang: 'de'
});
assert.lengthOf(audit.rules, 1);
assert.equal(audit.data.rules.target, undefined);
audit._constructHelpUrls();
assert.deepEqual(audit.data.rules.target, {
helpUrl:
'https://dequeuniversity.com/rules/axe/x.y/target?application=axeAPI&lang=de'
});
});
});

describe('Audit#setBranding', function() {
Expand Down Expand Up @@ -368,6 +386,16 @@ describe('Audit', function() {
audit.resetRulesAndChecks();
assert.equal(audit.checks.target, undefined);
});
it('should reset locale', function() {
var audit = new Audit();
assert.equal(audit.lang, 'en');
audit.applyLocale({
lang: 'de'
});
assert.equal(audit.lang, 'de');
audit.resetRulesAndChecks();
assert.equal(audit.lang, 'en');
});
});

describe('Audit#addCheck', function() {
Expand Down
16 changes: 16 additions & 0 deletions test/core/public/configure.js
Original file line number Diff line number Diff line change
Expand Up @@ -343,6 +343,22 @@ describe('axe.configure', function() {
});
});

it('sets the lang property', function() {
axe.configure({
locale: {
lang: 'lol',
rules: { greeting: { description: 'hello' } },
checks: {
banana: {
fail: 'icecream'
}
}
}
});

assert.equal(axe._audit.lang, 'lol');
});

describe('only given checks', function() {
it('should not error', function() {
assert.doesNotThrow(function() {
Expand Down