From a459e0af7b28a8c04ad51867e10374482aa5cec3 Mon Sep 17 00:00:00 2001 From: nileshgnagepatil Date: Wed, 30 Aug 2023 14:02:16 +0100 Subject: [PATCH] Changes to hide Role - salary field when no salary value provided --- .../Renderers/InlineRoleListRendererTests.cs | 45 +++++++++++++++++++ .../Renderers/InlineRoleListRenderer.cs | 39 ++++++++-------- .../Views/Shared/_DetailedRole.cshtml | 3 ++ 3 files changed, 68 insertions(+), 19 deletions(-) diff --git a/Childrens-Social-Care-CPD-Tests/Contentful/Renderers/InlineRoleListRendererTests.cs b/Childrens-Social-Care-CPD-Tests/Contentful/Renderers/InlineRoleListRendererTests.cs index 1ac951c4..3979992e 100644 --- a/Childrens-Social-Care-CPD-Tests/Contentful/Renderers/InlineRoleListRendererTests.cs +++ b/Childrens-Social-Care-CPD-Tests/Contentful/Renderers/InlineRoleListRendererTests.cs @@ -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 + { + new Content + { + Id = "id", + Items = new List() + { + detailedRole + } + } + } + }; + + _contentLinkRenderer.Render(Arg.Any()).Returns(new HtmlString("AAA")); + + var sb = new StringBuilder(); + sb.Append("
"); + sb.Append("

AAA

"); + sb.Append("

"); + 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:"); + } } diff --git a/Childrens-Social-Care-CPD/Contentful/Renderers/InlineRoleListRenderer.cs b/Childrens-Social-Care-CPD/Contentful/Renderers/InlineRoleListRenderer.cs index bb14af98..826f5627 100644 --- a/Childrens-Social-Care-CPD/Contentful/Renderers/InlineRoleListRenderer.cs +++ b/Childrens-Social-Care-CPD/Contentful/Renderers/InlineRoleListRenderer.cs @@ -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; } diff --git a/Childrens-Social-Care-CPD/Views/Shared/_DetailedRole.cshtml b/Childrens-Social-Care-CPD/Views/Shared/_DetailedRole.cshtml index d5f32ae7..8082f1a0 100644 --- a/Childrens-Social-Care-CPD/Views/Shared/_DetailedRole.cshtml +++ b/Childrens-Social-Care-CPD/Views/Shared/_DetailedRole.cshtml @@ -34,6 +34,8 @@
+ @if(!string.IsNullOrEmpty(Model.SalaryRange)) + {
Salary range @@ -42,6 +44,7 @@ @Model.SalaryRange depending on location, responsibilities and experience
+ }
Summary