Skip to content

Commit

Permalink
Add an additional unit test from readium#28
Browse files Browse the repository at this point in the history
  • Loading branch information
Dmitry M authored and matwood committed Aug 12, 2015
1 parent 54bbec7 commit 5cf9432
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions spec/javascripts/models/cfi_generation_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,32 @@ describe("CFI GENERATOR", function () {
expect(generatedCFI).toEqual("/4/2[startParent],/1:2,/2/1:6");
});

// https://github.com/readium/readium-cfi-js/issues/28
it("generates for different node level II", function () {

var dom =
" <html>" +
" <body>" +
" <h1>Title</h1>" +
" <p>Some <strong>very important</strong> text</p>" +
" </body>" +
"</html>";

var $dom = $((new window.DOMParser).parseFromString(dom, "text/xml"));
// per the issue The CFI for "important text" should be : /2/4, /2/1:5, /3:5
var $startElement = $($("strong", $dom).contents()[0]); // "very important"
var $endElement = $($("p", $dom).contents()[2]); // " text"
var generatedCFI = EPUBcfi.Generator.generateCharOffsetRangeComponent(
$startElement[0],
5,
$endElement[0],
5
);

expect(generatedCFI).toEqual("/2/4,/2/1:5,/3:5");
});


it("generates for an element with multiple child text nodes", function () {

var dom =
Expand Down

0 comments on commit 5cf9432

Please sign in to comment.