-
Notifications
You must be signed in to change notification settings - Fork 784
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(get-ancestry): add nth-child selector for multiple siblings of sh…
- Loading branch information
Showing
2 changed files
with
43 additions
and
22 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,50 +1,69 @@ | ||
describe('axe.utils.getAncestry', function () { | ||
describe('axe.utils.getAncestry', () => { | ||
'use strict'; | ||
var fixture = document.getElementById('fixture'); | ||
var shadowTest = axe.testUtils.shadowSupport.v1 ? it : xit; | ||
const fixture = document.getElementById('fixture'); | ||
|
||
afterEach(function () { | ||
afterEach(() => { | ||
fixture.innerHTML = ''; | ||
}); | ||
|
||
it('should be a function', function () { | ||
it('should be a function', () => { | ||
assert.isFunction(axe.utils.getAncestry); | ||
}); | ||
|
||
it('should generate an ancestry selector', function () { | ||
it('should generate an ancestry selector', () => { | ||
fixture.innerHTML = '<div>1</div> <p>2</p> <p>3</p>'; | ||
|
||
var sel1 = axe.utils.getAncestry(fixture.children[0]); | ||
const sel1 = axe.utils.getAncestry(fixture.children[0]); | ||
assert.equal(sel1, 'html > body > div:nth-child(1) > div:nth-child(1)'); | ||
assert.isNotNull(document.querySelector(sel1)); | ||
|
||
var sel2 = axe.utils.getAncestry(fixture.children[1]); | ||
const sel2 = axe.utils.getAncestry(fixture.children[1]); | ||
assert.equal(sel2, 'html > body > div:nth-child(1) > p:nth-child(2)'); | ||
assert.isNotNull(document.querySelector(sel1)); | ||
|
||
var sel3 = axe.utils.getAncestry(fixture.children[2]); | ||
const sel3 = axe.utils.getAncestry(fixture.children[2]); | ||
assert.equal(sel3, 'html > body > div:nth-child(1) > p:nth-child(3)'); | ||
assert.isNotNull(document.querySelector(sel1)); | ||
}); | ||
|
||
shadowTest('generates selectors of nested shadow trees', function () { | ||
var node = document.createElement('section'); | ||
it('generates selectors of nested shadow trees', () => { | ||
const node = document.createElement('section'); | ||
fixture.appendChild(node); | ||
|
||
var shadowRoot1 = node.attachShadow({ mode: 'open' }); | ||
const shadowRoot1 = node.attachShadow({ mode: 'open' }); | ||
shadowRoot1.innerHTML = '<div><article><slot /></article</div>'; | ||
|
||
var shadowRoot2 = shadowRoot1 | ||
const shadowRoot2 = shadowRoot1 | ||
.querySelector('article') | ||
.attachShadow({ mode: 'open' }); | ||
shadowRoot2.innerHTML = '<h1>Hello world</h1>'; | ||
|
||
var target = shadowRoot2.querySelector('h1'); | ||
var sel = axe.utils.getAncestry(target); | ||
const target = shadowRoot2.querySelector('h1'); | ||
const sel = axe.utils.getAncestry(target); | ||
assert.deepEqual(sel, [ | ||
'html > body > div:nth-child(1) > section', | ||
'div > article', | ||
'h1' | ||
]); | ||
}); | ||
|
||
it('generates selectors of siblings in shadow tree', () => { | ||
const node = document.createElement('section'); | ||
fixture.appendChild(node); | ||
|
||
const shadowRoot = node.attachShadow({ mode: 'open' }); | ||
shadowRoot.innerHTML = '<div>1</div> <div>2</div>'; | ||
|
||
const sel1 = axe.utils.getAncestry(shadowRoot.children[0]); | ||
assert.deepEqual(sel1, [ | ||
'html > body > div:nth-child(1) > section', | ||
'div:nth-child(1)' | ||
]); | ||
|
||
const sel2 = axe.utils.getAncestry(shadowRoot.children[1]); | ||
assert.deepEqual(sel2, [ | ||
'html > body > div:nth-child(1) > section', | ||
'div:nth-child(2)' | ||
]); | ||
}); | ||
}); |