-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
78502bd
commit ad778d1
Showing
4 changed files
with
199 additions
and
0 deletions.
There are no files selected for viewing
22 changes: 22 additions & 0 deletions
22
tests/Rhythm.Drop.Web.Tests/TagHelperRenderers/FakeModal.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
namespace Rhythm.Drop.Web.Tests.TagHelperRenderers; | ||
|
||
using Rhythm.Drop.Models.Common.Attributes; | ||
using Rhythm.Drop.Models.Components; | ||
using Rhythm.Drop.Models.Modals; | ||
using System.Collections.Generic; | ||
|
||
internal class FakeModal : IModal | ||
{ | ||
public string ViewName => "Fake"; | ||
|
||
public string UniqueKey => "fake"; | ||
|
||
public IReadOnlyCollection<IComponent> Content => [ new FakeComponent() ]; | ||
|
||
public IReadOnlyHtmlAttributeCollection Attributes => ReadOnlyHtmlAttributeCollection.Empty(); | ||
|
||
public IReadOnlyCollection<IComponent> GetComponents() | ||
{ | ||
return Content; | ||
} | ||
} |
58 changes: 58 additions & 0 deletions
58
...Rhythm.Drop.Web.Tests/TagHelperRenderers/Modals/DefaultDropModalTagHelperRendererTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
namespace Rhythm.Drop.Web.Tests.TagHelperRenderers.Modals; | ||
|
||
using Rhythm.Drop.Models.Common.Attributes; | ||
using Rhythm.Drop.Models.Modals; | ||
using Rhythm.Drop.Web.Infrastructure.TagHelperRenderers.Modals; | ||
|
||
[TestFixture] | ||
public class DefaultDropModalTagHelperRendererTests : DefaultDropModalTagHelperRendererTestsBase | ||
{ | ||
[Test] | ||
public async Task RenderAsync_With_No_TagName_Returns_No_Output_Tag() | ||
{ | ||
// arrange | ||
var tagHelperRenderer = CreateDefaultDropModalsTagHelperRenderer(); | ||
var model = CreateRendererContext(new FakeModal()); | ||
var context = CreateTagHelperContext(DefaultTagName); | ||
var output = CreateTagHelperOutput(DefaultTagName); | ||
|
||
// act | ||
await tagHelperRenderer.RenderAsync(model, context, output); | ||
|
||
// assert | ||
Assert.Multiple(() => | ||
{ | ||
Assert.That(output.TagName, Is.Not.EqualTo(DefaultTagName)); | ||
Assert.That(output.Content.IsEmptyOrWhiteSpace, Is.False); | ||
}); | ||
|
||
} | ||
|
||
[Test] | ||
public async Task RenderAsync_With_No_Modal_Returns_No_Output() | ||
{ | ||
// arrange | ||
var tagHelperRenderer = CreateDefaultDropModalsTagHelperRenderer(); | ||
var model = CreateRendererContext(default); | ||
var context = CreateTagHelperContext(DefaultTagName); | ||
var output = CreateTagHelperOutput(DefaultTagName); | ||
|
||
// act | ||
await tagHelperRenderer.RenderAsync(model, context, output); | ||
|
||
// assert | ||
Assert.Multiple(() => | ||
{ | ||
Assert.That(output.TagName, Is.Not.EqualTo(DefaultTagName)); | ||
Assert.That(output.Content.IsEmptyOrWhiteSpace, Is.True); | ||
}); | ||
} | ||
|
||
|
||
private static DropModalTagHelperRendererContext CreateRendererContext(IModal? modal) | ||
{ | ||
var viewContext = CreateViewContext(); | ||
|
||
return new DropModalTagHelperRendererContext(modal, DefaultTheme, ReadOnlyHtmlAttributeCollection.Empty(), viewContext, default); | ||
} | ||
} |
49 changes: 49 additions & 0 deletions
49
...hm.Drop.Web.Tests/TagHelperRenderers/Modals/DefaultDropModalTagHelperRendererTestsBase.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
namespace Rhythm.Drop.Web.Tests.TagHelperRenderers.Modals; | ||
|
||
using Microsoft.AspNetCore.Html; | ||
using Microsoft.AspNetCore.Mvc.Rendering; | ||
using Moq; | ||
using Rhythm.Drop.Web.Factories.MetaData; | ||
using Rhythm.Drop.Web.Infrastructure.Factories.MetaData; | ||
using Rhythm.Drop.Web.Infrastructure.Helpers.Rendering; | ||
using Rhythm.Drop.Web.Infrastructure.MetaData; | ||
using Rhythm.Drop.Web.Infrastructure.TagHelperRenderers.Modals; | ||
using Rhythm.Drop.Web.TagHelperRenderers.Modals; | ||
using System.Threading.Tasks; | ||
|
||
public abstract class DefaultDropModalTagHelperRendererTestsBase : TagHelperRendererTestsBase | ||
{ | ||
protected const string DefaultTheme = "Default"; | ||
|
||
|
||
|
||
protected static IRenderingHelper CreateRenderingHelper() | ||
{ | ||
return CreateRenderingHelper(new HtmlString("<div>Test</div>")); | ||
} | ||
|
||
protected static IRenderingHelper CreateRenderingHelper(IHtmlContent htmlContent) | ||
{ | ||
var mock = new Mock<IRenderingHelper>(); | ||
mock.Setup(x => x.RenderAsync(It.IsAny<ModalMetaData>())).Returns(Task.FromResult(htmlContent)); | ||
|
||
return mock.Object; | ||
} | ||
|
||
protected static IModalMetaDataFactory CreateModalMetaDataFactory() | ||
{ | ||
return new DefaultModalMetaDataFactory(); | ||
} | ||
|
||
protected static IDropModalsTagHelperRenderer CreateDefaultDropModalsTagHelperRenderer() | ||
{ | ||
var modalMetaDataFactory = CreateModalMetaDataFactory(); | ||
var renderingHelper = CreateRenderingHelper(); | ||
return new DefaultDropModalsTagHelperRenderer(modalMetaDataFactory, renderingHelper); | ||
} | ||
|
||
protected static ViewContext CreateViewContext() | ||
{ | ||
return Mock.Of<ViewContext>(); | ||
} | ||
} |
70 changes: 70 additions & 0 deletions
70
...hythm.Drop.Web.Tests/TagHelperRenderers/Modals/DefaultDropModalsTagHelperRendererTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
namespace Rhythm.Drop.Web.Tests.TagHelperRenderers.Modals; | ||
using Rhythm.Drop.Models.Modals; | ||
using Rhythm.Drop.Web.Infrastructure.MetaData; | ||
using Rhythm.Drop.Web.Infrastructure.TagHelperRenderers.Modals; | ||
using System.Threading.Tasks; | ||
|
||
public class DefaultDropModalsTagHelperRendererTests : DefaultDropModalTagHelperRendererTestsBase | ||
{ | ||
[Test] | ||
public async Task RenderAsync_With_Modals_And_No_TagName_Returns_Output_With_No_TagName() | ||
{ | ||
// arrange | ||
var tagHelperRenderer = CreateDefaultDropModalsTagHelperRenderer(); | ||
var model = CreateRendererContext([new FakeModal()]); | ||
var context = CreateTagHelperContext(DefaultTagName); | ||
var output = CreateTagHelperOutput(DefaultTagName); | ||
|
||
// act | ||
await tagHelperRenderer.RenderAsync(model, context, output); | ||
|
||
// assert | ||
Assert.That(output.TagName, Is.Default); | ||
Assert.That(output.TagName, Is.Not.EqualTo(DefaultTagName)); | ||
} | ||
|
||
[Test] | ||
public async Task RenderAsync_With_TagName_And_No_Modals_Returns_Output_With_No_TagName() | ||
{ | ||
// arrange | ||
var tagHelperRenderer = CreateDefaultDropModalsTagHelperRenderer(); | ||
var model = CreateRendererContext([]); | ||
var context = CreateTagHelperContext(DefaultTagName); | ||
var output = CreateTagHelperOutput(DefaultTagName); | ||
|
||
// act | ||
await tagHelperRenderer.RenderAsync(model, context, output); | ||
|
||
// assert | ||
Assert.That(output.TagName, Is.Default); | ||
Assert.That(output.TagName, Is.Not.EqualTo(DefaultTagName)); | ||
} | ||
|
||
[Test] | ||
public async Task RenderAsync_With_TagName_And_Modals_Returns_Output_With_Expected_TagName() | ||
{ | ||
// arrange | ||
const string NewTagName = "section"; | ||
var tagHelperRenderer = CreateDefaultDropModalsTagHelperRenderer(); | ||
var model = CreateRendererContext([new FakeModal()], NewTagName); | ||
var context = CreateTagHelperContext(DefaultTagName); | ||
var output = CreateTagHelperOutput(DefaultTagName); | ||
|
||
// act | ||
await tagHelperRenderer.RenderAsync(model, context, output); | ||
|
||
// assert | ||
Assert.That(output.TagName, Is.EqualTo(NewTagName)); | ||
} | ||
|
||
private static DropModalsTagHelperRendererContext CreateRendererContext(IModal[] modals) | ||
{ | ||
return CreateRendererContext(modals, default); | ||
} | ||
private static DropModalsTagHelperRendererContext CreateRendererContext(IModal[] modals, string? tagName) | ||
{ | ||
var viewContext = CreateViewContext(); | ||
|
||
return new DropModalsTagHelperRendererContext(modals, DefaultTheme, tagName, viewContext, default); | ||
} | ||
} |