added a few tests for the new UmbracoHelper methods.
This commit is contained in:
@@ -21,6 +21,21 @@ namespace Umbraco.Tests.FrontEnd
|
||||
Assert.AreEqual("Hello world, this is some…", result);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// If a truncated string ends with a space, we should trim the space before appending the ellipsis.
|
||||
/// </summary>
|
||||
[Test]
|
||||
public void Truncate_Simple_With_Trimming()
|
||||
{
|
||||
var text = "Hello world, this is some text <a href='blah'>with a link</a>";
|
||||
|
||||
var helper = new UmbracoHelper();
|
||||
|
||||
var result = helper.Truncate(text, 26).ToString();
|
||||
|
||||
Assert.AreEqual("Hello world, this is some…", result);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Truncate_Inside_Word()
|
||||
{
|
||||
@@ -78,5 +93,41 @@ namespace Umbraco.Tests.FrontEnd
|
||||
|
||||
Assert.AreEqual(expectedResult, result);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Truncate_By_Words()
|
||||
{
|
||||
var text = "Hello world, this is some text <a href='blah'>with a link</a>";
|
||||
|
||||
var helper = new UmbracoHelper();
|
||||
|
||||
var result = helper.TruncateByWords(text, 4).ToString();
|
||||
|
||||
Assert.AreEqual("Hello world, this is…", result);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Truncate_By_Words_With_Tag()
|
||||
{
|
||||
var text = "Hello world, <b>this</b> is some text <a href='blah'>with a link</a>";
|
||||
|
||||
var helper = new UmbracoHelper();
|
||||
|
||||
var result = helper.TruncateByWords(text, 4).ToString();
|
||||
|
||||
Assert.AreEqual("Hello world, <b>this</b> is…", result);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Truncate_By_Words_Mid_Tag()
|
||||
{
|
||||
var text = "Hello world, this is some text <a href='blah'>with a link</a>";
|
||||
|
||||
var helper = new UmbracoHelper();
|
||||
|
||||
var result = helper.TruncateByWords(text, 7).ToString();
|
||||
|
||||
Assert.AreEqual("Hello world, <b>this</b> is some text <a href='blah'>with…</a>", result);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user