Skip to content

Commit

Permalink
feat: Add shadow DOM to landmark check
Browse files Browse the repository at this point in the history
  • Loading branch information
WilcoFiers committed Jul 17, 2017
1 parent 414fcbe commit 98f6023
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 7 deletions.
2 changes: 1 addition & 1 deletion lib/checks/navigation/landmark.js
Original file line number Diff line number Diff line change
@@ -1 +1 @@
return node.getElementsByTagName('main').length > 0 || !!node.querySelector('[role="main"]') ;
return axe.utils.querySelectorAll(virtualNode, 'main, [role="main"]').length > 0;
42 changes: 36 additions & 6 deletions test/checks/navigation/landmark.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,54 @@ describe('landmark', function () {
'use strict';

var fixture = document.getElementById('fixture');
var checkSetup = axe.testUtils.checkSetup;
var shadowSupport = axe.testUtils.shadowSupport;

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

it('should return true when role=main is found', function () {
fixture.innerHTML = '<div role="main"></div>';
assert.isTrue(checks.landmark.evaluate(fixture));
var checkArgs = checkSetup('<div role="main"></div>', '#fixture');
assert.isTrue(checks.landmark.evaluate.apply(null, checkArgs));
});

it('should return true when <main> is found', function () {
fixture.innerHTML = '<main></main>';
assert.isTrue(checks.landmark.evaluate(fixture));
var checkArgs = checkSetup('<main></main>', '#fixture');
assert.isTrue(checks.landmark.evaluate.apply(null, checkArgs));
});

it('should otherwise return false', function () {
fixture.innerHTML = '<div role="contentinfo"></div>';
assert.isFalse(checks.landmark.evaluate(fixture));
var checkArgs = checkSetup('<div role="contentinfo"></div>', '#fixture');
assert.isFalse(checks.landmark.evaluate.apply(null, checkArgs));
});

(shadowSupport ? it : xit)('should not automatically pass if there is a shadow tree', function () {
var node = document.createElement('div');
var shadow = node.attachShadow({ mode: 'open' });
shadow.innerHTML = '<div></div>';
var checkArgs = checkSetup(node, '#fixture');

assert.isFalse(checks.landmark.evaluate.apply(null, checkArgs));
});

(shadowSupport ? it : xit)('should find elements inside shadow trees', function () {
var node = document.createElement('div');
var shadow = node.attachShadow({ mode: 'open' });
shadow.innerHTML = '<main></main>';
var checkArgs = checkSetup(node, '#fixture');

assert.isTrue(checks.landmark.evaluate.apply(null, checkArgs));
});

(shadowSupport ? it : xit)('should find elements slotted in shadow trees', function () {
var node = document.createElement('div');
node.innerHTML = '<main></main>';
var shadow = node.attachShadow({ mode: 'open' });
shadow.innerHTML = '<slot></slot>';
var checkArgs = checkSetup(node, '#fixture');

assert.isTrue(checks.landmark.evaluate.apply(null, checkArgs));
});

});

0 comments on commit 98f6023

Please sign in to comment.