From 72e5bd5081582c24990ec1549901698f11011249 Mon Sep 17 00:00:00 2001 From: Romain Deltour Date: Sat, 28 Oct 2017 13:06:15 +0200 Subject: [PATCH] fix(rules): properly detect page markers using `epub:type="pagebreak"` Closes #85 --- src/scripts/ace-extraction.js | 2 +- src/scripts/ace-extraction.test.js | 2 +- tests/__tests__/regression.test.js | 6 ++++++ tests/data/issue-85/EPUB/content_001.xhtml | 10 +++++++++ tests/data/issue-85/EPUB/nav.xhtml | 17 +++++++++++++++ tests/data/issue-85/EPUB/package.opf | 24 ++++++++++++++++++++++ tests/data/issue-85/META-INF/container.xml | 6 ++++++ tests/data/issue-85/mimetype | 1 + 8 files changed, 66 insertions(+), 2 deletions(-) create mode 100644 tests/data/issue-85/EPUB/content_001.xhtml create mode 100644 tests/data/issue-85/EPUB/nav.xhtml create mode 100644 tests/data/issue-85/EPUB/package.opf create mode 100644 tests/data/issue-85/META-INF/container.xml create mode 100644 tests/data/issue-85/mimetype diff --git a/src/scripts/ace-extraction.js b/src/scripts/ace-extraction.js index 80652dce..1b5cadf9 100644 --- a/src/scripts/ace-extraction.js +++ b/src/scripts/ace-extraction.js @@ -242,5 +242,5 @@ ace.hasMathML = function() { } ace.hasPageBreaks = function() { - return document.querySelectorAll('[epub\\:type~="pagebreak"], [role~="doc-pagebreak"]').length > 0; + return document.querySelectorAll('[*|type~="pagebreak"], [role~="doc-pagebreak"]').length > 0; } diff --git a/src/scripts/ace-extraction.test.js b/src/scripts/ace-extraction.test.js index b3932b5b..dad66fa2 100644 --- a/src/scripts/ace-extraction.test.js +++ b/src/scripts/ace-extraction.test.js @@ -321,7 +321,7 @@ describe('finding pagebreaks', () => { expect(results).toBe(false); }); - test.skip('epub:type break', async () => { + test('epub:type break', async () => { const results = await run('hasPageBreaks', ''); expect(results).toBe(true); }); diff --git a/tests/__tests__/regression.test.js b/tests/__tests__/regression.test.js index 71a97649..641f1c9a 100644 --- a/tests/__tests__/regression.test.js +++ b/tests/__tests__/regression.test.js @@ -50,3 +50,9 @@ test('issue #57: Failed to execute \'matches\' on \'Element\': \'m:annotation-xm const report = await ace('../data/issue-57'); expect(report['earl:result']['earl:outcome']).toEqual('pass'); }); + +test('issue #85: failed to detect page markers from `epub:type`', async () => { + const report = await ace('../data/issue-85'); + expect(report['earl:result']['earl:outcome']).toEqual('pass'); + expect(report.properties.hasPageBreaks).toBe(true); +}); diff --git a/tests/data/issue-85/EPUB/content_001.xhtml b/tests/data/issue-85/EPUB/content_001.xhtml new file mode 100644 index 00000000..ce8cf670 --- /dev/null +++ b/tests/data/issue-85/EPUB/content_001.xhtml @@ -0,0 +1,10 @@ + + +Minimal EPUB + + +

Loomings

+

Call me Ishmael.

+ + + diff --git a/tests/data/issue-85/EPUB/nav.xhtml b/tests/data/issue-85/EPUB/nav.xhtml new file mode 100644 index 00000000..9e2b963c --- /dev/null +++ b/tests/data/issue-85/EPUB/nav.xhtml @@ -0,0 +1,17 @@ + + +Minimal Nav + + + + + + diff --git a/tests/data/issue-85/EPUB/package.opf b/tests/data/issue-85/EPUB/package.opf new file mode 100644 index 00000000..1e0bd931 --- /dev/null +++ b/tests/data/issue-85/EPUB/package.opf @@ -0,0 +1,24 @@ + + + + Minimal EPUB 3.0 + en + NOID + https://example.com + 2017-01-01T00:00:01Z + structuralNavigation + everything OK! + noFlashingHazard + noSoundHazard + noMotionSimulationHazard + textual + textual + + + + + + + + + diff --git a/tests/data/issue-85/META-INF/container.xml b/tests/data/issue-85/META-INF/container.xml new file mode 100644 index 00000000..2cf00654 --- /dev/null +++ b/tests/data/issue-85/META-INF/container.xml @@ -0,0 +1,6 @@ + + + + + + diff --git a/tests/data/issue-85/mimetype b/tests/data/issue-85/mimetype new file mode 100644 index 00000000..57ef03f2 --- /dev/null +++ b/tests/data/issue-85/mimetype @@ -0,0 +1 @@ +application/epub+zip \ No newline at end of file