2020-12-20 08:36:11 +01:00
|
|
|
// Copyright (c) Umbraco.
|
|
|
|
|
// See LICENSE for more details.
|
|
|
|
|
|
|
|
|
|
using NUnit.Framework;
|
2021-02-18 11:06:02 +01:00
|
|
|
using Umbraco.Cms.Web.Common.Mvc;
|
2017-09-19 15:51:47 +02:00
|
|
|
|
2022-06-21 08:09:38 +02:00
|
|
|
namespace Umbraco.Cms.Tests.UnitTests.Umbraco.Web.Common.Mvc;
|
|
|
|
|
|
|
|
|
|
[TestFixture]
|
|
|
|
|
public class HtmlStringUtilitiesTests
|
2017-09-19 15:51:47 +02:00
|
|
|
{
|
2022-06-21 08:09:38 +02:00
|
|
|
[SetUp]
|
|
|
|
|
public virtual void Initialize() => _htmlStringUtilities = new HtmlStringUtilities();
|
|
|
|
|
|
|
|
|
|
private HtmlStringUtilities _htmlStringUtilities;
|
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
|
public void TruncateWithElipsis()
|
|
|
|
|
{
|
|
|
|
|
var output = _htmlStringUtilities.Truncate("hello world", 5, true, false).ToString();
|
|
|
|
|
var expected = "hello…";
|
|
|
|
|
Assert.AreEqual(expected, output);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
|
public void TruncateWithoutElipsis()
|
|
|
|
|
{
|
|
|
|
|
var output = _htmlStringUtilities.Truncate("hello world", 5, false, false).ToString();
|
|
|
|
|
var expected = "hello";
|
|
|
|
|
Assert.AreEqual(expected, output);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
|
public void TruncateShorterWordThanHellip()
|
|
|
|
|
{
|
|
|
|
|
// http://issues.umbraco.org/issue/U4-10478
|
|
|
|
|
var output = _htmlStringUtilities.Truncate("hi", 5, true, false).ToString();
|
|
|
|
|
var expected = "hi";
|
|
|
|
|
Assert.AreEqual(expected, output);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
|
public void TruncateAndRemoveSpaceBetweenHellipAndWord()
|
2017-09-19 15:51:47 +02:00
|
|
|
{
|
2022-06-21 08:09:38 +02:00
|
|
|
var output = _htmlStringUtilities.Truncate("hello world", 6 /* hello plus space */, true, false).ToString();
|
|
|
|
|
var expected = "hello…";
|
|
|
|
|
Assert.AreEqual(expected, output);
|
2017-09-19 15:51:47 +02:00
|
|
|
}
|
2018-09-06 14:10:10 +02:00
|
|
|
}
|