diff --git a/tests/Dfe.EarlyYearsQualification.UnitTests/Renderers/InsetTextRendererTests.cs b/tests/Dfe.EarlyYearsQualification.UnitTests/Renderers/InsetTextRendererTests.cs index 51c0c50e..13fd9330 100644 --- a/tests/Dfe.EarlyYearsQualification.UnitTests/Renderers/InsetTextRendererTests.cs +++ b/tests/Dfe.EarlyYearsQualification.UnitTests/Renderers/InsetTextRendererTests.cs @@ -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; @@ -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(); @@ -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(); @@ -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("
"); + } + + private static IContentfulClient CreateMockContentfulContentClient() + { + var contentClientMock = new Mock(); + + 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; + } } \ No newline at end of file