From 9ddfc0f415cf7ae562e775c83a48adbe74c5ed4d Mon Sep 17 00:00:00 2001 From: Wilco Fiers Date: Mon, 17 Jul 2017 19:38:30 +0200 Subject: [PATCH] feat: Make explicit check consider shadow DOM (#442) --- test/checks/label/explicit.js | 44 +++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) diff --git a/test/checks/label/explicit.js b/test/checks/label/explicit.js index 11aae79908..805f261062 100644 --- a/test/checks/label/explicit.js +++ b/test/checks/label/explicit.js @@ -3,6 +3,7 @@ describe('explicit-label', function () { var fixture = document.getElementById('fixture'); var fixtureSetup = axe.testUtils.fixtureSetup; + var shadowSupport = axe.testUtils.shadowSupport; afterEach(function () { fixture.innerHTML = ''; @@ -34,4 +35,47 @@ describe('explicit-label', function () { assert.isFalse(checks['explicit-label'].evaluate(node)); }); + (shadowSupport.v1 ? it : xit)('should return true if input and label are in the same shadow root', function () { + var root = document.createElement('div'); + var shadow = root.attachShadow({ mode: 'open' }); + shadow.innerHTML = ''; + fixtureSetup(root); + + var node = shadow.querySelector('#target'); + assert.isTrue(checks['explicit-label'].evaluate(node)); + }); + + (shadowSupport.v1 ? it : xit)('should return true if label content is slotted', function () { + var root = document.createElement('div'); + root.innerHTML = 'American band'; + var shadow = root.attachShadow({ mode: 'open' }); + shadow.innerHTML = ''; + fixtureSetup(root); + + var node = shadow.querySelector('#target'); + assert.isTrue(checks['explicit-label'].evaluate(node)); + }); + + (shadowSupport.v1 ? it : xit)('should return false if input is inside shadow DOM and the label is not', function () { + var root = document.createElement('div'); + root.innerHTML = ''; + var shadow = root.attachShadow({ mode: 'open' }); + shadow.innerHTML = ''; + fixtureSetup(root); + + var node = shadow.querySelector('#target'); + assert.isFalse(checks['explicit-label'].evaluate(node)); + }); + + (shadowSupport.v1 ? it : xit)('should return false if label is inside shadow DOM and the input is not', function () { + var root = document.createElement('div'); + root.innerHTML = ''; + var shadow = root.attachShadow({ mode: 'open' }); + shadow.innerHTML = ''; + fixtureSetup(root); + + var node = root.querySelector('#target'); + assert.isFalse(checks['explicit-label'].evaluate(node)); + }); + });