-
Notifications
You must be signed in to change notification settings - Fork 769
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
Changes from 1 commit
Commits
Show all changes
24 commits
Select commit
Hold shift + click to select a range
edeb860
init
sulsanaul 3d37aab
feat: add new rule, landmark-no-more-than-one-main
sulsanaul 4e1b18b
test(landmark-at-least-one-main): updated integration tests for check
sulsanaul 2840b02
feat(landmark-main-is-top-level): add rule ensuring each main landmar…
sulsanaul fa6069d
Merge https://github.com/dequelabs/axe-core into main/is-top-level
sulsanaul 6eb553b
refactor(landmark-main-is-top-level): change help messages
sulsanaul 094e251
feat(landmark-main-is-top-level): change a function used in check and…
sulsanaul 2c55cbb
refactor(main-is-top-level): change pass/fail messages
sulsanaul b9b1bf5
refactor(landmark-main-is-top-level): change description/help messages
sulsanaul bf85e0d
Merge https://github.com/dequelabs/axe-core into main/is-top-level
sulsanaul 747990d
Merge branch 'main/is-top-level' of https://github.com/ssanaul/axe-co…
sulsanaul 9c0e75c
feat(main-is-top-level): update check for shadow dom features
sulsanaul 824ee2d
fix(main-is-top-level): update check to ignore form as a landmark
sulsanaul 05ee0a7
fix: edit incorrect usage of getComposedParent
sulsanaul 73ed9cf
test: add unit test to check if main landmark in shadow dom is top level
sulsanaul f82c667
style: remove spaces in attributes
sulsanaul 34407e9
fix: update test so that checkSetup passes in correct argument
sulsanaul 3e5c6ad
test: add test to ensure correct number of violations nodes
sulsanaul ff463ef
Merge branch 'main/is-top-level' of https://github.com/ssanaul/axe-co…
sulsanaul 03e5434
fix: revert 'application' type to landmark
sulsanaul 56ad598
Merge https://github.com/dequelabs/axe-core into main/is-top-level
sulsanaul 00b10c1
Merge https://github.com/dequelabs/axe-core into main/is-top-level
sulsanaul f936751
style: remove spaces in attributes
sulsanaul 12b1903
fix: allow main landmark to be in form
sulsanaul File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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; |
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,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" | ||
} | ||
} | ||
} |
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": "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": [] | ||
} |
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,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); | ||
}); | ||
|
||
}); |
14 changes: 14 additions & 0 deletions
14
test/integration/full/landmark-no-more-than-one-main/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,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> |
11 changes: 11 additions & 0 deletions
11
test/integration/full/landmark-no-more-than-one-main/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,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> |
9 changes: 9 additions & 0 deletions
9
test/integration/full/landmark-no-more-than-one-main/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,9 @@ | ||
<!doctype html> | ||
<html id="violation2"> | ||
<head> | ||
<meta charset="utf8"> | ||
<script src="/axe.js"></script> | ||
</head> | ||
<body> | ||
</body> | ||
</html> |
25 changes: 25 additions & 0 deletions
25
.../integration/full/landmark-no-more-than-one-main/landmark-no-more-than-one-main-pass.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,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> |
39 changes: 39 additions & 0 deletions
39
test/integration/full/landmark-no-more-than-one-main/landmark-no-more-than-one-main-pass.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,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); | ||
}); | ||
|
||
}); |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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.