Permalink
Browse files

add unit tests for linkTextWithEntity()

  • Loading branch information...
keita
keita committed May 2, 2012
1 parent b4bbc0d commit fcd597ec28ce2cefac731de6d5def9138398e3a4
Showing with 38 additions and 0 deletions.
  1. +38 −0 test/tests.js
View
@@ -191,6 +191,44 @@ test("twttr.txt.autolink", function() {
"Autolink hashtag/mentionURL w/ Supplementary character");
});
+test("twttr.txt.linkTextWithEntity", function() {
+ var result = twttr.txt.linkTextWithEntity({
+ "url": "http://t.co/abcde",
+ "display_url": "twitter.com",
+ "expanded_url": "http://twitter.com/"},
+ {invisibleTagAttrs: "class='invisible'"});
+ same(result,
+ "<span class='tco-ellipsis'><span class='invisible'>&nbsp;</span></span><span class='invisible'>http://</span><span class='js-display-url'>twitter.com</span><span class='invisible'>/</span><span class='tco-ellipsis'><span class='invisible'>&nbsp;</span></span>",
+ "Entire display_url is in expanded_url");
+
+ result = twttr.txt.linkTextWithEntity({
+ "url": "http://t.co/abcde",
+ "display_url": "twitter.com…",
+ "expanded_url": "http://twitter.com/abcdefg"},
+ {invisibleTagAttrs: "class='invisible'"});
+ same(result,
+ "<span class='tco-ellipsis'><span class='invisible'>&nbsp;</span></span><span class='invisible'>http://</span><span class='js-display-url'>twitter.com</span><span class='invisible'>/abcdefg</span><span class='tco-ellipsis'><span class='invisible'>&nbsp;</span>…</span>",
+ "display_url ends with …");
+
+ result = twttr.txt.linkTextWithEntity({
+ "url": "http://t.co/abcde",
+ "display_url": "…tter.com/abcdefg",
+ "expanded_url": "http://twitter.com/abcdefg"},
+ {invisibleTagAttrs: "class='invisible'"});
+ same(result,
+ "<span class='tco-ellipsis'>…<span class='invisible'>&nbsp;</span></span><span class='invisible'>http://twi</span><span class='js-display-url'>tter.com/abcdefg</span><span class='invisible'></span><span class='tco-ellipsis'><span class='invisible'>&nbsp;</span></span>",
+ "display_url begins with …");
+
+ result = twttr.txt.linkTextWithEntity({
+ "url": "http://t.co/abcde",
+ "display_url": "pic.twitter.com/xyz",
+ "expanded_url": "http://twitter.com/foo/statuses/123/photo/1"},
+ {invisibleTagAttrs: "class='invisible'"});
+ same(result,
+ "pic.twitter.com/xyz",
+ "display_url and expanded_url are on different domains");
+});
+
test("twttr.txt.extractMentionsOrListsWithIndices", function() {
var invalid_chars = ['!', '@', '#', '$', '%', '&', '*'];

0 comments on commit fcd597e

Please sign in to comment.