diff --git a/lib/checks/navigation/p-as-heading.js b/lib/checks/navigation/p-as-heading.js index cd02854f40..9f08de59f1 100644 --- a/lib/checks/navigation/p-as-heading.js +++ b/lib/checks/navigation/p-as-heading.js @@ -5,10 +5,10 @@ options = options || {}; let margins = options.margins || []; let nextSibling = siblings.slice(currentIndex+1) -.find(elm => elm.nodeName.toUpperCase() === 'P') +.find(elm => elm.nodeName.toUpperCase() === 'P'); let prevSibling = siblings.slice(0, currentIndex).reverse() -.find(elm => elm.nodeName.toUpperCase() === 'P') +.find(elm => elm.nodeName.toUpperCase() === 'P'); function getTextContainer(elm) { let nextNode = elm; @@ -52,7 +52,7 @@ function getStyleValues(node) { }; } -function isHeaderStyle(styleA, styleB, margin) { +function isHeaderStyle(styleA, styleB, margins) { return margins.reduce((out, margin) => { return (out || ( (!margin.size || styleA.fontSize / margin.size > styleB.fontSize) && diff --git a/lib/core/base/audit.js b/lib/core/base/audit.js index 1609f281b1..f70b492a38 100644 --- a/lib/core/base/audit.js +++ b/lib/core/base/audit.js @@ -260,6 +260,10 @@ Audit.prototype.validateOptions = function (options) { Audit.prototype.setBranding = function (branding) { 'use strict'; + let previous = { + brand: this.brand, + application: this.application + }; if (branding && branding.hasOwnProperty('brand') && branding.brand && typeof branding.brand === 'string') { this.brand = branding.brand; @@ -268,23 +272,31 @@ Audit.prototype.setBranding = function (branding) { branding.application && typeof branding.application === 'string') { this.application = branding.application; } - this._constructHelpUrls(); + this._constructHelpUrls(previous); }; /** * For all the rules, create the helpUrl and add it to the data for that rule */ +function getHelpUrl ({brand, application}, ruleId, version) { + return axe.constants.helpUrlBase + brand + + '/' + ( version || axe.version.substring(0, axe.version.lastIndexOf('.'))) + + '/' + ruleId + '?application=' + application; +} -Audit.prototype._constructHelpUrls = function () { +Audit.prototype._constructHelpUrls = function (previous = null) { var version = axe.version.substring(0, axe.version.lastIndexOf('.')); - this.rules.forEach(rule => { - this.data.rules[rule.id] = this.data.rules[rule.id] || {}; - this.data.rules[rule.id].helpUrl = 'https://dequeuniversity.com/rules/' + - this.brand + '/' + - version + '/' + - rule.id + '?' + - 'application=' + this.application; + if (!this.data.rules[rule.id]) { + this.data.rules[rule.id] = {}; + } + let metaData = this.data.rules[rule.id]; + if ( + typeof metaData.helpUrl !== 'string' || + (previous && metaData.helpUrl === getHelpUrl(previous, rule.id, version)) + ) { + metaData.helpUrl = getHelpUrl(this, rule.id, version); + } }); }; diff --git a/lib/core/constants.js b/lib/core/constants.js index c9bd00e187..a9e7684b4c 100644 --- a/lib/core/constants.js +++ b/lib/core/constants.js @@ -23,6 +23,7 @@ var definitions = [{ }]; var constants = { + helpUrlBase: 'https://dequeuniversity.com/rules/', results: [], resultGroups: [], resultGroupMap: {}, diff --git a/lib/rules/window-is-top.js b/lib/rules/window-is-top.js index 97713059fa..51173d79aa 100644 --- a/lib/rules/window-is-top.js +++ b/lib/rules/window-is-top.js @@ -1,2 +1 @@ -/* global window */ return node.ownerDocument.defaultView.self === node.ownerDocument.defaultView.top; \ No newline at end of file diff --git a/test/checks/navigation/p-as-heading.js b/test/checks/navigation/p-as-heading.js index 1cd983e1dc..daf7c39da5 100644 --- a/test/checks/navigation/p-as-heading.js +++ b/test/checks/navigation/p-as-heading.js @@ -144,21 +144,25 @@ describe('p-as-heading', function () { it('returns false if any of the margins is passed', function () { var options = { - margins: [{ size: 1.2, weight: 100 }], - margins: [{ size: 1.5 }], - margins: [{ italic: true }] + margins: [ + { size: 1.2, weight: 100 }, + { size: 1.5 }, + { italic: true } + ], }; fixture.innerHTML = '

elm 1

elm 2

'; var node = fixture.querySelector('p'); assert.isFalse(checks['p-as-heading'].evaluate.call(checkContext, node, options)); - }) + }); it('returns true if none of the set margins is passed', function () { var options = { - margins: [{ size: 1.2, weight: 100 }], - margins: [{ size: 1.5 }], - margins: [{ size: 1.2, italic: true }] + margins: [ + { size: 1.2, weight: 100 }, + { size: 1.5 }, + { size: 1.2, italic: true } + ] }; fixture.innerHTML = '

elm 1

elm 2

'; diff --git a/test/core/base/audit.js b/test/core/base/audit.js index a7b4b69141..af6a18c948 100644 --- a/test/core/base/audit.js +++ b/test/core/base/audit.js @@ -113,6 +113,42 @@ describe('Audit', function () { helpUrl: 'https://dequeuniversity.com/rules/axe/x.y/target?application=thing' }); }); + + it('does not override helpUrls of different products', function () { + var audit = new Audit(); + audit.addRule({ + id: 'target1', + matches: 'function () {return "hello";}', + selector: 'bob', + metadata: { + helpUrl: 'https://dequeuniversity.com/rules/myproject/x.y/target1?application=axeAPI' + } + }); + audit.addRule({ + id: 'target2', + matches: 'function () {return "hello";}', + selector: 'bob' + }); + + assert.equal( + audit.data.rules.target1.helpUrl, + 'https://dequeuniversity.com/rules/myproject/x.y/target1?application=axeAPI' + ); + assert.isUndefined(audit.data.rules.target2); + + assert.lengthOf(audit.rules, 2); + audit.brand = 'thing'; + audit._constructHelpUrls(); + + assert.equal( + audit.data.rules.target1.helpUrl, + 'https://dequeuniversity.com/rules/myproject/x.y/target1?application=axeAPI' + ); + assert.equal( + audit.data.rules.target2.helpUrl, + 'https://dequeuniversity.com/rules/thing/x.y/target2?application=axeAPI' + ); + }); }); describe('Audit#setBranding', function () { @@ -166,6 +202,26 @@ describe('Audit', function () { helpUrl: 'https://dequeuniversity.com/rules/axe/x.y/target?application=axeAPI' }); }); + it('should not replace custom set branding', function () { + var audit = new Audit(); + audit.addRule({ + id: 'target', + matches: 'function () {return "hello";}', + selector: 'bob', + metadata: { + helpUrl: 'https://dequeuniversity.com/rules/customer-x/x.y/target?application=axeAPI' + } + }); + audit.setBranding({ + application: 'thing', + brand: 'other' + }); + assert.equal( + audit.data.rules.target.helpUrl, + 'https://dequeuniversity.com/rules/customer-x/x.y/target?application=axeAPI' + ); + + }); }); diff --git a/test/rule-matches/p-as-heading-matches.js b/test/rule-matches/p-as-heading-matches.js index ab924cbb74..88aad46722 100644 --- a/test/rule-matches/p-as-heading-matches.js +++ b/test/rule-matches/p-as-heading-matches.js @@ -2,7 +2,7 @@ describe('p-as-heading-matches', function () { 'use strict'; var rule; - var fixture = document.getElementById('fixture') + var fixture = document.getElementById('fixture'); beforeEach(function () { rule = axe._audit.rules.find(function (rule) { @@ -60,7 +60,7 @@ describe('p-as-heading-matches', function () { assert.isTrue(rule.matches(target)); fixture.innerHTML = '

some text

'; - var target = fixture.querySelector('#target'); + target = fixture.querySelector('#target'); assert.isFalse(rule.matches(target)); });