-
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.
test(Outlines): add outlines and styles tag helper tests
- Loading branch information
1 parent
2ef3e81
commit c8e67de
Showing
5 changed files
with
255 additions
and
51 deletions.
There are no files selected for viewing
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
22 changes: 22 additions & 0 deletions
22
test/XperienceCommunity.PreviewComponentOutlinesTests/ContextFixtures.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 @@ | ||
using Kentico.Content.Web.Mvc; | ||
using Kentico.PageBuilder.Web.Mvc; | ||
using Kentico.Web.Mvc; | ||
|
||
namespace XperienceCommunity.PreviewComponentOutlinesTests | ||
{ | ||
public static class ContextFixtures | ||
{ | ||
public static IFeatureSet InitializeFeatures(bool isEditModeEnabled, bool isPreviewModeEnabled) | ||
{ | ||
var previewFeature = Substitute.For<IPreviewFeature>(); | ||
previewFeature.Enabled.Returns(isPreviewModeEnabled); | ||
var features = Substitute.For<IFeatureSet>(); | ||
features.GetFeature<IPreviewFeature>().Returns(previewFeature); | ||
var pageBuilderFeature = Substitute.For<IPageBuilderFeature>(); | ||
pageBuilderFeature.EditMode.Returns(isEditModeEnabled); | ||
features.GetFeature<IPageBuilderFeature>().Returns(pageBuilderFeature); | ||
|
||
return features; | ||
} | ||
} | ||
} |
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
121 changes: 121 additions & 0 deletions
121
...XperienceCommunity.PreviewComponentOutlinesTests/OutlinesStylesTagHelperComponentTests.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,121 @@ | ||
using FluentAssertions; | ||
using Microsoft.AspNetCore.Http; | ||
using Microsoft.AspNetCore.Razor.TagHelpers; | ||
using Microsoft.Extensions.Options; | ||
using XperienceCommunity.PreviewComponentOutlines; | ||
|
||
namespace XperienceCommunity.PreviewComponentOutlinesTests | ||
{ | ||
public class OutlinesStylesTagHelperComponentTests | ||
{ | ||
[Test] | ||
public async Task The_Styles_Element_Will_Not_Be_Added_When_The_Request_Is_In_Live_Mode() | ||
{ | ||
var accessor = Substitute.For<IHttpContextAccessor>(); | ||
var httpContext = Substitute.For<HttpContext>(); | ||
httpContext.Items = new Dictionary<object, object?> | ||
{ | ||
{ "Kentico.Features", ContextFixtures.InitializeFeatures(isEditModeEnabled: false, isPreviewModeEnabled: false) } | ||
}; | ||
accessor.HttpContext.Returns(httpContext); | ||
|
||
var tagHelperContext = new TagHelperContext("head", new(), new Dictionary<object, object>(), Guid.NewGuid().ToString()); | ||
var output = new TagHelperOutput("head", new(), (val, encoder) => | ||
{ | ||
return Task.FromResult<TagHelperContent>(new DefaultTagHelperContent()); | ||
}); | ||
|
||
var options = Options.Create(new OutlinesConfiguration()); | ||
|
||
var sut = new OutlinesStylesTagHelperComponent(accessor, options); | ||
|
||
await sut.ProcessAsync(tagHelperContext, output); | ||
|
||
output.PostContent.IsEmptyOrWhiteSpace.Should().BeTrue(); | ||
} | ||
|
||
[Test] | ||
public async Task The_Styles_Element_Will_Not_Be_Added_When_The_Request_Is_In_Edit_Mode() | ||
{ | ||
var accessor = Substitute.For<IHttpContextAccessor>(); | ||
var httpContext = Substitute.For<HttpContext>(); | ||
httpContext.Items = new Dictionary<object, object?> | ||
{ | ||
{ "Kentico.Features", ContextFixtures.InitializeFeatures(isEditModeEnabled: true, isPreviewModeEnabled: false) } | ||
}; | ||
accessor.HttpContext.Returns(httpContext); | ||
|
||
var tagHelperContext = new TagHelperContext("head", new(), new Dictionary<object, object>(), Guid.NewGuid().ToString()); | ||
var output = new TagHelperOutput("head", new(), (val, encoder) => | ||
{ | ||
return Task.FromResult<TagHelperContent>(new DefaultTagHelperContent()); | ||
}); | ||
|
||
var options = Options.Create(new OutlinesConfiguration()); | ||
|
||
var sut = new OutlinesStylesTagHelperComponent(accessor, options); | ||
|
||
await sut.ProcessAsync(tagHelperContext, output); | ||
|
||
output.PostContent.IsEmptyOrWhiteSpace.Should().BeTrue(); | ||
} | ||
|
||
[Test] | ||
public async Task The_Styles_Element_Will_Not_Be_Added_When_The_Request_Is_In_Preview_Mode_And_The_Configuration_Does_Not_Use_Included_Styles() | ||
{ | ||
var accessor = Substitute.For<IHttpContextAccessor>(); | ||
var httpContext = Substitute.For<HttpContext>(); | ||
httpContext.Items = new Dictionary<object, object?> | ||
{ | ||
{ "Kentico.Features", ContextFixtures.InitializeFeatures(isEditModeEnabled: false, isPreviewModeEnabled: true) } | ||
}; | ||
accessor.HttpContext.Returns(httpContext); | ||
|
||
var tagHelperContext = new TagHelperContext("head", new(), new Dictionary<object, object>(), Guid.NewGuid().ToString()); | ||
var output = new TagHelperOutput("head", new(), (val, encoder) => | ||
{ | ||
return Task.FromResult<TagHelperContent>(new DefaultTagHelperContent()); | ||
}); | ||
|
||
var options = Options.Create(new OutlinesConfiguration | ||
{ | ||
UseIncludedStyles = false | ||
}); | ||
|
||
var sut = new OutlinesStylesTagHelperComponent(accessor, options); | ||
|
||
await sut.ProcessAsync(tagHelperContext, output); | ||
|
||
output.PostContent.IsEmptyOrWhiteSpace.Should().BeTrue(); | ||
} | ||
|
||
[Test] | ||
public async Task The_Styles_Element_Will_Be_Added_When_The_Request_Is_In_Preview_Mode() | ||
{ | ||
var accessor = Substitute.For<IHttpContextAccessor>(); | ||
var httpContext = Substitute.For<HttpContext>(); | ||
httpContext.Items = new Dictionary<object, object?> | ||
{ | ||
{ "Kentico.Features", ContextFixtures.InitializeFeatures(isEditModeEnabled: false, isPreviewModeEnabled: true) } | ||
}; | ||
accessor.HttpContext.Returns(httpContext); | ||
|
||
var tagHelperContext = new TagHelperContext("head", new(), new Dictionary<object, object>(), Guid.NewGuid().ToString()); | ||
var output = new TagHelperOutput("head", new(), (val, encoder) => | ||
{ | ||
return Task.FromResult<TagHelperContent>(new DefaultTagHelperContent()); | ||
}); | ||
|
||
var config = new OutlinesConfiguration(); | ||
var options = Options.Create(config); | ||
|
||
var sut = new OutlinesStylesTagHelperComponent(accessor, options); | ||
|
||
await sut.ProcessAsync(tagHelperContext, output); | ||
|
||
var content = output.PostContent.GetContent(); | ||
|
||
content.Should().BeEquivalentTo(sut.Style); | ||
} | ||
} | ||
} |
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