-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: report EPUB-specific violations
Add EPUB-specific checks in a new `checker-epub` module, sibling to `checker-nightmare` which handles the HTML content. The new checker is responsible for checking publication-level violations. Currently: - checks that the publication has a title - checks the presence of a11y metadata - checks that the source of page breaks (if any) is defined Closes #10
- Loading branch information
Showing
24 changed files
with
310 additions
and
26 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,106 @@ | ||
'use strict'; | ||
|
||
const builders = require('../report/report-builders.js'); | ||
const winston = require('winston'); | ||
|
||
const ASSERTED_BY = 'Ace'; | ||
const MODE = 'automatic'; | ||
const KB_BASE = 'https://daisy.github.io/a11y-kb/'; | ||
|
||
function newViolation({ impact = 'serious', title, testDesc, resDesc, kbPath, kbTitle }) { | ||
return new builders.AssertionBuilder() | ||
.withAssertedBy(ASSERTED_BY) | ||
.withMode(MODE) | ||
.withTest( | ||
new builders.TestBuilder() | ||
.withImpact(impact) | ||
.withTitle(title) | ||
.withDescription(testDesc) | ||
.withHelp( | ||
KB_BASE + kbPath, | ||
kbTitle) | ||
.build()) | ||
.withResult( | ||
new builders.ResultBuilder('fail') | ||
.withDescription(resDesc) | ||
.build()) | ||
.build(); | ||
} | ||
|
||
function newMetadataAssertion(name, impact = 'serious') { | ||
return newViolation({ | ||
impact, | ||
title: `metadata-${name.toLowerCase().replace(':', '-')}`, | ||
testDesc: `Ensures a '${name}' metadata is present`, | ||
resDesc: `Add a '${name}' metadata property to the Package Document`, | ||
kbPath: 'docs/metadata/schema-org.html', | ||
kbTitle: 'Schema.org Accessibility Metadata', | ||
}); | ||
} | ||
|
||
function checkMetadata(assertions, epub) { | ||
// Required metadata | ||
[ | ||
'schema:accessMode', | ||
'schema:accessibilityFeature', | ||
'schema:accessibilitySummary', | ||
].filter(meta => epub.metadata[meta] === undefined) | ||
.forEach(meta => assertions.withAssertions(newMetadataAssertion(meta))); | ||
// Recommended metadata | ||
[ | ||
'schema:accessModeSufficient', | ||
].filter(meta => epub.metadata[meta] === undefined) | ||
.forEach(meta => assertions.withAssertions(newMetadataAssertion(meta, 'moderate'))); | ||
} | ||
|
||
function checkTitle(assertions, epub) { | ||
const title = epub.metadata['dc:title']; | ||
if (title === undefined || title.trim() === '') { | ||
assertions.withAssertions(newViolation({ | ||
title: 'epub-title', | ||
testDesc: 'Ensures the EPUB has a title', | ||
resDesc: 'Add a \'dc:title\' metadata property to the Package Document', | ||
kbPath: '', | ||
kbTitle: 'EPUB Title', | ||
})); | ||
} | ||
} | ||
|
||
function checkPageSource(assertion, epub) { | ||
if (epub.navDoc.hasPageList | ||
&& (epub.metadata['dc:source'] === undefined | ||
|| epub.metadata['dc:source'].trim() === '')) { | ||
assertion.withAssertions(newViolation({ | ||
title: 'epub-pagesource', | ||
testDesc: 'Ensures the source of page breaks is identified', | ||
resDesc: 'Add a \'dc:source\' metadata property to the Package Document', | ||
kbPath: 'docs/navigation/pagelist.html', | ||
kbTitle: 'Page Navigation', | ||
})); | ||
} | ||
} | ||
|
||
function check(epub, report) { | ||
winston.info('Checking package...'); | ||
const assertion = new builders.AssertionBuilder() | ||
.withSubAssertions() | ||
.withTestSubject( | ||
epub.packageDoc.src, | ||
(epub.metadata['dc:title'] !== undefined) ? epub.metadata['dc:title'] : ''); | ||
|
||
// Check a11y metadata | ||
checkMetadata(assertion, epub); | ||
|
||
// Check presence of a title | ||
checkTitle(assertion, epub); | ||
|
||
// Check page list is sourced | ||
checkPageSource(assertion, epub); | ||
|
||
report.addAssertions(assertion.build()); | ||
// Report the Nav Doc | ||
report.addEPUBNav(epub.navDoc); | ||
return Promise.resolve(); | ||
} | ||
|
||
module.exports.check = check; |
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
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
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
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
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 |
---|---|---|
@@ -0,0 +1,49 @@ | ||
'use strict'; | ||
|
||
const fs = require('fs'); | ||
const path = require('path'); | ||
const tmp = require('tmp'); | ||
|
||
const runAce = require('../runAceJS'); | ||
|
||
tmp.setGracefulCleanup(); | ||
|
||
let outdir; | ||
let tmpdir; | ||
let reportPath; | ||
|
||
beforeEach(() => { | ||
outdir = tmp.dirSync({ prefix: 'ace_out_', unsafeCleanup: true }); | ||
tmpdir = tmp.dirSync({ prefix: 'ace_tmp_', unsafeCleanup: true }); | ||
reportPath = path.join(outdir.name, 'ace.json'); | ||
}); | ||
|
||
afterEach(() => { | ||
outdir.removeCallback(); | ||
tmpdir.removeCallback(); | ||
}); | ||
|
||
|
||
function ace(epub, options = {}) { | ||
return runAce(path.join(__dirname, epub), Object.assign({ | ||
outdir: outdir.name, | ||
tmp: tmpdir.name, | ||
}, options)) | ||
.then(() => { | ||
expect(fs.existsSync(reportPath)).toBeTruthy(); | ||
return JSON.parse(fs.readFileSync(reportPath, 'utf8')); | ||
}) | ||
.catch(err => console.log(err)); | ||
} | ||
|
||
test('nothing to report', async () => { | ||
const report = await ace('../data/base-epub-30'); | ||
expect(report['earl:result']['earl:outcome']).toEqual('pass'); | ||
}); | ||
|
||
describe('page list and breaks', () => { | ||
test.only('page list correctly sourced', async () => { | ||
const report = await ace('../data/epubrules-pagelist'); | ||
expect(report['earl:result']['earl:outcome']).toEqual('pass'); | ||
}); | ||
}); |
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
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 |
---|---|---|
@@ -0,0 +1,10 @@ | ||
<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> | ||
<span id="p1" epub:type="pagebreak" aria-label="p1"/> | ||
</body> | ||
</html> |
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 |
---|---|---|
@@ -0,0 +1,16 @@ | ||
<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> | ||
<nav epub:type="page-list"> | ||
<ol> | ||
<li><a href="content_001.xhtml#p1">p1</a></li> | ||
</ol> | ||
</nav></body> | ||
</html> |
Oops, something went wrong.