Skip to content

Commit ea6171a

Browse files
committed
fix: page break role / page list errors were reported multiple times
1 parent fdcb568 commit ea6171a

File tree

10 files changed

+138
-3
lines changed

10 files changed

+138
-3
lines changed

packages/ace-core/src/checker/checker-epub.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -388,6 +388,7 @@ function checkReadingOrder(epub) {
388388
// let pos = -1;
389389
let failed = undefined;
390390
for (const page of pageListFilePathsAndTargetIDs) {
391+
failed = undefined;
391392
const found = docs.findIndex((doc) => page.full === doc.full);
392393
if (found === -1) {
393394
failed = page;
@@ -418,7 +419,7 @@ function checkReadingOrder(epub) {
418419
kbTitle: localize("checkepub.pagelistbrokenviolation.kbtitle"),
419420
ruleDesc: localize("checkepub.pagelistbrokenviolation.ruledesc", { ref, interpolation: { escapeValue: false } })
420421
}));
421-
// break;
422+
// break; MAKE SURE failed IS RESET TO undefined at each loop iteration
422423
}
423424
}
424425
if (!isFXL) {
@@ -460,6 +461,7 @@ function checkReadingOrder(epub) {
460461
let pos = -1;
461462
let failed = undefined;
462463
for (const toc of tocFilePathsAndTargetIDs) {
464+
failed = undefined;
463465
const found = docs.findIndex((doc) => toc.full === doc.full);
464466
if (found === -1) {
465467
failed = toc;
@@ -483,7 +485,7 @@ function checkReadingOrder(epub) {
483485
kbTitle: localize("checkepub.ordertocviolation.kbtitle"),
484486
ruleDesc: localize("checkepub.ordertocviolation.ruledesc", { ref, interpolation: { escapeValue: false } })
485487
}));
486-
break;
488+
break; // NO NEED TO MAKE SURE failed IS RESET TO undefined at each loop iteration
487489
}
488490
}
489491
}

tests/__tests__/epub-rules.test.js

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,26 @@ test('nothing to report', async () => {
4646
});
4747

4848
describe('page list and TOC reading order', () => {
49+
50+
test('minor missing page break for a page list item', async () => {
51+
const report = await ace('../data/epubrules-pagelist-missing-pagebreak-target');
52+
// console.log(JSON.stringify(report, null, 4));
53+
expect(report['earl:result']['earl:outcome']).toEqual('fail');
54+
const assertions = findAssertionsForDoc(report, '/EPUB/nav.xhtml');
55+
// console.log(JSON.stringify(assertions, null, 4));
56+
expect(assertions).toEqual(expect.arrayContaining([
57+
58+
expect.objectContaining({
59+
'earl:test': expect.objectContaining({
60+
'dct:title': 'epub-pagelist-broken',
61+
"earl:impact": "minor",
62+
"dct:description": expect.stringMatching(/.+content_001\.xhtml#p1.+/),
63+
}),
64+
}),
65+
66+
]));
67+
});
68+
4969
test('TOC correctly ordered PASS but missing page list item for a page break', async () => {
5070
const report = await ace('../data/epubrules-pagelist-missing-pagebreak');
5171
// console.log(JSON.stringify(report, null, 4));
@@ -67,6 +87,13 @@ describe('page list and TOC reading order', () => {
6787
"dct:description": expect.stringMatching(/.+content_002\.xhtml#p3.+/),
6888
}),
6989
}),
90+
expect.objectContaining({
91+
'earl:test': expect.objectContaining({
92+
'dct:title': 'epub-pagelist-missing-pagebreak',
93+
"earl:impact": "serious",
94+
"dct:description": expect.stringMatching(/.+content_002\.xhtml#p5.+/),
95+
}),
96+
}),
7097
]));
7198
});
7299
test('page list and TOC correctly ordered PASS, but SMIL missing pagebreak epub:type', async () => {
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 1</title>
4+
</head>
5+
<body>
6+
<h1>Loomings</h1>
7+
<p>Call me Ishmael.</p>
8+
<span id="p1" epub:typexx="pagebreak" rolexx="doc-pagebreak" aria-label="p1"/>
9+
<section id="sec"><p>txt1</p><p id="useless">txt2
10+
<span id="p2" epub:type="pagebreak" role="doc-pagebreak" aria-label="p2">p2</span>
11+
txt3</p><p>txt4</p></section>
12+
</body>
13+
</html>
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
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 2</title>
4+
</head>
5+
<body>
6+
<h1>Other</h1>
7+
<p>Bla.</p>
8+
<section id="sec"><p>txt1</p><p id="useless">txt2
9+
<span id="p3" epub:type="pagebreak" role="doc-pagebreak" aria-label="p3">p3</span>
10+
txt3</p><p>txt4</p></section>
11+
<span id="p4" epub:type="pagebreak" role="doc-pagebreak" aria-label="p4"/>
12+
13+
<span id="p5" epub:type="pagebreak" role="doc-pagebreak" aria-label="p5"> MISSING p5 in pagelist</span>
14+
</body>
15+
</html>
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
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+
7+
<a href="dummyHREF1">DUMMY 1</a>
8+
9+
<nav epub:type="toc" role="doc-toc">
10+
<ol>
11+
<li><a href="./content_001.xhtml">content 001</a></li>
12+
<li><ol>
13+
<li><a href="content_001.xhtml#p1">page 1</a></li>
14+
<li><a href="content_001.xhtml#sec">section</a></li>
15+
<li><a href="content_001.xhtml#p2">page 2</a></li>
16+
</ol>
17+
</li>
18+
<li><a href="../EPUB/content_002.xhtml">content 002</a></li>
19+
<li><ol>
20+
<li><a href="content_002.xhtml#sec">section</a></li>
21+
<li><a href="../EPUB/./content_002.xhtml#p3">page 3</a></li>
22+
<li><a href="content_002.xhtml#p4">page 4</a></li>
23+
</ol>
24+
</li>
25+
</ol>
26+
</nav>
27+
<nav epub:type="page-list" role="doc-pagelist">
28+
<ol>
29+
<li><a href="content_001.xhtml#p1">p1</a></li>
30+
<li><a href="content_001.xhtml#p2">p2</a></li>
31+
<li><a href="content_002.xhtml#p3">p3</a></li>
32+
<li><a href="content_002.xhtml#p4">p4</a></li>
33+
<li><a href="content_002.xhtml#p5">p5</a></li>
34+
</ol>
35+
</nav>
36+
37+
<a href="dummyHREF2">DUMMY2</a>
38+
39+
</body>
40+
</html>
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
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+
8+
<dc:source id="pg-src">urn:isbn:9781234567891</dc:source>
9+
<meta property="source-of" refines="#pg-src">pagination</meta>
10+
<!-- meta property="pageBreakSource">urn:isbn:9781234567891</meta -->
11+
12+
<meta property="dcterms:modified">2017-01-01T00:00:01Z</meta>
13+
<meta property="schema:accessibilityFeature">structuralNavigation</meta>
14+
<meta property="schema:accessibilitySummary">everything OK!</meta>
15+
<meta property="schema:accessibilityHazard">noFlashingHazard</meta>
16+
<meta property="schema:accessibilityHazard">noSoundHazard</meta>
17+
<meta property="schema:accessibilityHazard">noMotionSimulationHazard</meta>
18+
<meta property="schema:accessMode">textual</meta>
19+
<meta property="schema:accessModeSufficient">textual</meta>
20+
</metadata>
21+
<manifest>
22+
<item id="nav" href="nav.xhtml" media-type="application/xhtml+xml" properties="nav"/>
23+
<item id="content_001" href="content_001.xhtml" media-type="application/xhtml+xml"/>
24+
<item id="content_002" href="content_002.xhtml" media-type="application/xhtml+xml"/>
25+
</manifest>
26+
<spine>
27+
<itemref idref="content_001" />
28+
<itemref idref="content_002" />
29+
</spine>
30+
</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

tests/data/epubrules-pagelist-missing-pagebreak/EPUB/content_002.xhtml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,6 @@
1010
txt3</p><p>txt4</p></section>
1111
<span id="p4" epub:type="pagebreak" role="doc-pagebreak" aria-label="p4"/>
1212

13-
<span id="p5" role="doc-pagebreak" aria-label="p5">NOT MISSING p5 in pagelist</span>
13+
<span id="p5" role="doc-pagebreak" aria-label="p5"> MISSING p5 in pagelist</span>
1414
</body>
1515
</html>

tests/data/epubrules-pagelist-missing-pagebreak/EPUB/nav.xhtml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
<!-- li><a href="content_001.xhtml#p2">p2</a></li -->
3131
<!-- li><a href="content_002.xhtml#p3">p3</a></li -->
3232
<li><a href="content_002.xhtml#p4">p4</a></li>
33+
<!-- li><a href="content_002.xhtml#p5">p5</a></li -->
3334
</ol>
3435
</nav>
3536

0 commit comments

Comments
 (0)