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

SWCD-2379: numbered list bug #518

Merged
merged 7 commits into from
Oct 16, 2024
Merged
Show file tree
Hide file tree
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
Expand Up @@ -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<IContent>
{
new ListItem
Expand Down Expand Up @@ -90,13 +91,59 @@ public void List_Renders()
actual.Should().Be("<ul class=\"HtmlEncode[[govuk-list govuk-list--bullet]]\"><li>AAA</li><li>BBB</li></ul>");
}

[Test]
public void Ordered_List_Renders()
{
// arrange
var stringWriter = new StringWriter();
var list = new List()
{
NodeType = "ordered-list",
Content = new List<IContent>
{
new ListItem
{
Content = new List<IContent>
{
new Paragraph
{
Content = new List<IContent> { new Text() }
}
}
},
new ListItem
{
Content = new List<IContent>
{
new Paragraph
{
Content = new List<IContent> { new Hyperlink() }
}
}

}
}
};
_textLinkRenderer.Render(Arg.Any<Text>()).Returns(new HtmlString("AAA"));
mattb-hippo marked this conversation as resolved.
Show resolved Hide resolved
_hyperlinkRenderer.Render(Arg.Any<Hyperlink>()).Returns(new HtmlString("BBB"));

// act
var htmlContent = _sut.Render(list);
htmlContent.WriteTo(stringWriter, new HtmlTestEncoder());
var actual = stringWriter.ToString();

// assert
actual.Should().Be("<ol class=\"HtmlEncode[[govuk-list govuk-list--number]]\"><li>AAA</li><li>BBB</li></ol>");
}

[Test]
public void List_Only_Renders_Paragraphs()
{
// arrange
var stringWriter = new StringWriter();
var list = new List()
{
NodeType = "unordered-list",
Content = new List<IContent>
{
new ListItem
Expand Down
21 changes: 16 additions & 5 deletions Childrens-Social-Care-CPD/Contentful/Renderers/ListRenderer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
mattb-hippo marked this conversation as resolved.
Show resolved Hide resolved
{
listTag = new TagBuilder("ol");
cssClass = "govuk-list govuk-list--number";
}
listTag.AddCssClass(cssClass);

foreach (var listItem in item.Content.OfType<ListItem>())
{
Expand All @@ -38,9 +49,9 @@ public IHtmlContent Render(List item)
}
}
}
ul.InnerHtml.AppendHtml(li);
listTag.InnerHtml.AppendHtml(li);
}

return ul;
return listTag;
}
}
}
Loading