added a few tests for the new UmbracoHelper methods.

This commit is contained in:
Claus
2017-08-15 13:08:30 +02:00
parent cddc6f3116
commit bb01eca7b7

View File

@@ -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&hellip;", 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&hellip;", 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&hellip;", 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&hellip;</a>", result);
}
}
}