Skip to content

Commit a078739

Browse files
committed
feat(rules): ensure that page break markers have an accessible label
Configure a new aXe rule to ensure that page break markers (identified with the ARIA role `doc-pagebreak` or with `epub:type="pagebreak"`) have an accessible label defined in a `title` attribute or an `aria-label` attribute. Closes #71
1 parent b18740a commit a078739

File tree

9 files changed

+105
-1
lines changed

9 files changed

+105
-1
lines changed

src/report/axe2ace.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ const winston = require('winston');
99
const kbMap = {
1010
'baseUrl': 'http://kb.daisy.org/publishing/',
1111
'map': {
12+
'pagebreak-label': {url: 'docs/navigation/pagelist.html', 'title': 'Page Breaks'},
1213
'html-has-lang': {url: 'docs/html/lang.html', title: 'Language'},
1314
'html-lang-valid': {url: 'docs/html/lang.html', title: 'Language'},
1415
'valid-lang': {url: 'docs/html/lang.html', title: 'Language'},

src/scripts/ace-axe.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,20 @@ daisy.ace.run = function(done) {
8383
}
8484
};
8585

86+
window.axe.configure({
87+
rules: [
88+
{
89+
id: 'pagebreak-label',
90+
selector: '[*|type~="pagebreak"], [role~="doc-pagebreak"]',
91+
any: ['aria-label', 'non-empty-title'],
92+
metadata: {
93+
description: "Ensure page markers have an accessible label",
94+
},
95+
tags: ['cat.epub']
96+
}
97+
]
98+
});
99+
86100
window.axe.run(
87101
{
88102
"rules": {

tests/__tests__/axe-rules.test.js

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,3 +45,28 @@ test('DPUB ARIA roles are allowed', async () => {
4545
const report = await ace('../data/axerule-dpubroles');
4646
expect(report['earl:result']['earl:outcome']).toEqual('pass');
4747
});
48+
49+
test('Ensure page breaks have labels', async () => {
50+
const report = await ace('../data/axerule-pagebreak-label');
51+
expect(report['earl:result']['earl:outcome']).toEqual('fail');
52+
expect(report.assertions).toEqual(expect.arrayContaining([
53+
expect.objectContaining({
54+
'earl:testSubject': expect.objectContaining({ url: 'content_001.xhtml' }),
55+
assertions: [
56+
expect.objectContaining({
57+
'earl:test': expect.objectContaining({ 'dct:title': 'pagebreak-label' }),
58+
'earl:result': expect.objectContaining({
59+
'earl:outcome': 'fail',
60+
'earl:pointer': expect.objectContaining({ css: ['#p3'] }),
61+
}),
62+
}),
63+
expect.objectContaining({
64+
'earl:test': expect.objectContaining({ 'dct:title': 'pagebreak-label' }),
65+
'earl:result': expect.objectContaining({
66+
'earl:outcome': 'fail',
67+
'earl:pointer': expect.objectContaining({ css: ['#p4'] }),
68+
}),
69+
}),
70+
],
71+
})]));
72+
});

tests/data/axerule-dpubroles/EPUB/content_001.xhtml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@
4242
<div role="doc-introduction"></div>
4343
<div role="doc-noteref"></div>
4444
<div role="doc-notice"></div>
45-
<div role="doc-pagebreak"></div>
45+
<div role="doc-pagebreak" title="p1"></div>
4646
<div role="doc-pagelist"></div>
4747
<div role="doc-part"></div>
4848
<div role="doc-preface"></div>
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:epub="http://www.idpf.org/2007/ops" xml:lang="en">
2+
<head>
3+
<title>Minimal EPUB</title>
4+
</head>
5+
<body>
6+
<h1>Loomings</h1>
7+
<p>Call me Ishmael.</p>
8+
<span id="p1" role="doc-pagebreak" title="p1"/>
9+
<span id="p2" epub:type="pagebreak" title="p2"/>
10+
<span id="p3" role="doc-pagebreak"/>
11+
<span id="p4" epub:type="pagebreak"/>
12+
</body>
13+
</html>
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:epub="http://www.idpf.org/2007/ops" xml:lang="en">
2+
<head>
3+
<title>Minimal Nav</title>
4+
</head>
5+
<body>
6+
<nav epub:type="toc">
7+
<ol>
8+
<li><a href="content_001.xhtml">content 001</a></li>
9+
</ol>
10+
</nav>
11+
<nav epub:type="page-list">
12+
<ol>
13+
<li><a href="content_001.xhtml#p1">page 1</a></li>
14+
<li><a href="content_001.xhtml#p2">page 2</a></li>
15+
<li><a href="content_001.xhtml#p3">page 3</a></li>
16+
<li><a href="content_001.xhtml#p4">page 4</a></li>
17+
</ol>
18+
</nav>
19+
</body>
20+
</html>
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<package xmlns="http://www.idpf.org/2007/opf" version="3.0" xml:lang="en" unique-identifier="uid">
3+
<metadata xmlns:dc="http://purl.org/dc/elements/1.1/">
4+
<dc:title id="title">Minimal EPUB 3.0</dc:title>
5+
<dc:language>en</dc:language>
6+
<dc:identifier id="uid">NOID</dc:identifier>
7+
<dc:source>https://example.com</dc:source>
8+
<meta property="dcterms:modified">2017-01-01T00:00:01Z</meta>
9+
<meta property="schema:accessibilityFeature">structuralNavigation</meta>
10+
<meta property="schema:accessibilitySummary">everything OK!</meta>
11+
<meta property="schema:accessibilityHazard">noFlashingHazard</meta>
12+
<meta property="schema:accessibilityHazard">noSoundHazard</meta>
13+
<meta property="schema:accessibilityHazard">noMotionSimulationHazard</meta>
14+
<meta property="schema:accessMode">textual</meta>
15+
<meta property="schema:accessModeSufficient">textual</meta>
16+
</metadata>
17+
<manifest>
18+
<item id="nav" href="nav.xhtml" media-type="application/xhtml+xml" properties="nav"/>
19+
<item id="content_001" href="content_001.xhtml" media-type="application/xhtml+xml"/>
20+
</manifest>
21+
<spine>
22+
<itemref idref="content_001" />
23+
</spine>
24+
</package>
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<?xml version="1.0" encoding="UTF-8" ?>
2+
<container version="1.0" xmlns="urn:oasis:names:tc:opendocument:xmlns:container">
3+
<rootfiles>
4+
<rootfile full-path="EPUB/package.opf" media-type="application/oebps-package+xml"/>
5+
</rootfiles>
6+
</container>
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
application/epub+zip

0 commit comments

Comments
 (0)