-
Notifications
You must be signed in to change notification settings - Fork 791
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(page-has-heading-one): Added new best-practice rule
- Loading branch information
1 parent
9a9c283
commit cb8f261
Showing
17 changed files
with
349 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
if (!options || !options.selector || typeof options.selector !== 'string') { | ||
throw new TypeError('visible-in-page requires options.selector to be a string'); | ||
throw new TypeError('visible-in-page requires options.selector to be a string'); | ||
} | ||
|
||
const matchingElms = axe.utils.querySelectorAll(virtualNode, | ||
options.selector); | ||
return matchingElms && matchingElms.length > 0; | ||
const matchingElms = axe.utils.querySelectorAll(virtualNode, options.selector); | ||
this.relatedNodes(matchingElms.map(vNode => vNode.actualNode)); | ||
return matchingElms.length > 0; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
{ | ||
"id": "page-has-heading-one", | ||
"evaluate": "page-has-elm.js", | ||
"after": "page-has-elm-after.js", | ||
"options": { | ||
"selector": "h1:not([role]), [role=\"heading\"][aria-level=\"1\"]" | ||
}, | ||
"metadata": { | ||
"impact": "moderate", | ||
"messages": { | ||
"pass": "Page has at least one level-one heading", | ||
"fail": "Page must have a level-one heading" | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
{ | ||
"id": "page-has-heading-one", | ||
"selector": "html", | ||
"tags": [ | ||
"best-practice" | ||
], | ||
"metadata": { | ||
"description": "Ensure that the page, or at least one of its frames contains a level-one heading", | ||
"help": "Page must contain a level-one heading" | ||
}, | ||
"all": [ | ||
"page-has-heading-one" | ||
], | ||
"any": [], | ||
"none": [] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
10 changes: 10 additions & 0 deletions
10
test/integration/full/page-has-heading-one/frames/level1-fail.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
<!doctype html> | ||
<html lang="en" id="violation2"> | ||
<head> | ||
<meta charset="utf8"> | ||
<script src="/axe.js"></script> | ||
</head> | ||
<body> | ||
<p>No h1 here either</p> | ||
</body> | ||
</html> |
12 changes: 12 additions & 0 deletions
12
test/integration/full/page-has-heading-one/frames/level1.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
<!doctype html> | ||
<html lang="en" id="pass2"> | ||
<head> | ||
<meta charset="utf8"> | ||
<script src="/axe.js"></script> | ||
</head> | ||
<body> | ||
<p>No h1 here either</p> | ||
<iframe id="frame2" src="level2-a.html"></iframe> | ||
<iframe id="frame3" src="level2.html"></iframe> | ||
</body> | ||
</html> |
10 changes: 10 additions & 0 deletions
10
test/integration/full/page-has-heading-one/frames/level2-a.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
<!doctype html> | ||
<html lang="en" id="pass3"> | ||
<head> | ||
<meta charset="utf8"> | ||
<script src="/axe.js"></script> | ||
</head> | ||
<body> | ||
<h1>This page has an h1</h1> | ||
</body> | ||
</html> |
10 changes: 10 additions & 0 deletions
10
test/integration/full/page-has-heading-one/frames/level2.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
<!doctype html> | ||
<html lang="en" id="pass4"> | ||
<head> | ||
<meta charset="utf8"> | ||
<script src="/axe.js"></script> | ||
</head> | ||
<body> | ||
<p>No h1 content in this iframe</p> | ||
</body> | ||
</html> |
24 changes: 24 additions & 0 deletions
24
test/integration/full/page-has-heading-one/page-has-heading-one-fail.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
<!doctype html> | ||
<html lang="en" id="fail1"> | ||
<head> | ||
<meta charset="utf8"> | ||
<link rel="stylesheet" type="text/css" href="/node_modules/mocha/mocha.css" /> | ||
<script src="/node_modules/mocha/mocha.js"></script> | ||
<script src="/node_modules/chai/chai.js"></script> | ||
<script src="/axe.js"></script> | ||
<script> | ||
mocha.setup({ | ||
timeout: 10000, | ||
ui: 'bdd' | ||
}); | ||
var assert = chai.assert; | ||
</script> | ||
</head> | ||
<body> | ||
<p>No h1 here</p> | ||
<iframe id="frame1" src="frames/level1-fail.html"></iframe> | ||
<div id="mocha"></div> | ||
<script src="page-has-heading-one-fail.js"></script> | ||
<script src="/test/integration/adapter.js"></script> | ||
</body> | ||
</html> |
49 changes: 49 additions & 0 deletions
49
test/integration/full/page-has-heading-one/page-has-heading-one-fail.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
describe('page-has-heading-one test failure', function () { | ||
'use strict'; | ||
var results; | ||
before(function (done) { | ||
function start() { | ||
// Stop messing with my tests Mocha! | ||
document.querySelector('#mocha h1').outerHTML = '<h2>page-has-heading-one test</h2>' | ||
|
||
axe.run({ runOnly: { type: 'rule', values: ['page-has-heading-one'] }}, function (err, r) { | ||
assert.isNull(err); | ||
results = r; | ||
done(); | ||
}); | ||
} | ||
if (document.readyState !== 'complete') { | ||
window.addEventListener('load', start); | ||
} else { | ||
start(); | ||
} | ||
}); | ||
|
||
describe('violations', function () { | ||
it('should find 1', function () { | ||
assert.lengthOf(results.violations[0].nodes, 2); | ||
}); | ||
|
||
it('should find #frame1', function () { | ||
assert.deepEqual(results.violations[0].nodes[0].target, ['#fail1']); | ||
}); | ||
|
||
it('should find #frame1, #violation2', function () { | ||
assert.deepEqual(results.violations[0].nodes[1].target, ['#frame1', '#violation2']); | ||
}); | ||
}); | ||
|
||
describe('passes', function () { | ||
it('should find 0', function () { | ||
assert.lengthOf(results.passes, 0); | ||
}); | ||
}); | ||
|
||
it('should find 0 inapplicable', function () { | ||
assert.lengthOf(results.inapplicable, 0); | ||
}); | ||
|
||
it('should find 0 incomplete', function () { | ||
assert.lengthOf(results.incomplete, 0); | ||
}); | ||
}); |
24 changes: 24 additions & 0 deletions
24
test/integration/full/page-has-heading-one/page-has-heading-one-pass1.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
<!doctype html> | ||
<html lang="en" id="pass1"> | ||
<head> | ||
<meta charset="utf8"> | ||
<link rel="stylesheet" type="text/css" href="/node_modules/mocha/mocha.css" /> | ||
<script src="/node_modules/mocha/mocha.js"></script> | ||
<script src="/node_modules/chai/chai.js"></script> | ||
<script src="/axe.js"></script> | ||
<script> | ||
mocha.setup({ | ||
timeout: 10000, | ||
ui: 'bdd' | ||
}); | ||
var assert = chai.assert; | ||
</script> | ||
</head> | ||
<body> | ||
<p>No h1 content</p> | ||
<iframe id="frame1" src="frames/level1.html"></iframe> | ||
<div id="mocha"></div> | ||
<script src="page-has-heading-one-pass1.js"></script> | ||
<script src="/test/integration/adapter.js"></script> | ||
</body> | ||
</html> |
59 changes: 59 additions & 0 deletions
59
test/integration/full/page-has-heading-one/page-has-heading-one-pass1.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
describe('page-has-heading-one test pass', function () { | ||
'use strict'; | ||
var results; | ||
before(function (done) { | ||
function start() { | ||
// Stop messing with my tests Mocha! | ||
document.querySelector('#mocha h1').outerHTML = '<h2>page-has-heading-one test</h2>' | ||
|
||
axe.run({ runOnly: { type: 'rule', values: ['page-has-heading-one'] } }, function (err, r) { | ||
assert.isNull(err); | ||
results = r; | ||
console.log(r); | ||
done(); | ||
}); | ||
} | ||
if (document.readyState !== 'complete') { | ||
window.addEventListener('load', start); | ||
} else { | ||
start(); | ||
} | ||
}); | ||
|
||
describe('violations', function () { | ||
it('should find 0', function () { | ||
assert.lengthOf(results.violations, 0); | ||
}); | ||
}); | ||
|
||
describe('passes', function () { | ||
it('should find 4', function () { | ||
assert.lengthOf(results.passes[0].nodes, 4); | ||
}); | ||
|
||
it('should find #pass1', function () { | ||
assert.deepEqual(results.passes[0].nodes[0].target, ['#pass1']); | ||
}); | ||
|
||
it('should find #frame1, #pass2', function () { | ||
assert.deepEqual(results.passes[0].nodes[1].target, ['#frame1', '#pass2']); | ||
}); | ||
|
||
it('should find #frame1, #frame2, #pass3', function () { | ||
assert.deepEqual(results.passes[0].nodes[2].target, ['#frame1', '#frame2', '#pass3']); | ||
}); | ||
|
||
it('should find #frame1, #frame3, #pass4', function () { | ||
assert.deepEqual(results.passes[0].nodes[3].target, ['#frame1', '#frame3', '#pass4']); | ||
}); | ||
}); | ||
|
||
it('should find 0 inapplicable', function () { | ||
assert.lengthOf(results.inapplicable, 0); | ||
}); | ||
|
||
it('should find 0 incomplete', function () { | ||
assert.lengthOf(results.incomplete, 0); | ||
}); | ||
|
||
}); |
23 changes: 23 additions & 0 deletions
23
test/integration/full/page-has-heading-one/page-has-heading-one-pass2.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
<!doctype html> | ||
<html lang="en" id="pass1"> | ||
<head> | ||
<meta charset="utf8"> | ||
<link rel="stylesheet" type="text/css" href="/node_modules/mocha/mocha.css" /> | ||
<script src="/node_modules/mocha/mocha.js"></script> | ||
<script src="/node_modules/chai/chai.js"></script> | ||
<script src="/axe.js"></script> | ||
<script> | ||
mocha.setup({ | ||
timeout: 10000, | ||
ui: 'bdd' | ||
}); | ||
var assert = chai.assert; | ||
</script> | ||
</head> | ||
<body> | ||
<div role="heading" aria-level="1">Level one heading!</div> | ||
<div id="mocha"></div> | ||
<script src="page-has-heading-one-pass2.js"></script> | ||
<script src="/test/integration/adapter.js"></script> | ||
</body> | ||
</html> |
Oops, something went wrong.