diff --git a/modules/cms-kit/test/Volo.CmsKit.Domain.Tests/Polls/PollViewComponentManager_Test.cs b/modules/cms-kit/test/Volo.CmsKit.Domain.Tests/Polls/PollViewComponentManager_Test.cs new file mode 100644 index 0000000000..67ae5982f1 --- /dev/null +++ b/modules/cms-kit/test/Volo.CmsKit.Domain.Tests/Polls/PollViewComponentManager_Test.cs @@ -0,0 +1,123 @@ +using System; +using System.Collections.Generic; +using System.Threading.Tasks; +using Microsoft.Extensions.Options; +using Shouldly; +using Xunit; + +namespace Volo.CmsKit.Polls; + +public class PollViewComponentManager_Test : CmsKitDomainTestBase +{ + private readonly PollViewComponentManager pollManager; + private readonly CmsKitTestData testData; + private readonly IOptions _options; + + public PollViewComponentManager_Test() + { + pollManager = GetRequiredService(); + testData = GetRequiredService(); + _options = GetRequiredService>(); + } + + [Fact] + public async Task ParseAsync_ShouldWorkWithoutConfigOptions() + { + var content = @"**ABP Framework** is completely open source and developed in a community-driven manner. + [Widget Type= ""Poll"" PollName =""poll-name""] + Thanks _for_ *your * feedback."; + + var page = await pollManager.ParseAsync(content); + + page.ShouldNotBeNull(); + page.Count.ShouldBe(1);//Ignored Widget + } + + [Fact] + public async Task ParseAsync_ShouldWorkWithWrongConfigOptions() + { + _options.Value.AddWidgetConfig(testData.WidgetName, new ContentWidgetConfig(testData.PollName)); + + var content = @"**ABP Framework** is completely open source and developed in a community-driven manner. + [Widget Type= ""Poll"" PollName =""poll-name""] + Thanks _for_ *your * feedback."; + + var page = await pollManager.ParseAsync(content); + + page.ShouldNotBeNull(); + page.Count.ShouldBe(2); + } + + [Fact] + public async Task ParseAsync_ShouldWorkWithWrongWidgetType() + { + _options.Value.AddWidgetConfig(testData.PollName, new ContentWidgetConfig(testData.WidgetName)); + + var content = @"**ABP Framework** is completely open source and developed in a community-driven manner. + [Widget Wrong Type= ""Poll"" PollName =""poll-name""] + Thanks _for_ *your * feedback."; + + var page = await pollManager.ParseAsync(content); + + page.ShouldNotBeNull(); + page.Count.ShouldBe(2); + } + + [Fact] + public async Task ParseAsync_ShouldWorkWithWrongPollName() + { + _options.Value.AddWidgetConfig(testData.PollName, new ContentWidgetConfig(testData.WidgetName)); + + var content = @"**ABP Framework** is completely open source and developed in a community-driven manner. + [Widget Type= ""Poll"" PollWrongName =""poll-name""] + Thanks _for_ *your * feedback."; + + var page = await pollManager.ParseAsync(content); + + page.ShouldNotBeNull(); + page.Count.ShouldBe(2); + } + + [Theory] + [MemberData(nameof(ExampleData))] + public async Task ParseAsync_ShouldWorkProperlyWithCorrectInputs(string content, int expectedLine) + { + _options.Value.AddWidgetConfig(testData.PollName, new ContentWidgetConfig(testData.WidgetName)); + + var page = await pollManager.ParseAsync(content); + + page.ShouldNotBeNull(); + page.Count.ShouldBe(expectedLine); + } + + public static IEnumerable ExampleData => + new List + { + new object[] { @"**ABP Framework** is completely open source and developed in a community-driven manner. + [Widget Type=""Poll"" PollName=""poll-name""] + Thanks _for_ *your * feedback.", 3}, + + new object[] { @"**ABP Framework** is completely open source and developed in a community-driven manner. + [Widget Type=""Poll"" PollName=""poll-name""] + Thanks _for_ *your * feedback. + [Widget Type=""Poll"" PollName=""poll-name1""]", 4 }, + + new object[] { @"**ABP Framework** is completely open source and developed in a community-driven manner. + Thanks _for_ *your * feedback. + [Widget Type=""Poll"" PollName=""poll-name""]", 2 }, + + new object[] { @"[Widget Type=""Poll"" PollName=""poll-name""] gg [Widget Type=""Poll"" PollName=""poll-name1""]**ABP Framework** is completely open source and developed in a community-driven manner. + Thanks _for_ *your * feedback. + Thanks _for_ *your * feedback.", 4}, + + new object[] { @"Thanks _for_ *your * feedback. + Thanks _for_ *your * feedback.", 1} + }; + +} + + + + + + diff --git a/modules/cms-kit/test/Volo.CmsKit.TestBase/CmsKitTestData.cs b/modules/cms-kit/test/Volo.CmsKit.TestBase/CmsKitTestData.cs index d47f139560..6445fb86f4 100644 --- a/modules/cms-kit/test/Volo.CmsKit.TestBase/CmsKitTestData.cs +++ b/modules/cms-kit/test/Volo.CmsKit.TestBase/CmsKitTestData.cs @@ -127,4 +127,8 @@ public class CmsKitTestData : ISingletonDependency public string MenuItem_3_Name { get; } = "Products"; public string MenuItem_3_Url { get; } = "/products"; + + public string PollName { get; } = "Poll"; + + public string WidgetName { get; } = "CmsPollByName"; }