diff --git a/src/Umbraco.Tests/FrontEnd/UmbracoHelperTests.cs b/src/Umbraco.Tests/FrontEnd/UmbracoHelperTests.cs index 672b9022e5..f951304874 100644 --- a/src/Umbraco.Tests/FrontEnd/UmbracoHelperTests.cs +++ b/src/Umbraco.Tests/FrontEnd/UmbracoHelperTests.cs @@ -21,6 +21,21 @@ namespace Umbraco.Tests.FrontEnd Assert.AreEqual("Hello world, this is some…", result); } + /// + /// If a truncated string ends with a space, we should trim the space before appending the ellipsis. + /// + [Test] + public void Truncate_Simple_With_Trimming() + { + var text = "Hello world, this is some text with a link"; + + 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 with a link"; + + 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, this is some text with a link"; + + var helper = new UmbracoHelper(); + + var result = helper.TruncateByWords(text, 4).ToString(); + + Assert.AreEqual("Hello world, this is…", result); + } + + [Test] + public void Truncate_By_Words_Mid_Tag() + { + var text = "Hello world, this is some text with a link"; + + var helper = new UmbracoHelper(); + + var result = helper.TruncateByWords(text, 7).ToString(); + + Assert.AreEqual("Hello world, this is some text with…", result); + } } }