diff --git a/Childrens-Social-Care-CPD-Tests/Contentful/Renderers/ListRendererTests.cs b/Childrens-Social-Care-CPD-Tests/Contentful/Renderers/ListRendererTests.cs index 129c170b..3735c93e 100644 --- a/Childrens-Social-Care-CPD-Tests/Contentful/Renderers/ListRendererTests.cs +++ b/Childrens-Social-Care-CPD-Tests/Contentful/Renderers/ListRendererTests.cs @@ -47,12 +47,13 @@ public void List_Does_Not_Render_When_No_Items() } [Test] - public void List_Renders() + public void Unordered_List_Renders() { // arrange var stringWriter = new StringWriter(); var list = new List() { + NodeType = "unordered-list", Content = new List { new ListItem @@ -90,6 +91,51 @@ public void List_Renders() actual.Should().Be(""); } + [Test] + public void Ordered_List_Renders() + { + // arrange + var stringWriter = new StringWriter(); + var list = new List() + { + NodeType = "ordered-list", + Content = new List + { + new ListItem + { + Content = new List + { + new Paragraph + { + Content = new List { new Text() } + } + } + }, + new ListItem + { + Content = new List + { + new Paragraph + { + Content = new List { new Hyperlink() } + } + } + + } + } + }; + _textLinkRenderer.Render(Arg.Any()).Returns(new HtmlString("AAA")); + _hyperlinkRenderer.Render(Arg.Any()).Returns(new HtmlString("BBB")); + + // act + var htmlContent = _sut.Render(list); + htmlContent.WriteTo(stringWriter, new HtmlTestEncoder()); + var actual = stringWriter.ToString(); + + // assert + actual.Should().Be("
  1. AAA
  2. BBB
"); + } + [Test] public void List_Only_Renders_Paragraphs() { @@ -97,6 +143,7 @@ public void List_Only_Renders_Paragraphs() var stringWriter = new StringWriter(); var list = new List() { + NodeType = "unordered-list", Content = new List { new ListItem diff --git a/Childrens-Social-Care-CPD/Contentful/Renderers/ListRenderer.cs b/Childrens-Social-Care-CPD/Contentful/Renderers/ListRenderer.cs index 14b77c62..8c295c61 100644 --- a/Childrens-Social-Care-CPD/Contentful/Renderers/ListRenderer.cs +++ b/Childrens-Social-Care-CPD/Contentful/Renderers/ListRenderer.cs @@ -14,8 +14,19 @@ public IHtmlContent Render(List item) return null; } - var ul = new TagBuilder("ul"); - ul.AddCssClass("govuk-list govuk-list--bullet"); + TagBuilder listTag; + string cssClass; + if (item.NodeType == "unordered-list") + { + listTag = new TagBuilder("ul"); + cssClass = "govuk-list govuk-list--bullet"; + } + else + { + listTag = new TagBuilder("ol"); + cssClass = "govuk-list govuk-list--number"; + } + listTag.AddCssClass(cssClass); foreach (var listItem in item.Content.OfType()) { @@ -38,9 +49,9 @@ public IHtmlContent Render(List item) } } } - ul.InnerHtml.AppendHtml(li); + listTag.InnerHtml.AppendHtml(li); } - return ul; + return listTag; } -} +} \ No newline at end of file