diff --git a/Childrens-Social-Care-CPD-Tests/Contentful/Renderers/ParagraphRendererTests.cs b/Childrens-Social-Care-CPD-Tests/Contentful/Renderers/ParagraphRendererTests.cs index 0d65d578..3d91ef51 100644 --- a/Childrens-Social-Care-CPD-Tests/Contentful/Renderers/ParagraphRendererTests.cs +++ b/Childrens-Social-Care-CPD-Tests/Contentful/Renderers/ParagraphRendererTests.cs @@ -5,7 +5,6 @@ using NSubstitute; using NUnit.Framework; using System.IO; -using System; using ParagraphRenderer = Childrens_Social_Care_CPD.Contentful.Renderers.ParagraphRenderer; using FluentAssertions; using System.Collections.Generic; @@ -18,6 +17,7 @@ public class ParagraphRendererTests private IRenderer _textRenderer; private IRenderer _roleListRenderer; private IRenderer _hyperlinkRenderer; + private IRenderer _contentLinkRenderer; private ParagraphRenderer _sut; @@ -27,8 +27,9 @@ public void Setup() _textRenderer = Substitute.For>(); _roleListRenderer = Substitute.For>(); _hyperlinkRenderer = Substitute.For>(); + _contentLinkRenderer = Substitute.For>(); - _sut = new ParagraphRenderer(_textRenderer, _roleListRenderer, _hyperlinkRenderer); + _sut = new ParagraphRenderer(_textRenderer, _roleListRenderer, _hyperlinkRenderer, _contentLinkRenderer); } [Test] @@ -47,6 +48,7 @@ public void Paragraph_Renders_With_Text() _textRenderer.Render(Arg.Any()).Returns(new HtmlString("AAA")); _roleListRenderer.Render(Arg.Any()).Returns(new HtmlString("BBB")); _hyperlinkRenderer.Render(Arg.Any()).Returns(new HtmlString("CCC")); + _contentLinkRenderer.Render(Arg.Any()).Returns(new HtmlString("DDD")); // act var htmlContent = _sut.Render(paragraph); @@ -79,6 +81,7 @@ public void Paragraph_Renders_With_RoleList() _textRenderer.Render(Arg.Any()).Returns(new HtmlString("AAA")); _roleListRenderer.Render(Arg.Any()).Returns(new HtmlString("BBB")); _hyperlinkRenderer.Render(Arg.Any()).Returns(new HtmlString("CCC")); + _contentLinkRenderer.Render(Arg.Any()).Returns(new HtmlString("DDD")); // act var htmlContent = _sut.Render(paragraph); @@ -105,6 +108,7 @@ public void Paragraph_Renders_With_Hyperlink() _textRenderer.Render(Arg.Any()).Returns(new HtmlString("AAA")); _roleListRenderer.Render(Arg.Any()).Returns(new HtmlString("BBB")); _hyperlinkRenderer.Render(Arg.Any()).Returns(new HtmlString("CCC")); + _contentLinkRenderer.Render(Arg.Any()).Returns(new HtmlString("DDD")); // act var htmlContent = _sut.Render(paragraph); @@ -114,4 +118,37 @@ public void Paragraph_Renders_With_Hyperlink() // assert actual.Should().Be($"

CCC

"); } + + [Test] + public void Paragraph_Renders_With_ContentLink() + { + // arrange + var stringWriter = new StringWriter(); + var paragraph = new Paragraph() + { + Content = new List + { + new EntryStructure + { + Data = new EntryStructureData + { + Target = new ContentLink() + } + } + } + }; + + _textRenderer.Render(Arg.Any()).Returns(new HtmlString("AAA")); + _roleListRenderer.Render(Arg.Any()).Returns(new HtmlString("BBB")); + _hyperlinkRenderer.Render(Arg.Any()).Returns(new HtmlString("CCC")); + _contentLinkRenderer.Render(Arg.Any()).Returns(new HtmlString("DDD")); + + // act + var htmlContent = _sut.Render(paragraph); + htmlContent.WriteTo(stringWriter, new HtmlTestEncoder()); + var actual = stringWriter.ToString(); + + // assert + actual.Should().Be($"

DDD

"); + } } diff --git a/Childrens-Social-Care-CPD/Contentful/Renderers/ParagraphRenderer.cs b/Childrens-Social-Care-CPD/Contentful/Renderers/ParagraphRenderer.cs index e6f419b8..acb25059 100644 --- a/Childrens-Social-Care-CPD/Contentful/Renderers/ParagraphRenderer.cs +++ b/Childrens-Social-Care-CPD/Contentful/Renderers/ParagraphRenderer.cs @@ -10,12 +10,15 @@ internal class ParagraphRenderer : IRenderer private readonly IRenderer _textRenderer; private readonly IRenderer _roleListRenderer; private readonly IRenderer _hyperlinkRenderer; + private readonly IRenderer _contentLinkRenderer; + - public ParagraphRenderer(IRenderer textRenderer, IRenderer roleListRenderer, IRenderer hyperlinkRenderer) + public ParagraphRenderer(IRenderer textRenderer, IRenderer roleListRenderer, IRenderer hyperlinkRenderer, IRenderer contentLinkRenderer) { _textRenderer = textRenderer; _roleListRenderer = roleListRenderer; _hyperlinkRenderer = hyperlinkRenderer; + _contentLinkRenderer = contentLinkRenderer; } public IHtmlContent Render(Paragraph item) @@ -32,6 +35,7 @@ public IHtmlContent Render(Paragraph item) { switch (entryStructure.Data.Target) { + case ContentLink contentLink: p.InnerHtml.AppendHtml(_contentLinkRenderer.Render(contentLink)); break; case RoleList roleList: p.InnerHtml.AppendHtml(_roleListRenderer.Render(roleList)); break; } break;