Skip to content

Commit

Permalink
fix: aria-describedby can be a list of IDs
Browse files Browse the repository at this point in the history
- Do not fail when `aria-describedby` has a list of ID references.
- Only the first ID is used to extract the description in the report

Fixes #209
  • Loading branch information
rdeltour committed Jul 4, 2019
1 parent a5452c3 commit f0aef4c
Show file tree
Hide file tree
Showing 9 changed files with 72 additions and 3 deletions.
5 changes: 3 additions & 2 deletions packages/ace-core/src/scripts/ace-extraction.js
Original file line number Diff line number Diff line change
Expand Up @@ -178,8 +178,9 @@ ace.getImages = function() {
}
let describedby = img.getAttribute('aria-describedby')
if (describedby) {
let elem = document.getElementById(describedby);
imageObj.describedby = elem.innerText || elem.textContent;
var describedbyID = describedby.trim().replace(/\s{2,}/g, ' ').split(' ').shift();
let elem = document.getElementById(describedbyID);
if (elem) imageObj.describedby = elem.innerText || elem.textContent;
}
let figure = findFigure(img);
if (figure) {
Expand Down
2 changes: 1 addition & 1 deletion tests/__tests__/axe-rules.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ test('Checks that `epub:type` have matching ARIA roles', async() => {
})
]));
});
test('Checks that `epub:type` `cover` isn’t reported has missing a matching ARIA role', async() => {
test.only('Checks that `epub:type` `cover` isn’t reported has missing a matching ARIA role', async() => {
const report = await ace('../data/axerule-matching-dpub-role-cover');
expect(report['earl:result']['earl:outcome']).toEqual('pass');
});
12 changes: 12 additions & 0 deletions tests/__tests__/regression.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,3 +89,15 @@ test('issue #182: named character references are parsed', async () => {
})
]));
});

test('issue #209: `aria-describedby` can be a list of IDs', async () => {
const report = await ace('../data/issue-209');
expect(report.data).toEqual(expect.objectContaining({
"images": expect.arrayContaining([
expect.objectContaining({
"src": "EPUB/image_001.jpg",
"describedby": "description 1",
})
])
}));
});
12 changes: 12 additions & 0 deletions tests/data/issue-209/EPUB/content_001.xhtml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:epub="http://www.idpf.org/2007/ops" xml:lang="en">
<head>
<title>Minimal EPUB</title>
</head>
<body>
<h1>Loomings</h1>
<p>Call me Ishmael.</p>
<img id="img" src="image_001.jpg" alt="a fake image" aria-describedby="desc1 desc2"/>
<p id="desc1">description 1</p>
<p id="desc2">description 2</p>
</body>
</html>
1 change: 1 addition & 0 deletions tests/data/issue-209/EPUB/image_001.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
12 changes: 12 additions & 0 deletions tests/data/issue-209/EPUB/nav.xhtml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:epub="http://www.idpf.org/2007/ops" xml:lang="en">
<head>
<title>Minimal Nav</title>
</head>
<body>
<nav epub:type="toc">
<ol>
<li><a href="content_001.xhtml">content 001</a></li>
</ol>
</nav>
</body>
</html>
24 changes: 24 additions & 0 deletions tests/data/issue-209/EPUB/package.opf
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?xml version="1.0" encoding="UTF-8"?>
<package xmlns="http://www.idpf.org/2007/opf" version="3.0" xml:lang="en" unique-identifier="uid">
<metadata xmlns:dc="http://purl.org/dc/elements/1.1/">
<dc:title id="title">Minimal EPUB 3.0</dc:title>
<dc:language>en</dc:language>
<dc:identifier id="uid">NOID</dc:identifier>
<meta property="dcterms:modified">2017-01-01T00:00:01Z</meta>
<meta property="schema:accessibilityFeature">structuralNavigation</meta>
<meta property="schema:accessibilitySummary">everything OK!</meta>
<meta property="schema:accessibilityHazard">noFlashingHazard</meta>
<meta property="schema:accessibilityHazard">noSoundHazard</meta>
<meta property="schema:accessibilityHazard">noMotionSimulationHazard</meta>
<meta property="schema:accessMode">textual</meta>
<meta property="schema:accessModeSufficient">textual</meta>
</metadata>
<manifest>
<item id="nav" href="nav.xhtml" media-type="application/xhtml+xml" properties="nav"/>
<item id="content_001" href="content_001.xhtml" media-type="application/xhtml+xml"/>
<item id="image_001" href="image_001.jpg" media-type="image/jpeg"/>
</manifest>
<spine>
<itemref idref="content_001" />
</spine>
</package>
6 changes: 6 additions & 0 deletions tests/data/issue-209/META-INF/container.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8" ?>
<container version="1.0" xmlns="urn:oasis:names:tc:opendocument:xmlns:container">
<rootfiles>
<rootfile full-path="EPUB/package.opf" media-type="application/oebps-package+xml"/>
</rootfiles>
</container>
1 change: 1 addition & 0 deletions tests/data/issue-209/mimetype
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
application/epub+zip

0 comments on commit f0aef4c

Please sign in to comment.