Skip to content

Commit

Permalink
Add a unit test to check CFI range generation when start and end node…
Browse files Browse the repository at this point in the history
… don't have the same level

Related to readium#28
  • Loading branch information
ClementHard authored and matwood committed Aug 12, 2015
1 parent 7a2e857 commit 5c295d2
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions spec/javascripts/models/cfi_generation_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,33 @@ describe("CFI GENERATOR", function () {
expect(generatedCFI).toEqual("/4/2[startParent]/2,/1:2,/1:6");
});

it("generates for different node level", function () {

var dom =
"<html>"
+ "<div></div>"
+ "<div>"
+ "<div id='startParent'>"
+ "text target for start"
+ "<div>text target for end</div>"
+ "</div>"
+ "</div>"
+ "<div></div>"
+ "</html>";
var $dom = $((new window.DOMParser).parseFromString(dom, "text/xml"));

var $startElement = $($('#startParent', $dom).contents()[0]);
var $endElement = $($('#startParent', $dom).children()[0].firstChild);
var generatedCFI = EPUBcfi.Generator.generateCharOffsetRangeComponent(
$startElement[0],
2,
$endElement[0],
6
);

expect(generatedCFI).toEqual("/4/2[startParent],/1:2,/2/1:6");
});

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

var dom =
Expand Down

0 comments on commit 5c295d2

Please sign in to comment.