Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
9c88746
commit eb7e7f6
Showing
3 changed files
with
77 additions
and
40 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
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,76 @@ | ||
describe("summary", function() { | ||
var cheerio = require("cheerio"); | ||
var summary = require("../summary"); | ||
|
||
beforeEach(function() { | ||
this.summary = function(input) { | ||
var $ = cheerio.load(input.html, { | ||
decodeEntities: false, | ||
withDomLvl1: false // this may cause issues? | ||
}); | ||
|
||
return summary($, input.title || ""); | ||
}; | ||
}); | ||
|
||
it("is empty when HTML is empty", function() { | ||
expect( | ||
this.summary({ | ||
title: "", | ||
html: "" | ||
}) | ||
).toEqual(""); | ||
}); | ||
|
||
it("is the text of the first paragraph", function() { | ||
expect( | ||
this.summary({ | ||
html: "<p>H</p>" | ||
}) | ||
).toEqual("H"); | ||
}); | ||
|
||
it("contains text inside inline elements", function() { | ||
expect( | ||
this.summary({ | ||
html: "<p>H<b>ell</b>o</p>" | ||
}) | ||
).toEqual("Hello"); | ||
}); | ||
|
||
it("does not contain the text of the title", function() { | ||
expect( | ||
this.summary({ | ||
html: "<p>Hello</p><p>World</p>", | ||
title: "Hello" | ||
}) | ||
).toEqual("World"); | ||
}); | ||
|
||
// Not sure if I like this behaviour | ||
it("has spaces between seperate paragraphs", function() { | ||
expect( | ||
this.summary({ | ||
html: "<p>Hello</p><p>World</p>", | ||
title: "Hello" | ||
}) | ||
).toEqual("World"); | ||
}); | ||
|
||
it("will not contain or truncate long words", function() { | ||
expect( | ||
this.summary({ | ||
html: "<p>Hello there helloooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo.</p>" | ||
}) | ||
).toEqual("Hello there"); | ||
}); | ||
|
||
it("decodes HTML entities", function() { | ||
expect( | ||
this.summary({ | ||
html: "<p>Hello & & foo</p><p>there</p>" | ||
}) | ||
).toEqual("Hello & & foo there"); | ||
}); | ||
|
||
}); |