Skip to content

Commit

Permalink
feat: hide the role salary field if the field is not populated
Browse files Browse the repository at this point in the history
Merge pull request #228 from DFE-Digital/Feature/HideEmptySalaryField
  • Loading branch information
killij authored Aug 31, 2023
2 parents e64b48f + 6946575 commit 9578087
Show file tree
Hide file tree
Showing 3 changed files with 68 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -199,4 +199,49 @@ public void RoleList_Renders_Salary_Range()
// assert
actual.Should().MatchRegex(expected);
}

[Test]
public void RoleList_Does_Not_Renders_Salary_Range_For_Empty_value()
{
// arrange
var stringWriter = new StringWriter();
var detailedRole = new DetailedRole()
{
Title = "title",
Summary = "summary",
SalaryRange = ""
};
var roleList = new RoleList()
{
Title = "A Title",
Roles = new List<Content>
{
new Content
{
Id = "id",
Items = new List<IContent>()
{
detailedRole
}
}
}
};

_contentLinkRenderer.Render(Arg.Any<ContentLink>()).Returns(new HtmlString("AAA"));

var sb = new StringBuilder();
sb.Append("<div class=\"HtmlEncode[[govuk-heading-s govuk-!-margin-bottom-1]]\">");
sb.Append("<h3>AAA</h3></div>");
sb.Append("<p class=\"HtmlEncode[[govuk-body]]\"></p>");
var expected = $".*?{Regex.Escape(sb.ToString())}.*";

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

// assert
actual.Should().MatchRegex(expected);
actual.Should().NotContain("Salary range:");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -65,30 +65,31 @@ private static IHtmlContent RoleSummary(DetailedRole detailedRole)
var p = new TagBuilder("p");
p.AddCssClass("govuk-body");
p.InnerHtml.Append(detailedRole.RoleListSummary);
htmlContentBuilder.AppendHtml(p);
if (!string.IsNullOrEmpty(detailedRole.SalaryRange))
{
var rowDiv = new TagBuilder("div");
rowDiv.AddCssClass("govuk-grid-row govuk-!-padding-bottom-3");

var rowDiv = new TagBuilder("div");
rowDiv.AddCssClass("govuk-grid-row govuk-!-padding-bottom-3");

var columnDiv = new TagBuilder("div");
columnDiv.AddCssClass("govuk-grid-column-one-half");
var columnDiv = new TagBuilder("div");
columnDiv.AddCssClass("govuk-grid-column-one-half");

var ul = new TagBuilder("ul");
ul.AddCssClass("govuk-list");
var ul = new TagBuilder("ul");
ul.AddCssClass("govuk-list");

var li = new TagBuilder("li");
var li = new TagBuilder("li");

var span = new TagBuilder("span");
span.AddCssClass("govuk-!-font-size-16 govuk-!-font-weight-bold");
span.InnerHtml.Append("Salary range: ");
span.InnerHtml.Append(detailedRole.SalaryRange);
var span = new TagBuilder("span");
span.AddCssClass("govuk-!-font-size-16 govuk-!-font-weight-bold");
span.InnerHtml.Append("Salary range: ");
span.InnerHtml.Append(detailedRole.SalaryRange);

li.InnerHtml.AppendHtml(span);
ul.InnerHtml.AppendHtml(li);
columnDiv.InnerHtml.AppendHtml(ul);
rowDiv.InnerHtml.AppendHtml(columnDiv);

htmlContentBuilder.AppendHtml(p);
htmlContentBuilder.AppendHtml(rowDiv);
li.InnerHtml.AppendHtml(span);
ul.InnerHtml.AppendHtml(li);
columnDiv.InnerHtml.AppendHtml(ul);
rowDiv.InnerHtml.AppendHtml(columnDiv);
htmlContentBuilder.AppendHtml(rowDiv);
}

return htmlContentBuilder;
}
Expand Down
3 changes: 3 additions & 0 deletions Childrens-Social-Care-CPD/Views/Shared/_DetailedRole.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@
<div class="govuk-grid-row">
<div class="govuk-grid-column-two-thirds">
<dl class="govuk-summary-list">
@if(!string.IsNullOrEmpty(Model.SalaryRange))
{
<div class="govuk-summary-list__row">
<dt class="govuk-summary-list__key">
Salary range
Expand All @@ -42,6 +44,7 @@
@Model.SalaryRange <span>depending on location, responsibilities and experience</span>
</dd>
</div>
}
<div class="govuk-summary-list__row">
<dt class="govuk-summary-list__key">
Summary
Expand Down

0 comments on commit 9578087

Please sign in to comment.