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

Add rule, landmark-main-is-top-level #462

Merged
merged 24 commits into from
Nov 14, 2017
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
edeb860
init
sulsanaul Jul 19, 2017
3d37aab
feat: add new rule, landmark-no-more-than-one-main
sulsanaul Jul 19, 2017
4e1b18b
test(landmark-at-least-one-main): updated integration tests for check
sulsanaul Jul 19, 2017
2840b02
feat(landmark-main-is-top-level): add rule ensuring each main landmar…
sulsanaul Jul 26, 2017
fa6069d
Merge https://github.com/dequelabs/axe-core into main/is-top-level
sulsanaul Jul 26, 2017
6eb553b
refactor(landmark-main-is-top-level): change help messages
sulsanaul Aug 16, 2017
094e251
feat(landmark-main-is-top-level): change a function used in check and…
sulsanaul Aug 18, 2017
2c55cbb
refactor(main-is-top-level): change pass/fail messages
sulsanaul Aug 23, 2017
b9b1bf5
refactor(landmark-main-is-top-level): change description/help messages
sulsanaul Aug 23, 2017
bf85e0d
Merge https://github.com/dequelabs/axe-core into main/is-top-level
sulsanaul Aug 23, 2017
747990d
Merge branch 'main/is-top-level' of https://github.com/ssanaul/axe-co…
sulsanaul Aug 23, 2017
9c0e75c
feat(main-is-top-level): update check for shadow dom features
sulsanaul Aug 23, 2017
824ee2d
fix(main-is-top-level): update check to ignore form as a landmark
sulsanaul Aug 28, 2017
05ee0a7
fix: edit incorrect usage of getComposedParent
sulsanaul Sep 5, 2017
73ed9cf
test: add unit test to check if main landmark in shadow dom is top level
sulsanaul Sep 5, 2017
f82c667
style: remove spaces in attributes
sulsanaul Sep 21, 2017
34407e9
fix: update test so that checkSetup passes in correct argument
sulsanaul Sep 21, 2017
3e5c6ad
test: add test to ensure correct number of violations nodes
sulsanaul Sep 21, 2017
ff463ef
Merge branch 'main/is-top-level' of https://github.com/ssanaul/axe-co…
sulsanaul Sep 21, 2017
03e5434
fix: revert 'application' type to landmark
sulsanaul Sep 21, 2017
56ad598
Merge https://github.com/dequelabs/axe-core into main/is-top-level
sulsanaul Sep 21, 2017
00b10c1
Merge https://github.com/dequelabs/axe-core into main/is-top-level
sulsanaul Sep 26, 2017
f936751
style: remove spaces in attributes
sulsanaul Oct 18, 2017
12b1903
fix: allow main landmark to be in form
sulsanaul Oct 19, 2017
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
Next Next commit
init
  • Loading branch information
sulsanaul committed Jul 19, 2017
commit edeb860cbed8bd6b638a747f16c794f6c77f2815
1 change: 1 addition & 0 deletions doc/rule-descriptions.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
| input-image-alt | Ensures <input type="image"> elements have alternate text | cat.text-alternatives, wcag2a, wcag111, section508, section508.22.a | true |
| label-title-only | Ensures that every form element is not solely labeled using the title or aria-describedby attributes | cat.forms, best-practice | false |
| label | Ensures every form element has a label | cat.forms, wcag2a, wcag332, wcag131, section508, section508.22.n | true |
| landmark-no-more-than-one-main | Each document in a page must have no more than one main landmark, used to identify the main content. | cat.best-practice | true |
| layout-table | Ensures presentational <table> elements do not use <th>, <caption> elements or the summary attribute | cat.semantics, wcag2a, wcag131 | true |
| link-in-text-block | Links can be distinguished without relying on color | cat.color, experimental, wcag2a, wcag141 | true |
| link-name | Ensures links have discernible text | cat.name-role-value, wcag2a, wcag111, wcag412, wcag244, section508, section508.22.a | true |
Expand Down
2 changes: 2 additions & 0 deletions lib/checks/keyboard/has-no-more-than-one-main.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
var mains = document.querySelectorAll('main,[role=main]');
return mains.length<=1;
11 changes: 11 additions & 0 deletions lib/checks/keyboard/has-no-more-than-one-main.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"id": "has-no-more-than-one-main",
"evaluate": "has-no-more-than-one-main.js",
"metadata": {
"impact": "moderate",
"messages": {
"pass": "Document has no more than one main landmark",
"fail": "Document has more than one main landmark"
}
}
}
16 changes: 16 additions & 0 deletions lib/rules/landmark-no-more-than-one-main.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please remove this rule from the PR.

"id": "landmark-no-more-than-one-main",
"selector": "html",
"tags": [
"cat.best-practice"
],
"metadata": {
"description": "Each document in a page must have no more than one main landmark, used to identify the main content.",
"help": "A <main> element or an element with a role='main' attribute defines a main landmark."
},
"all": [],
"any": [
"has-no-more-than-one-main"
],
"none": []
}
37 changes: 37 additions & 0 deletions test/checks/keyboard/has-no-more-than-one-main.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
describe('has-no-more-than-one-main', function () {
'use strict';

var fixture = document.getElementById('fixture');

afterEach(function () {
fixture.innerHTML = '';
});

it('should return false if there is more than one element with role main', function () {
var mainDiv = document.createElement('div');
mainDiv.setAttribute('role','main');
var anotherMain = document.createElement('div');
anotherMain.setAttribute('role','main');
fixture.appendChild(mainDiv);
fixture.appendChild(anotherMain);
});

it('should return false if there is more than one main element', function () {
var mainLandmark = document.createElement('main');
var anotherMain = document.createElement('main');
fixture.appendChild(mainLandmark);
fixture.appendChild(anotherMain);
});

it('should return true if there is only one element with role main', function(){
var mainDiv = document.createElement('div');
mainDiv.setAttribute('role','main');
fixture.appendChild(mainDiv);
});

it('should return true if there is only one main element', function(){
var mainLandmark = document.createElement('main');
fixture.appendChild(mainLandmark);
});

});
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<!doctype html>
<html id="violation1">
<head>
<meta charset="utf8">
<script src="/axe.js"></script>
</head>
<body>
<main>
<p>Main content in the outer body</p>
</main>
<iframe id="frame2" src="level2.html"></iframe>
<iframe id="frame3" src="level2-a.html"></iframe>
</body>
</html>
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<!doctype html>
<html id="pass2">
<head>
<title>No lang test</title>
<meta charset="utf8">
<script src="/axe.js"></script>
</head>
<body>
Hi
</body>
</html>
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<!doctype html>
<html id="violation2">
<head>
<meta charset="utf8">
<script src="/axe.js"></script>
</head>
<body>
</body>
</html>
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<!doctype html>
<html lang="en" id="pass1">
<head>
<title>has-no-more-than-one-main test</title>
<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>

<iframe id="frame1" src="frames/level1.html"></iframe>
<div id="mocha"></div>
<script src="landmark-no-more-than-one-main-pass.js"></script>
<script src="/test/integration/adapter.js"></script>
</body>
</html>
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@

describe('landmark-no-more-than-one-main test pass', function () {
'use strict';
var results;
before(function (done) {
window.addEventListener('load', function () {
axe.run({ runOnly: { type: 'rule', values: ['landmark-no-more-than-one-main'] } }, function (err, r) {
assert.isNull(err);
results = r;
done();
});
});
});

describe('violations', function () {
it('should find 0', function () {
assert.lengthOf(results.violations, 0);
});
});

describe('passes', function () {
it('should find 2', function () {
assert.lengthOf(results.passes[0].nodes, 2);
});

it('should find #pass1', function () {
assert.deepEqual(results.passes[0].nodes[0].target, ['#pass1']);
});
});

it('should find 0 inapplicable', function () {
assert.lengthOf(results.inapplicable, 0);
});

it('should find 0 incomplete', function () {
assert.lengthOf(results.incomplete, 0);
});

});