Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore/renderer-test #226

Merged
merged 1 commit into from
Jul 3, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
using Contentful.Core;
using Contentful.Core.Configuration;
using Contentful.Core.Models;
using Dfe.EarlyYearsQualification.Content.Entities;
using Dfe.EarlyYearsQualification.Content.Renderers.GovUk;
using FluentAssertions;
using Moq;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;

namespace Dfe.EarlyYearsQualification.UnitTests.Renderers;
Expand Down Expand Up @@ -58,7 +60,7 @@ public void InsetTextRenderer_DataTargetIsEmptyCustomNode_NotSupported()
}

[TestMethod]
public void InsetTextRenderer_DataTargetIsCustomNodeWithJObject_OtherId_Supported()
public void InsetTextRenderer_DataTargetIsCustomNodeWithJObject_OtherId_NotSupported()
{
var contentClientMock = new Mock<IContentfulClient>();

Expand Down Expand Up @@ -95,7 +97,7 @@ public void InsetTextRenderer_DataTargetIsCustomNodeWithJObject_OtherId_Supporte
}

[TestMethod]
public void InsetTextRenderer_DataTargetIsCustomNodeWithJObject_Supported()
public void InsetTextRenderer_DataTargetIsCustomNodeWithJObject_IsSupported()
{
var contentClientMock = new Mock<IContentfulClient>();

Expand Down Expand Up @@ -150,4 +152,70 @@ public void InsetTextRenderer_DoesNotSupportHyperlink()

new InsetTextRenderer(contentClientMock.Object).SupportsContent(list).Should().BeFalse();
}

[TestMethod]
public async Task InsetTextRenderer_RendersDivWithId()
{
var innerDocument = new Document { Content = [] };
// ...we haven't worked out yet how to test this _with_ inner content,
// there is some Contentful SDK inner magic involved that is hard to replicate.

var govUkInsetTextModel = new GovUkInsetTextModel
{
Content = JObject.FromObject(innerDocument),
Sys =
{
ContentType = new ContentType
{
SystemProperties = new SystemProperties
{
Id = "govUkInsetText"
}
}
}
};

var jObject = JObject.FromObject(govUkInsetTextModel);

var customNode = new CustomNode
{
JObject = jObject
};

var content = new EntryStructure
{
Data = new EntryStructureData
{
Target = customNode
}
};

var renderer = new InsetTextRenderer(CreateMockContentfulContentClient());

var result = await renderer.RenderAsync(content);

result.Should().Be("<div class=\"govuk-inset-text\"></div>");
}

private static IContentfulClient CreateMockContentfulContentClient()
{
var contentClientMock = new Mock<IContentfulClient>();

var serializerSettings = new JsonSerializerSettings
{
Converters =
[
new AssetJsonConverter(),
new ContentJsonConverter()
],
TypeNameHandling = TypeNameHandling.All
}; // This is what a real ContentfulClient would have

contentClientMock.SetupGet(c => c.SerializerSettings)
.Returns(serializerSettings);

contentClientMock.SetupGet(c => c.ResolveEntriesSelectively).Returns(true);

return contentClientMock.Object;
}
}
Loading